![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Robot tryout
Dependencies: mbed QEI biquadFilter MODSERIAL FastPWM ttmath Math
Motor_tryout.cpp
- Committer:
- Feike
- Date:
- 2019-10-14
- Revision:
- 16:2ad161f709f6
- Parent:
- 14:b813ddfbcd71
- Child:
- 17:6da57acb7bea
File content as of revision 16:2ad161f709f6:
#include "mbed.h" #include "MODSERIAL.h" #include "QEI.h" DigitalOut motor_pwm(PTC2); DigitalOut motor_dir(PTC3); MODSERIAL pc(USBTX, USBRX); QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); int quit; int counts = 0; int limit_pos = 8400; Ticker pulse; void pulseget() { counts = Encoder.getPulses(); if(counts > limit_pos) { quit = 1; } } // DE MAIN FUNCTIE int main(void) { pc.baud(115200); 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); } cc = pc.getc(); counts = 0; pc.printf("The motor is in final state and counts is %i\n\r",counts); } }