//- msec millisecond동안 지연시키는 함수 void BTMR_DelayMs(uint32_t msec) { uint32_t t0; if (msec==0) return; t0 = BTMR_GetRuntime(); while ((BTMR_GetRuntime()-t0)<msec) { } }
void DoMainLoop(void) { static uint32_t t_c, t_old=(uint32_t)-1, cnt=0; int16_t i; t_c = BTMR_GetRuntime()/50//100; for 0.2 ms if (t_c != t_old) { t_old = t_c; SDBG_Printf("%d ", cnt++); //for (i=0; i<6; i++) { //SDBG_Printf("%4d ", FADC_Get(1));//Pot on board SDBG_Printf("%4d ", FADC_Get(5));//pd0 distance sensor //} SDBG_Printf("\n"); } if (SDBG_IsEvents()) SDBG_ExecuteCallback(); if (MUART_IsEvents()) MUART_ExecuteCallback(); }
//- timer1의 현재 값을 millisecond 단위로 리턴하는 함수 // BTMR_settimer1와 함께 사용 uint32_t BTMR_GetTimer1(void) { uint32_t etime; etime = BTMR_GetRuntime()-btmr_tstart1; if (etime < btmr_tset1) { return (btmr_tset1-etime); } return 0; }
//- timer0의 현재 값을 millisecond 단위로 리턴하는 함수 // BTMR_settimer0와 함께 사용 uint32_t BTMR_GetTimer0(void) { uint32_t etime; etime = BTMR_GetRuntime()-btmr_tstart0; if (etime < btmr_tset0) { return (btmr_tset0-etime); } return 0; }
void DoMainLoop(void) { //USONIC PART// Replace with Displacement static uint32_t t_c, t_old=(uint32_t)-1, cnt=0; //pot_value = (FADC_Get(1)-870)*10; //860-1024 //MCTL_RotateEngine(pot_value); angle = (FADC_Get(1)-950)*2; MCTL_RotateSwheel(angle); t_c = BTMR_GetRuntime()/200;//GetRuntime == mills//for 200 ms(0.2sec) if (t_c != t_old) { t_old = t_c; SDBG_Printf("Runtime = %u.%01u sec.", t_c/5, (t_c%5)*2); //SDBG_Printf("%d ", cnt++); //for (i=4; i<5; i++) {//6; i++) { pot_value = (FADC_Get(1)-850)*10; //860-1024 SDBG_Printf("%4d\t", angle);//Potentiometer on Board SDBG_Printf("%4d\t", FADC_Get(5)); // ADC on PD0 //} SDBG_Printf("\n"); } if (SDBG_IsEvents()) SDBG_ExecuteCallback(); if (MUART_IsEvents()) MUART_ExecuteCallback(); }
void DoMainLoop(void) { //COUNT FOR TIMER static uint32_t t_c, t_old=(uint32_t)-1, cnt=0; //RUN CAMERA //with dip sw 1 if(dipsw & 0x1)//high//sw1 CAM_RUN2(); else//low CAM_RUN(); //threshhold if(dipsw & 0x2)//sw2 cam_th = (FADC_Get(1)-800)*5; else cam_th = (CAM_MAX()+CAM_MIN())/2;//CAM_TRESHLOLD(); //camera exposure time if(dipsw & 0x8)//sw4 CAM_PulseWidth(50); else CAM_PulseWidth(100); //SERIAL COMMUNICATE if (SDBG_IsEvents()) SDBG_ExecuteCallback(); if (MUART_IsEvents()) MUART_ExecuteCallback(); //servo test in main sangle = (FADC_Get(1)-870)*2*37/156-37; MCTL_Servo(sangle); //DC test //if(DSW_GetTactAll() & 0x1){ MCTL_DC_R((FADC_Get(1)-800)*5); MCTL_DC_L((FADC_Get(1)-800)*5); /*} else{ MCTL_DC_R(1535); MCTL_DC_L(0); }*/ //TIMER FOR EACH 100 ms t_c = BTMR_GetRuntime()/500; if (t_c != t_old) { t_old = t_c; DLED_Toggle(DLED_LED1); dipsw = DSW_GetDipAll(); //ENCODER TEST //SDBG_Printf("\n%u: %4d", cnt++, RENC_Get()); //Servo test //MCTL_Servo(sangle); //sangle +=5; if(sangle > MCTL_SWHEEL_MAX) { sangle = -MCTL_SWHEEL_MAX; } //SDBG_Printf("\nServo Angle : %d",sangle); if(flag==0){ flag = 1; } } if(flag){ SDBG_Printf("\n%4d TH:%3d,%3d,%3d\t",t_c,cam_th,CAM_MAX(),CAM_MIN()); for(i_serial = 0; i_serial < NUM_OF_PIXEL; i_serial++){ /*if(i_serial >= NUM_OF_PIXEL){ SDBG_Printf("\n%4d TH:%3d,%3d,%3d\t",t_c,cam_th,CAM_MAX(),CAM_MIN()); //i_serial = 0; flag = 0; }*/ //if( i_serial < NUM_OF_PIXEL ){ if(dipsw & 0x4){//up if(CAM_DATA(i_serial) > cam_th){ SDBG_Printf("."); } else{ //if(CAM_READ(i_serial) , cam_th) SDBG_Printf("!"); } } else{//down SDBG_Printf("%3d ",CAM_DATA(i_serial)); } } /*else{ SDBG_Printf("%3d ",CAM_DATA(i_serial)); i_serial++; if(i_serial >= NUM_OF_PIXEL){ SDBG_Printf("\n%4d TH:%3d,%3d,%3d\t",t_c,cam_th,CAM_MAX(),CAM_MIN()); i_serial = 0; flag = 0; } }*/ /*for(i_serial = 0; i_serial < NUM_OF_PIXEL; i_serial++){ if(dipsw & 0x4){//up if(CAM_DATA(i_serial) > cam_th){ SDBG_Printf("."); } else{ //if(CAM_READ(i_serial) , cam_th) SDBG_Printf("!"); } } else{//down SDBG_Printf("%3d ",CAM_DATA(i_serial)); } }*/ flag = 0; } }
//- timer1를 msec millisecond로 설정하는 함수 // 이 함수 호출 이후 timer1 값은 0이 될 때까지 감소하며 // 이 값은 BTMR_GetTimr1로 확인 가능 void BTMR_SetTimer1(uint32_t msec) { btmr_tstart1 = BTMR_GetRuntime(); btmr_tset1 = msec; }
//- timer0를 msec millisecond로 설정하는 함수 // 이 함수 호출 이후 timer0 값은 0이 될 때까지 감소하며 // 이 값은 BTMR_GetTimr0로 확인 가능 void BTMR_SetTimer0(uint32_t msec) { btmr_tstart0 = BTMR_GetRuntime(); btmr_tset0 = msec; }
void DoMainLoop(void) { //COUNT FOR TIMER static uint32_t t_current, t_old=(uint32_t)-1, t_test,cnt=0; //DIPSW - 1-Camera Run / 2-cam_th / 3-.! or %3d / 4-cam_pulsewidth(exposuretime) //dipsw = DSW_GetDipAll(); //RUN CAMERA //with dip sw 1 /*CAM RUN mode 1 or 2 * main loop 돌때 마다 스위치 값 읽어서 camera run mode를 바꿔주는거 * 카메라를 돌리는건 periodic interrupt timer channel 0 기준 */ if(dipsw & 0b0001) { //sw1 //0x1 CAM_RUN_MODE_SETUP(2);//up DLED_Set(DLED_LED1,0); blinking_LED= DLED_LED2; CAM_RUN2(); } else { CAM_RUN_MODE_SETUP(1);//down DLED_Set(DLED_LED2,0); blinking_LED= DLED_LED1; } //SERIAL COMMUNICATE if (SDBG_IsEvents()) SDBG_ExecuteCallback(); if (MUART_IsEvents()) MUART_ExecuteCallback(); //servo test in main sAngle = (FADC_Get(1)-870)*2*37/156-37; MCTL_Servo(sAngle); //DC test //if(DSW_GetTactAll() & 0x1){ //DC_Speed = (FADC_Get(1)-800)*10; MCTL_DC_R(DC_Speed); MCTL_DC_L(DC_Speed); //TIMER FOR EACH N ms time_gap = 200; t_current = BTMR_GetRuntime()/time_gap; if (t_current != t_old) { t_test = CAM_MICRO_SEC_RETURN(); SDBG_Printf("\n%u: %d", cnt++, t_test); t_old = t_current; DLED_Toggle(blinking_LED); /*DIP SWitch *1-Camera Run Mode *2-cam_threshold *3- .! or %3d 로 카메라 pixel 중 라인 위치, 명암값 출력 *4-cam_pulsewidth(exposure time)*/ dipsw = DSW_GetDipAll(); //Threshold if(dipsw & 0b0010)//sw2 //0x2 cam_th = (uint16_t)(FADC_Get(1)-800)*5; else cam_th = CAM_AVG(); //camera exposure time if(dipsw & 0b1000)//sw4//0x8 CAM_PulseWidth(100);//up else//down CAM_PulseWidth(50); //ENCODER TEST //*/ enc1_current = RENC_Get1(); enc2_current = RENC_Get2(); enc1_rate = enc1_current - enc1_old; enc2_rate = enc2_current - enc2_old; enc1_old = enc1_current; enc2_old = enc2_current; //SDBG_Printf("\n%u: Speed : %4d Rval : %4d %4d RATE : %4d %4d", cnt++, DC_Speed,RENC_Get1(),RENC_Get2(), enc1_rate, enc2_rate); Speed_Control(3);//3cm/s //DC_Speed = (FADC_Get(1)-800)*10;//(A2D_GetChResult_10bit(1)-800)*10; MCTL_DC_R(DC_Speed); MCTL_DC_L(DC_Speed); SDBG_Printf("\n%u: Speed : %4d Rval : %4d RATE : %4d", cnt++, DC_Speed,RENC_Get1(), enc1_rate); //SDBG_Printf("\n%u: US : %8u IR : %4d", cnt++, FUSS_GetMm(FUSS_CH0),FADC_Get(6));//adc6 = pd2 = IR /**/ //Servo test //MCTL_Servo(sAngle); //sAngle +=5; if(sAngle > MCTL_SWHEEL_MAX) { sAngle = -MCTL_SWHEEL_MAX; } //SDBG_Printf("\nServo Angle : %d",sAngle); //if(dipsw & 0x8){//sw4, SDBG if(flag==0) { //flag = 1; } //} } if(flag) { SDBG_Printf("\n %4d TH:%3d,%3d,%3d\t",t_current,cam_th,CAM_MAX(),CAM_MIN()); for(i_serial = 0; i_serial < NUM_OF_PIXEL; i_serial+=2) { //i_serial++){ if(dipsw & 0b0100) { //up//0x04 if(CAM_DATA1(i_serial) > cam_th) { SDBG_Printf("."); } else { //if(CAM_READ(i_serial) , cam_th) SDBG_Printf("!"); } } else { //down SDBG_Printf("%3d ",CAM_DATA1(i_serial)); } } SDBG_Printf("||"); for(i_serial = 0; i_serial < NUM_OF_PIXEL; i_serial+=2) { //i_serial++){ if(dipsw & 0b0100) { //up//0x04 if(CAM_DATA2(i_serial) > cam_th) { SDBG_Printf("."); } else { //if(CAM_READ(i_serial) , cam_th) SDBG_Printf("!"); } } else { //down SDBG_Printf("%3d ",CAM_DATA2(i_serial)); } } flag = 0; } }