I am working on an application that needs to switch tickers on and off. I can switch more than one ticker on without any problems but when I start to detach the interrupts then strange things happen.
In the code example below I switch on four tickers in turn for each LED. Then I switch them off in turn. On my MBed when I switch off the first ticker, the other three spontaneously stop. After a while the first ticker starts up again and the cycle repeats.
Can anyone verify this behaviour and suggest a workaround/fix?
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
Ticker tick1;
Ticker tick2;
Ticker tick3;
Ticker tick4;
void int1(void);
void int2(void);
void int3(void);
void int4(void);
void int1(void) {
led1=!led1;
}
void int2(void) {
led2=!led2;
}
void int3(void) {
led3=!led3;
}
void int4(void) {
led4=!led4;
}
int main() {
while(1) {
printf("Starting first ticker.\n");
tick1.attach(&int1,0.18);
wait(2);
printf("Starting second ticker.\n");
tick2.attach(&int2,0.12);
wait(2);
printf("Starting third ticker.\n");
tick3.attach(&int3,0.1);
wait(2);
printf("Starting fourth ticker.\n");
tick4.attach(&int4,0.15);
wait(2);
printf("Stopping first ticker.\n");
tick1.detach();
led1=0;
wait(2);
printf("Stopping second ticker.\n");
tick2.detach();
led2=0;
wait(2);
printf("Stopping third ticker.\n");
tick3.detach();
led3=0;
wait(2);
printf("Stopping fourth ticker.\n");
tick4.detach();
led4=0;
wait(2);
}
}
I am working on an application that needs to switch tickers on and off. I can switch more than one ticker on without any problems but when I start to detach the interrupts then strange things happen.
In the code example below I switch on four tickers in turn for each LED. Then I switch them off in turn. On my MBed when I switch off the first ticker, the other three spontaneously stop. After a while the first ticker starts up again and the cycle repeats.
Can anyone verify this behaviour and suggest a workaround/fix?
#include "mbed.h" DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); Ticker tick1; Ticker tick2; Ticker tick3; Ticker tick4; void int1(void); void int2(void); void int3(void); void int4(void); void int1(void) { led1=!led1; } void int2(void) { led2=!led2; } void int3(void) { led3=!led3; } void int4(void) { led4=!led4; } int main() { while(1) { printf("Starting first ticker.\n"); tick1.attach(&int1,0.18); wait(2); printf("Starting second ticker.\n"); tick2.attach(&int2,0.12); wait(2); printf("Starting third ticker.\n"); tick3.attach(&int3,0.1); wait(2); printf("Starting fourth ticker.\n"); tick4.attach(&int4,0.15); wait(2); printf("Stopping first ticker.\n"); tick1.detach(); led1=0; wait(2); printf("Stopping second ticker.\n"); tick2.detach(); led2=0; wait(2); printf("Stopping third ticker.\n"); tick3.detach(); led3=0; wait(2); printf("Stopping fourth ticker.\n"); tick4.detach(); led4=0; wait(2); } }