11 years, 1 month ago.

How reset the Ticker?

Hi, My test code work good in beginning but after 10 minutes my time_impulse become unstable. if i push on reset button to restart progam and it become stable again. What can be the cause? I think should be the timer. If yes, how can i reset the Ticker? Thank you, Vilounha

#include "mbed.h"
int start=0,count=0;
char command=0;

Ticker tick;
InterruptIn event(PTD6);
Serial pc(NC,USBRX);
DigitalOut lamp1(PTB8);
void time_impulse() {
    if(start){
        if((count==command)||(count==command+64)){
            lamp1=1;
            wait_us(5);
            lamp1=0;
        }
        else
        {
            lamp1=0;
        }
        if(count>128){
            start=0;
        }
        else count++;
    }
    
    
}
// sync with 60Hz zero-crossing AC Line
void zero_impulse() {
        start=1;
        count=0;
 }
int main() {
    tick.attach_us(&time_impulse,130);//1/60./128.= 0.00013020
    event.rise(&zero_impulse); 
    
    while(1){
        command=pc.getc();
        //pc.putc(command);
     }
}

2 Answers

11 years, 1 month ago.

Hello Vilounha,

I would guess the issue could be, you are writing the variable start and count in both functions. They are ISRs, if I understand this correctly, and one could have a higher priority. I am not sure how the MBED is configured. But I guess the interrupts can be nested. So the ISR with the higher priority changes a value which gets overwriten as soon as the ISR ends. e.g.

if(count>128){

zero_impulse() {start=1;count=0;}

start=0; }

Something like that would explain why you have an issue after some time. This is a matter of probability.

Best Regards

Klaus

Hi Klaus, I will look at ISRs priority. How to setup a priority of ISRs? Thank you, Regards, Vilounha

posted by Vilounha Phanalasy 16 Mar 2013
11 years, 1 month ago.

Try

volatile int start=0,count=0;
volatile char command=0;

Best regards
Neni