int main(void) { char dutyCycle; UART uart; PWM pwm; uart.init(); uart.println("*** QC-BLCD OS Startup Sequence ***"); uart.println(" > UART initialized"); pwm.init(); uart.println(" > PWM initialized"); uart.println("Startup Sequence successfull!"); uart.println("Main program starts now"); dutyCycle=0; while(42) { /*itoa(dutyCycle,msg,10); println(msg);*/ pwm.setDutyCycle(dutyCycle); dutyCycle++; _delay_ms(200); } }
int main() { PWM pwm; LeftMotor left; RightMotor right; IM::init(); log::emit() << "Tick-Freq: " << PWM::TickFrequency::numerator << " / " << PWM::TickFrequency::denominator << log::endl; log::emit() << "PWM-Freq: " << PWM::DutyFrequency::numerator << " / " << PWM::DutyFrequency::denominator << log::endl; pwm.start(); left.state(LeftMotor::forward); right.state(RightMotor::forward); pwm.value<PWM::channelA>(512); pwm.value<PWM::channelB>(256); while(true) Morpheus::sleep(Morpheus::SleepModes::idle); return 0; }
void LIGHT::light_init() { //pwm initialized outside //PWM head(PWM::pwm1, 0); //PWM for head lights //PWM tail(PWM::pwm2, 0); //PWM for tail lights hl_mode=OFF; data_rcv.headlights=true; head.set(0); tail.set(0); }
// FIXME: parity void tape::write(uint8_t b) { #if defined(PWM_DUTY) pwm.set_duty(PWM_DUTY); #endif write_bit(0); for (int i = 0; i < _data_bits; i++) { write_bit(b & 1); b >>= 1; } write_bit(1); if (_stop_bits == 2) write_bit(1); pwm.set_duty(0); }
void setup() { ebox_init(); uart1.begin(9600); PB8.mode(OUTPUT_PP); p = 1; ic.begin(p);//初始化输入捕获参数,p分频 ic.attch_ic_interrupt(mesure_frq);//绑定捕获中断事件函数 ic.attch_update_interrupt(update_event); pwm1.begin(1,500); pwm1.set_oc_polarity(1); }
int main(void) { NVIC_Excitation(); pwm.init(&pwm); adcdim.init(&adcdim); // dacout.Output1 = 1000; // dacout.init(&dacout); spiout.init(&spiout); for(;;); }
void PwmEnable15(void) { pwm.Enable(7); }
void PwmEnable13(void) { pwm.Enable(5); }
void PwmEnable12(void) { pwm.Enable(4); }
void PwmSetPolarity16(BOOL Polarity) { pwm.SetPolarity(8,Polarity); }
void PwmSetPolarity14(BOOL Polarity) { pwm.SetPolarity(6,Polarity); }
void PwmSetPolarity12(BOOL Polarity) { pwm.SetPolarity(4,Polarity); }
void PwmSetDuty13(U16 Duty) { pwm.SetDuty(5,Duty); }
void PwmSetDuty12(U16 Duty) { pwm.SetDuty(4,Duty); }
void PwmSetDuty6(U16 Duty) { pwm.SetDuty(3,Duty); }
void PwmSetPolarity5(BOOL Polarity) { pwm.SetPolarity(2,Polarity); }
void PwmSetPolarity6(BOOL Polarity) { pwm.SetPolarity(3,Polarity); }
void PwmSetDuty14(U16 Duty) { pwm.SetDuty(6,Duty); }
void PwmSetPolarity13(BOOL Polarity) { pwm.SetPolarity(5,Polarity); }
void PwmSetDuty15(U16 Duty) { pwm.SetDuty(7,Duty); }
void PwmSetPolarity15(BOOL Polarity) { pwm.SetPolarity(7,Polarity); }
void PwmSetDuty16(U16 Duty) { pwm.SetDuty(8,Duty); }
void PwmSetPolarity21(BOOL Polarity) { pwm.SetPolarity(9,Polarity); }
void PwmSetDuty21(U16 Duty) { pwm.SetDuty(9,Duty); }
void PwmSetPolarity26(BOOL Polarity) { pwm.SetPolarity(10,Polarity); }
void PwmSetDuty26(U16 Duty) { pwm.SetDuty(10,Duty); }
void PwmEnable14(void) { pwm.Enable(6); }
void PwmSetPolarity0(BOOL Polarity) { pwm.SetPolarity(0,Polarity); }
int main() { int breakflag=0; float M = 1.0; short m = 0; short cnt = 0; PWM pwm; RGBled led; js_event js; if(!led.initialize()) return EXIT_FAILURE; //-------- PS3 Controller setting -------- int joy_fd(-1), num_of_axis(0), num_of_buttons(0); char name_of_joystick[80]; vector<char> joy_button; vector<int> joy_axis; if((joy_fd = open(JOY_DEV, O_RDONLY)) < 0) { printf("Failed to open %s", JOY_DEV); cerr << "Failed to open " << JOY_DEV << endl; return -1; } ioctl(joy_fd, JSIOCGAXES, &num_of_axis); ioctl(joy_fd, JSIOCGBUTTONS, &num_of_buttons); ioctl(joy_fd, JSIOCGNAME(80), &name_of_joystick); joy_button.resize(num_of_buttons, 0); joy_axis.resize(num_of_axis, 0); printf("Joystick: %s axis: %d buttons: %d\n", name_of_joystick, num_of_axis, num_of_buttons); fcntl(joy_fd, F_SETFL, O_NONBLOCK); // using non-blocking mode for ( int i = 0 ; i < 4 ; i++ ) { if ( !pwm.init(i) ) { fprintf(stderr, "Output Enable not set. Are you root?\n"); return 0; } pwm.enable(i); pwm.set_period(i, 500); } printf("\nStart thrust test !\n"); ///// Clock setting struct timeval tval; unsigned long now_time,past_time,interval; gettimeofday(&tval,NULL); now_time=1000000 * tval.tv_sec + tval.tv_usec; past_time = now_time; interval = now_time - past_time; printf("set motor 'RIGHT'\n"); //========================== Main Loop ============================== while(true) { led.setColor(Colors::Red); while(true) { gettimeofday(&tval,NULL); past_time = now_time; now_time=1000000 * tval.tv_sec + tval.tv_usec; interval = now_time - past_time; //js_event js; read(joy_fd, &js, sizeof(js_event)); switch(js.type & ~JS_EVENT_INIT) { case JS_EVENT_AXIS: joy_axis[(int)js.number] = js.value; break; case JS_EVENT_BUTTON: joy_button[(int)js.number] = js.value; //printf("%5d\n %5d\n",(int)js.number,js.value); break; } if (joy_button[12]==1){ if (joy_button[4]==1){ M = M + 0.1; printf ( "PWM UP : %f\n" ,M ); } if (joy_button[6]==1){ M = M - 0.1; printf ( "PWM down : %f\n" ,M ); } } if (joy_button[13]==1){ if (joy_button[4]==1){ M = M + 0.001; printf ( "PWM UP : %f\n" ,M ); } if (joy_button[6]==1){ M = M - 0.001; printf ( "PWM down : %f\n" ,M ); } } if (joy_button[14]==1){ if (joy_button[4]==1){ M = M + 0.0001; printf ( "PWM UP : %f\n" ,M ); } if (joy_button[6]==1){ M = M - 0.0001; printf ( "PWM down : %f\n" ,M ); } } if (joy_button[15]==1){ if (joy_button[4]==1){ M = M + 0.00001; printf ( "PWM UP : %f\n" ,M ); } if (joy_button[6]==1){ M = M - 0.0001; printf ( "PWM down : %f\n" ,M ); } } if (joy_button[11]==1){ cnt++; if (cnt>30){ M = 2.0; printf( "Set PWM MAX!\n" ); cnt = 0; } } if (joy_button[10]==1){ cnt++; if (cnt>30){ M = 1.0; printf( "Set PWM MIN!\n" ); cnt = 0; } } if ( M > 2.0 ) M = 2.0; if ( M < 1.0 ) M = 1.0; pwm.set_duty_cycle(m, M); if (joy_button[3]==1){ break; } do{ gettimeofday(&tval,NULL); interval=1000000 * tval.tv_sec + tval.tv_usec - now_time; }while(interval<2000); } led.setColor(Colors::Blue); while (joy_button[3]==1){ read(joy_fd, &js, sizeof(js_event)); switch(js.type & ~JS_EVENT_INIT) { case JS_EVENT_AXIS: joy_axis[(int)js.number] = js.value; break; case JS_EVENT_BUTTON: joy_button[(int)js.number] = js.value; //printf("%5d\n %5d\n",(int)js.number,js.value); break; } } while (true){ read(joy_fd, &js, sizeof(js_event)); switch(js.type & ~JS_EVENT_INIT) { case JS_EVENT_AXIS: joy_axis[(int)js.number] = js.value; break; case JS_EVENT_BUTTON: joy_button[(int)js.number] = js.value; //printf("%5d\n %5d\n",(int)js.number,js.value); break; } M = 1.0; if (joy_button[4]==1){ m = 2; printf("set motor 'FRONT'\n"); } if (joy_button[5]==1){ m = 0; printf("set motor 'RIGHT'\n"); } if (joy_button[6]==1){ m = 3; printf("set motor 'REAR'\n"); } if (joy_button[7]==1){ m = 1; printf("set motor 'LEFT'\n"); } if (joy_button[3]==1){ break; } if (joy_button[0]==1){ breakflag=1; break; } else breakflag = 0; } if (breakflag == 1)break; else breakflag = 0; while (joy_button[3]==1){ read(joy_fd, &js, sizeof(js_event)); switch(js.type & ~JS_EVENT_INIT) { case JS_EVENT_AXIS: joy_axis[(int)js.number] = js.value; break; case JS_EVENT_BUTTON: joy_button[(int)js.number] = js.value; //printf("%5d\n %5d\n",(int)js.number,js.value); break; } } } led.setColor(Colors::Green); return 0; }
void PwmSetPolarity1(BOOL Polarity) { pwm.SetPolarity(1,Polarity); }