Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 5 months ago.
STM32F103RB Ticker Crash
Hello all,
For the next program i'm using a STM32F103RB nucleo board. I'm trying to use a ticker to set an interrupt at a changing intervaltime. I want to use it to create an accurate acceleration with PWM. Therefor I need to attach and detach the ticker multiple times at high speeds. After a fixed amount of runs the program suddenly crashes.
#include "mbed.h"
Serial pc(USBTX, USBRX);
DigitalOut myLed(LED1);
Ticker ledTicker;
bool ledBlink;
bool tickerTrigger;
int n;
void blink(){
if(ledBlink == true){
myLed =0;
ledBlink = false;
ledTicker.detach();
tickerTrigger = false;
}
else if(ledBlink == false){
myLed = 1;
ledBlink = true;
ledTicker.detach();
tickerTrigger = false;
}
}
int main() {
while(1) {
if(tickerTrigger == false){
n++;
pc.printf("%i\r\n", n);
tickerTrigger = true;
ledTicker.attach_us(&blink, 250);
}
}
}
When i change the interval times, the program always crashes at the same points:
- 250 us interval crashes at n = 14071
- 500 us interval crashes at n = 13154
- 1000 us interval crashes at n = 10305
- 2000 us interval crashes at n = 14628
- 3000 us interval crashes at n = 7097
- 4000 us interval crashes at n = 3334
- 5000 us interval crashes at n = 9562
The next error is reported: mbed assertation failed: _ops, file: /home/arm/mbed_jenkins/workspace/bm_wrap/172/mbed-os/BUILD/mbed/platform/Callback.h, line
When I delete the serial communication and/or counter n the program still crashes.
Thanks in advance!
1 Answer
8 years, 5 months ago.
Try something like this. Be sure to watch printf's when you have tight loops. This will generate a variable pulse. Might look into FastPWM instead depending on the accuracy of what you're really trying to do.
#include "mbed.h"
Serial pc(USBTX, USBRX);
DigitalOut myLed(LED1);
Timeout ledTicker;
bool ledBlink;
bool tickerTrigger;
int n;
int delay=250,inc=10;
void blink(){
myLed = !ledBlink;
ledBlink = !ledBlink;
tickerTrigger = false;
delay += inc;
if(delay > 12345)inc=-inc;
if(delay < 123)inc = -inc;
}
int main() {
pc.baud(921600);
while(1) {
if(tickerTrigger == false){
n++;
pc.printf("%i\r\n", n);
tickerTrigger = true;
ledTicker.attach_us(&blink, delay);
}
}
}