unable to generate time axis for a measurement from TimerX,Y

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good day everyone,

On my hardware setup, I am running measurements to measure X value with a sensor. Everything runs fine and all data is generated as it should. The timescale of such a measurement is millisecond to several minutes range.

 

The generated data although needs to be sampled as usual over time, to be plotted as graph X(y). The timekeeping functions of mine are done through the Timer which overflows and generated an interrupt and then everything gets gradually incremented starting from milliseconds. When the system is doing its routine tasks then the timekeeping is fine and it ticks as it should.

 

 

When I run a test from a test() function, basically the CPU drops all its work and only runs this test() function which then generates the data X. If i try to append the milliseconds or seconds from this timekeeping functions, it does not show me the time. Actually it is not working for me to create a time Axis which is time in milliseconds or seconds to be generated during this function execution time test().

 

 

 


#define OVERFLOWS_PER_SECOND        1220          // (F_CPU = 20 MHz, F_OSC Timer / 64) / 255 = ~ 1220 overflows
#define OVERFLOWS_PER_MILLISECOND   2       // (F_CPU = 20 MHz, F_OSC Timer / 64) /255 / 1000 = ~ 1.22 overflows




static inline void initTimer_1(void){

    TCCR1A |= (1 << WGM10);                                                       // Phase Correct PWM 8-Bit Mode
    TCCR1B |= ((1 << CS11) | (1 << CS10));                                                // prescaler = F_CPU/64
    TCCR1A |= ((1 << COM1A1) | (1 << COM1B1));                               // toggle OC1A/OC1B on compare match
    TIMSK1 |= (1 << TOIE1);                                                  // Timer-1 overflow interrupt enable
}



void monthsRun(void){                                                 // small function counts months from Timer

    months_++;
    if(months_ > 12){
        months_ = 0;
        year_ += 1;
    }
}

void daysRun(void){                                                     // small function counts days from Timer

    days_ ++;
    if(days_ > 31){
        days_ = 0;
        monthsRun();
    }
}



void hoursRun(void){                                                   // small function counts hours from Timer

    hours_ ++;
    if(hours_ > 23){
        hours_ = 0;
        daysRun();
    }

}

void minutesRun(void){                                                // small function counts minutes from Timer

    minutes_ ++;
    if(minutes_ > 59){
        minutes_ = 0;
        hoursRun();
    }

void secondsRun(void){                                                 // small function counts seconds from Timer

    seconds_ ++;
    if(seconds_ > 59){
        seconds_ = 0;
        minutesRun();
    }

 

void millisecondsRun(void){

    milliseconds_ ++;
    if(milliseconds_ > 999){
        milliseconds_ = 0;
        secondsRun();
    }
    //printWord(milliseconds_);
    //printString("\r\n");
}

 

 

ISR()....

ISR(TIMER1_OVF_vect){                                                                   

    sys_tick ++;
}

 

this is the event loop......

//-------------------------------------- Event loop --------------------------------------------------------------------------//
        while(1){
            
            if(sys_tick == OVERFLOWS_PER_MILLISECOND){
                sys_tick = 0;
                millisecondsRun();
            }
            pcLinkSerial();
//          espLinkSilent();
//          espLinkSerialTest();
        }
    return(0);
}

 

 

at the moment the output from the function test() looks like this:

 

i would like to print the time in column where TimerX is shown.

ADC-(adcValue) = 126    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 127    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 127    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 127    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 126    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 127    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 127    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 127    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 126    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 127    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 126    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 126    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 126    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000
ADC-(adcValue) = 127    ADC-(lowValue) = 126    ADC-(highValue) = 127   TimerX-(TCNTX) = 00000

 

 

work in progress...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Did you forget that variables shared between ISR() and  main() must be volatile and accessed atomically?

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"