Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed QEI MODSERIAL FastPWM ttmath Math
Motor_tryout.cpp
- Committer:
- Feike
- Date:
- 2019-10-14
- Revision:
- 17:6da57acb7bea
- Parent:
- 16:2ad161f709f6
- Child:
- 18:ab0fe311e7f3
File content as of revision 17:6da57acb7bea:
#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);
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;
}
}
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;
{
pc.printf("in while");
int frequency_pwm = 10000; //10 kHz PWM
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);
}
}
}