Am I going nuts!!! I'm trying to step through a table at a particular rate and to achieve this I've set up a ticker interrupt. The following code is a fragment of the original but is the minimum program to illustrate the problem of the "while (!sl_flag)" loop waiting for the interrupt "sl_flag " and totally ignoring it. The program hangs in the "while" loop, never reaching the print statements.
#include "mbed.h"
#include "MobileLCD.h"
MobileLCD lcd(p11, p12, p13, p10, p9);
Ticker slice; //specify slice interrupt
DigitalOut led1(LED1); //is something happening led
const int table[20] = {
0,70,139,208,276,342,407,469,530,588,643,695,743,788,829,866,899,
927,951,970
};
int sl_flag = 0;
int fout = 0;
int q = 0;
void slice_flag() {
sl_flag = 1;
led1 = !led1; //see something happening!!
}
int main(){
slice.attach(&slice_flag,0.5); //set up slice interrupt for this note
while(1) {
for(int i=0;i<20;i++) {
fout = table[i];
while (!sl_flag); //wait for interrupt
sl_flag = 0; //reset flag for next time round
//print stuff to show what's happening i.e. debug
lcd.locate(0,5); lcd.printf(" "); //clear print area
lcd.locate(0,5); lcd.printf("%d %d",i, fout);
}
}
}
However, if I give the "while" loop something frivolous to do while it is waiting, it spots the interrupt and executes properly and the printfs show everything counting nicely.
while (!sl_flag) {q++; lcd.locate(0,9) ; lcd.printf("%d ",q);}
Is there something wrong with my code or is the compiler optimising a bit too much?
The fragment is slowed right down so I can see things happening (or not). At full speed, there are no printfs and the ticker period is ~40us. Which brings me to the next question. What is the minimum period and resolution for Ticker - can it cope with float numbers - with 43.5us, for instance?
Pip
Am I going nuts!!! I'm trying to step through a table at a particular rate and to achieve this I've set up a ticker interrupt. The following code is a fragment of the original but is the minimum program to illustrate the problem of the "while (!sl_flag)" loop waiting for the interrupt "sl_flag " and totally ignoring it. The program hangs in the "while" loop, never reaching the print statements.
#include "mbed.h"
#include "MobileLCD.h"
MobileLCD lcd(p11, p12, p13, p10, p9);
Ticker slice; //specify slice interrupt
DigitalOut led1(LED1); //is something happening led
const int table[20] = {
0,70,139,208,276,342,407,469,530,588,643,695,743,788,829,866,899,
927,951,970
};
int sl_flag = 0;
int fout = 0;
int q = 0;
void slice_flag() {
sl_flag = 1;
led1 = !led1; //see something happening!!
}
int main(){
slice.attach(&slice_flag,0.5); //set up slice interrupt for this note
while(1) {
for(int i=0;i<20;i++) {
fout = table[i];
while (!sl_flag); //wait for interrupt
sl_flag = 0; //reset flag for next time round
//print stuff to show what's happening i.e. debug
lcd.locate(0,5); lcd.printf(" "); //clear print area
lcd.locate(0,5); lcd.printf("%d %d",i, fout);
}
}
}
However, if I give the "while" loop something frivolous to do while it is waiting, it spots the interrupt and executes properly and the printfs show everything counting nicely.
while (!sl_flag) {q++; lcd.locate(0,9) ; lcd.printf("%d ",q);}
Is there something wrong with my code or is the compiler optimising a bit too much?
The fragment is slowed right down so I can see things happening (or not). At full speed, there are no printfs and the ticker period is ~40us. Which brings me to the next question. What is the minimum period and resolution for Ticker - can it cope with float numbers - with 43.5us, for instance?
Pip