Signa-bot code for project BioRobotics, at University of Twente.
Dependencies: mbed QEI MODSERIAL FastPWM ttmath Math
Diff: Motor_tryout.cpp
- Revision:
- 17:6da57acb7bea
- Parent:
- 16:2ad161f709f6
- Child:
- 18:ab0fe311e7f3
--- a/Motor_tryout.cpp Mon Oct 14 07:36:10 2019 +0000 +++ b/Motor_tryout.cpp Mon Oct 14 09:05:05 2019 +0000 @@ -1,10 +1,12 @@ #include "mbed.h" #include "MODSERIAL.h" #include "QEI.h" +MODSERIAL pc(USBTX, USBRX); +PwmOut motor1_pwm(PTC2); +DigitalOut motor1_dir(PTC3); +PwmOut motor3_pwm(PTA1); +DigitalOut motor3_dir(PTB9); -DigitalOut motor_pwm(PTC2); -DigitalOut motor_dir(PTC3); -MODSERIAL pc(USBTX, USBRX); QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); int quit; @@ -21,37 +23,48 @@ } } +Ticker show; +void pulseshow() +{ + pc.printf("The counts is %i",counts); + } + + // DE MAIN FUNCTIE int main(void) { pc.baud(115200); + char cc = pc.getc(); while(true) { quit = 0; counts = 0; - char cc = pc.getc(); { pc.printf("in while"); int frequency_pwm = 10000; //10 kHz PWM - PwmOut motor_pwm(PTC2); - PwmOut motor_dir(PTC3); - motor_pwm.period(1.0/(double)frequency_pwm); // T=1/f - motor_dir.write(0); // positief - motor_pwm.write(0.8); // write Duty Cycle - pulse.attach(pulseget,1.0/10000); - if(quit == 1) - { - pulse.detach(); - motor_pwm.write(0); - pc.printf("The motor is off with counts is %i\n\r",counts); - break; - } - wait(1.0/10000); + motor1_pwm.period(1.0/(double)frequency_pwm); // T=1/f + motor1_dir.write(0); // positief + motor1_pwm.write(0.8); // write Duty Cycle + + motor3_pwm.period(1.0/(double)frequency_pwm); // T=1/f + motor3_dir.write(0); // positief + motor3_pwm.write(0.8); // write Duty Cycle + + counts = Encoder.getPulses(); + pc.printf("The counts is %i\n\r",counts); + + //pulse.attach(pulseget,1.0/10000); + // show.attach(pulseshow,1.0/10000); + + //if(quit == 1) + //{ + // pulse.detach(); + // motor1_pwm.write(0); + // motor3_pwm.write(0); + // pc.printf("The motor is off with counts is %i\n\r",counts); + // break; + // } + wait(1.0/10); } - cc = pc.getc(); - counts = 0; - pc.printf("The motor is in final state and counts is %i\n\r",counts); } - } - - + } \ No newline at end of file