I have some simple code for my stepper motor controller. This following code suppose to generate right number of pulses per second. If waiting period is 10000us, then program is supposed to print out 100 ( 10^6/10000 = 100). But If I change waiting period is 5000us, then program still prints out 100. Could someone explain what is missing here?
Environment: Mbed studio 1.0/ Nucleo-F401RE
#include “mbed.h”
BufferedSerial pc(USBTX, USBRX);
FileHandle *mbed::mbed_override_console(int fd)
{
return &pc;
}
Thread thread;
int pulses = 0;
void motor_thread()
{
while (true) {
wait_us(10000);
pulses++;
}
}
int main()
{
Timer t;
t.start();
thread.start(motor_thread);
while (true) {
if(t.read() >= 1) {
printf(“pulse: %d\n”, pulses);
pulses = 0;
t.reset();
}
}
}