IntervalTimer question on Teensy 3.2

Status
Not open for further replies.

roomed

New member
Hello. I've been trying to use the IntervalTimer library to manage the "main timing" functionality of a voltage sequencer im designing. The question I have is basically about how this library works.

It looks like I can't use the begin function inside of the main loop. This is kida confusing to me cause if its not posible to initialize the timer inside the loop, how is the .end() function usable for freeing a timer in order to use it for another object? This might be a dumb question but I can't find more documentation/information than the one I already have. This is an example of what I tested.

As you can see I make the .begin() function to run one time.

void loop()
if(first){
main_timer.begin(tim, t);
analogWrite(pin_CV, round(sequence));
}else{
first = 0;
analogWrite(pin_CV, round(sequence));
}

Thanks in advanced.
 
It makes your code more readable if you enclose it within code tags.
You are more likely to get some help then.
It's not difficult!!
Code:
void loop()
     if(first){
          main_timer.begin(tim, t);
          analogWrite(pin_CV, round(sequence[i]));
     }else{
          first = 0;
          analogWrite(pin_CV, round(sequence[i]));
     }
 
It looks like I can't use the begin function inside of the main loop

Please provide the entire program so that we can see what you're doing. Select all of the text in your INO program, then copy and paste into a forum message. After you paste, use your mouse to select all of the code, then click on the '#' symbol in the menu above. This formats the code to make it easier for others to read, as @BriComp said.
 
Here is an example sketch with IntervalTimer and begin() is called from loop(). It works.

Code:
#include <IntervalTimer.h>

IntervalTimer main_timer;

volatile uint32_t main_timer_count;

void main_timer_ISR( void )
{
  main_timer_count++;
}

void setup()   {                
  while (!Serial) {} // wait for USB serial ready  
}

uint32_t first = 1; // detect first execution of loop()
uint32_t prev_count; // to compute change in main_timer_count

void loop() {
  if (first == 1) { // first time in loop()?
    main_timer.begin( main_timer_ISR, 1000 );
    first = 0; // make sure main_timer.begin() gets called only once
  }
  delay( 1000 ); // wait one second
  Serial.println( main_timer_count - prev_count ); // print number of main_timer interrupts
  prev_count = main_timer_count; // save for next time
}
 
It makes your code more readable if you enclose it within code tags.
You are more likely to get some help then.
It's not difficult!!

Please provide the entire program so that we can see what you're doing. Select all of the text in your INO program, then copy and paste into a forum message. After you paste, use your mouse to select all of the code, then click on the '#' symbol in the menu above. This formats the code to make it easier for others to read, as @BriComp said.

Sorry for the improper post, won't happen again. Thanks for the help. I managed to find the problem in my code.

Again, thank you very much for the quick response and sorry for doing an improper post.
 
Status
Not open for further replies.
Back
Top