Hi all,
I oiginally posted this in the questions area but it seems that does not get a lot of "foot traffic" so I'm reposting here. PLease excuse me if I'm comitting a no-no by cross posting!
I am currently utilizing a PWM pin to be a "simulator" for some hardware that I am going to build. Basically I am going to use the PWM to drive a stepper driver (from Pololu) and I'm using an opto-interrultor connected to a pin on the mbed and that pin is configured as an interrupt. This way I can count the interrupt time and be certain that the motor is actually moving at the RPM expected.
In the meantime I have the PWM directly driving the interrupt pin. (I'm only counting a "pulse" every 200th interrupt since the stepper takes 200 steps per revolution.)
The problem I am having is that when I go to change the period of the pulses on the PWM, the interrupts stop happening.
Below is a snippet of my code. I have tried both with a pointer tp PwmOut and a delete/new pair trying to "kickstart" things and with just a regular PwmOut member variable:
motorSim = new PwmOut(p21);
motorPulse.rise(&revolution);
motorSim->period_us(1000);
motorSim->pulsewidth_us(2);
wait(10);
char buf[1024];
int ptr = 0;
//pc.printf("\r\n\r\n"); //Position to where input will be
displayUpdater.attach(&updateDisplay, 1.0);
delete motorSim;
motorSim = new PwmOut(p21);
motorSim->period_ms(2000);
motorSim->pulsewidth_us(2);
So once I get input on the serial line and convert it into a number I calculate and change the period using period_ms(); but when that happens my interrupt code stops firing. So I am assuming that my change to the period is stopping the PWM output.
Any suggestions as to how I can change the period without killing the PWM?
Thanks in advance!
Hi all,
I oiginally posted this in the questions area but it seems that does not get a lot of "foot traffic" so I'm reposting here. PLease excuse me if I'm comitting a no-no by cross posting!
I am currently utilizing a PWM pin to be a "simulator" for some hardware that I am going to build. Basically I am going to use the PWM to drive a stepper driver (from Pololu) and I'm using an opto-interrultor connected to a pin on the mbed and that pin is configured as an interrupt. This way I can count the interrupt time and be certain that the motor is actually moving at the RPM expected.
In the meantime I have the PWM directly driving the interrupt pin. (I'm only counting a "pulse" every 200th interrupt since the stepper takes 200 steps per revolution.)
The problem I am having is that when I go to change the period of the pulses on the PWM, the interrupts stop happening.
Below is a snippet of my code. I have tried both with a pointer tp PwmOut and a delete/new pair trying to "kickstart" things and with just a regular PwmOut member variable:
So once I get input on the serial line and convert it into a number I calculate and change the period using period_ms(); but when that happens my interrupt code stops firing. So I am assuming that my change to the period is stopping the PWM output.
Any suggestions as to how I can change the period without killing the PWM?
Thanks in advance!