/*! * @brief 设置LED灯亮灭反转 * @param LED_e LED编号(LED0、LED1、LED2、LED3) * @since v5.2 * Sample usage: led_turn (LED0); // LED0灯亮灭反转 */ void led_turn(LED_e ledn) { if(ledn < LED_MAX) { gpio_turn(LED_PTxn[ledn]); } else { ledn = LED_MAX; while(ledn--) { gpio_turn(LED_PTxn[ledn]); } } }
void ccd_clock_turn(){ gpio_turn(PORTB, 9); // Gen 3 main board Clock }
void main() { uart_init(UART3, 115200); // For our flashed bluetooth //uart_init(UART3, 9600); // For our non-flashed bluetooth gpio_init(PORTE,6,GPI,0); // SW2 goes into gyro calibration mode printf("\nWelcome to the SmartCar 2013 Sensor team developement system\n"); while(1){ printf("==============================================================\n"); printf("Please select mode:\n---------------------------\n"); printf("1:Accelerometer&gyro\n"); printf("2:LinearCCD\n"); printf("3:Flash Memory\n"); printf("4:Encoder testing\n"); printf("6:Motor control test\n"); printf("7:SystemLoop Test\n"); delayms(300); if(gpio_get(PORTE,6)==0){ adc_init(ADC1,AD5b); adc_init(ADC1,AD7b); printf("We are now in gyro calibration mode, Please keep car stationery and wait till light dies"); gpio_init(PORTE,24,GPO,0); gpio_init(PORTE,25,GPO,0); gpio_init(PORTE,26,GPO,0); gpio_init(PORTE,27,GPO,0); delayms(3000); turn_gyro_offset=ad_ave(ADC1,AD5b,ADC_12bit,1000); balance_gyro_offset=ad_ave(ADC1,AD7b,ADC_12bit,1000); store_u32_to_flashmem1(turn_gyro_offset); store_u32_to_flashmem2(balance_gyro_offset); gpio_turn(PORTE,24); gpio_turn(PORTE,25); gpio_turn(PORTE,26); gpio_turn(PORTE,27); while(1){} } g_char_mode = '7'; // Hard code mode = system loop //g_char_mode = uart_getchar(UART3); switch (g_char_mode){ case '0': //VR analog input adc_init(ADC0,AD14); while(1){ delayms(500); printf("\n%d",ad_once(ADC0,AD14,ADC_16bit));//vr value } break; case '1': uart_sendStr(UART3,"The mode now is 1: Accelerometer and Gyroscope Test"); //accl_init(); adc_init(ADC1,AD6b); adc_init(ADC1,AD7b); adc_init(ADC0,AD14); adc_init(ADC1,AD4b); balance_centerpoint_set=ad_ave(ADC0,AD14,ADC_12bit,10); printf("\nEverything Initialized alright\n"); while(1) { //printf("\n\f===================================="); //control_tilt=(ad_ave(ADC1,AD6b,ADC_12bit,8)-3300)+(balance_centerpoint_set/10); //printf("\nMain gyro%d",control_tilt);//theta //printf("\n%d",ad_once(ADC1,AD7b,ADC_12bit)-1940);//omega printf("\n%d",ad_ave(ADC1,AD6b,ADC_12bit,8)-940); delayms(50); } break; case '2': uart_sendStr(UART3,"The mode now is 2: Linear CCD"); ccd_interrupts_init(); printf("\nEverything Initialized alright\n"); while(1) { //ccd_sampling(1); // Longer SI CCD Sampling } break; case '3': uart_sendStr(UART3,"The mode now is 3:Flash Memory\n"); Flash_init(); printf("Flash Memory init ok\n"); printf("writing the u32 : 3125 to memory 1\n"); store_u32_to_flashmem1(3125); printf("writing the u32: 1019 to memory 2\n"); store_u32_to_flashmem2(1019); printf("Now reading from memory\n"); printf("Memory 1:%d\n",get_u32_from_flashmem1()); printf("Memory 2:%d\n",get_u32_from_flashmem2()); while(1) { //stops loop to see results } break; case '4': //temporary case for debuggine encoder libraries, move to encoder.h later uart_sendStr(UART3,"The mode now is 4: encoder test"); DisableInterrupts; exti_init(PORTA,6,rising_up); //inits left encoder interrupt capture exti_init(PORTA,7,rising_up); //inits right encoder interrupt capture pit_init_ms(PIT1,500); //periodic interrupt every 500ms EnableInterrupts; printf("\nEverything Initialized alright\n"); while(1){ } break; case '6': uart_sendStr(UART3,"The mode now is 6: Motor Control test"); //inits motor_init(); printf("\nEverything Initialized alright\n"); delayms(1000); while(1) { //printf("\n\fInput 0-9 Motor Speed, Currently:%d",motor_test); //motor_test=100*(uart_getchar(UART3)-48); FTM_PWM_Duty(FTM1,CH0,2000); FTM_PWM_Duty(FTM1,CH1,2000);//left printf("\n\f Input direction : 0 or 1"); motor_test = uart_getchar(UART3)-48; if (motor_test){ gpio_set(PORTD,9,1); gpio_set(PORTD,7,1);//this is DIR }else{ gpio_set(PORTD,9,0); gpio_set(PORTD,1,0);//this is DIR } } break; case '7': printf("\n The Mode is now 7: SystemLoop Test"); adc_init(ADC1,AD6b); adc_init(ADC1,AD7b); adc_init(ADC0,AD14); adc_init(ADC1,AD5b); balance_centerpoint_set=ad_ave(ADC0,AD14,ADC_12bit,10); motor_init(); gpio_set(PORTD,9,0); //dir gpio_set(PORTD,7,0); //dir FTM_PWM_Duty(FTM1, CH0, 3000); //initital speed FTM_PWM_Duty(FTM1, CH1, 3000); //initital speed ccd_interrupts_init(); pit_init_ms(PIT3,1); printf("\nEverything inited alright"); while(1){ //system loop runs } break; default : printf("\n\fYou entered:%c, Please enter a number from 1-7 to select a mode\n\f",g_char_mode); } } }
void main(void) { int i1=0; int count10S = 0; Device_init(); disable_irq(PIT0_IRQn); systick_delay_ms(50); FLOAT_LDC_init(SPI1); systick_delay_ms(50); FLOAT_LDC_init(SPI0); systick_delay_ms(1000); uart_init(UART3,115200); key_init(0); key_init(1); key_init(2); //LDC_EVM_TEST(); //Speed_Ctl_Init(short point_value, double dKpp, double dKii, double dKdd); while(1) { //value_collect(); LCD_P6x8Str(0,2,"Rmax Lmin"); printf("Rmax Rmin\r\n"); systick_delay_ms(1500); i1=50; while(i1--) { adjustment[2]=(float)filter(SPI1)/10;//右max LCD_BL(55,2,(uint16)adjustment[2]); printf("%d\r\n",adjustment[2]); } i1=50; while(i1--) { adjustment[1]=(float)filter(SPI0)/10;//左min LCD_BL(90,2,(uint16)adjustment[1]); printf("%d\r\n",adjustment[1]); } LCD_BL(55,2,(uint16)adjustment[1]); LCD_BL(90,2,(uint16)adjustment[2]); LCD_P6x8Str(0,4,"Lmax Rmin"); printf("Lmax Rmin\r\n"); systick_delay_ms(1500); i1=50; while(i1--) { adjustment[3]=(float)filter(SPI1)/10;//右min LCD_BL(55,4,(uint16)adjustment[3]); printf("%d\r\n",adjustment[3]); } i1=50; while(i1--) { adjustment[4]=(float)filter(SPI0)/10;//左max LCD_BL(90,4,(uint16)adjustment[4]); printf("%d\r\n",adjustment[4]); } LCD_BL(55,4,(uint16)adjustment[4]); LCD_BL(90,4,(uint16)adjustment[3]); if(adjustment[1]<=adjustment[3]) adjustment[5]=adjustment[1];//次小值 else adjustment[5]=adjustment[3];//次小值 if(adjustment[2]>=adjustment[4]) adjustment[6]=adjustment[2];//次大值 else adjustment[6]=adjustment[4];//次大值 divisor = (adjustment[2] - adjustment[3])/60; //48 //50 divisor2 = (adjustment[4] - adjustment[1])/59; //48 //45 zengfuzhi = (adjustment[2] - adjustment[3])/(adjustment[4] - adjustment[1]); // for(int i=0;i<10;i++) // { // printf("%d\r\n",adjustment[i]); // } // systick_delay_ms(1000); LCD_P6x8Str(0,6,"Mid value"); i1 = 50; systick_delay_ms(1500); while(i1--) { adjustment[7]=(float)filter(SPI0)/10;//左 adjustment[8]=(float)filter(SPI1)/10;//右 LCD_BL(55,6,(uint16)adjustment[7]); LCD_BL(90,6,(uint16)adjustment[8]); } if(adjustment[7]>=adjustment[8]) { flag=1; adjustment[0]=adjustment[7]-adjustment[8]; } else { flag=0; adjustment[0]=adjustment[8]-adjustment[7]; } LCD_Fill(0x00); Out_side_collect(); LCD_Fill(0x00); adjustment_change(); enable_irq(PIT0_IRQn); while(1) { if(PIT_1sFlag == 1) { gpio_turn(PTD4); PIT_1sFlag = 0; count10S ++; } if(key_check(2) == 0) { LCD_Fill(0x00); Motor_stop(); break; } else { if(PIT_5msFlag == 1) { LDC_get(); PIT_5msFlag = 0; Steering_Change(); } if(count10S > 10) { if(gpio_get(PTC4) == 0) { while(1) { Motor_stop(); Steering_Change(); } } } if(PIT_10msFlag == 1) { Quad_count(); now = (float)guad_val; Motor_PID(now); PIT_10msFlag = 0; } if(PIT_20msFlag == 1) { PIT_20msFlag = 0; } if(PIT_50msFlag == 1) { //Result_collect(); PIT_50msFlag = 0; } //printf("guad_val:%d \r\n",(guad_val)); //TEST_display(); speed_control(); //key_choice(); uint16 i23 = gpio_get(PTC4); //LCD_BL(50,2,(uint16)(i23)); } } } }