Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
unsigned int result=((65537.0-(62500/10))+0.5); //the 0.5 is for rounding; TCCR3A = 0; TCCR3B = 1<<CS32 | 0<<CS31 | 0<<CS30; //256 prescale //Timer3 Overflow Interrupt Enable TIMSK3 = 1<<TOIE3; //load the timer for its first cycle TCNT3=result;
TICK_COUNT time_start = clockGetus();stuff_happens();//your code here, probably doing other non-PID stuffTICK_COUNT time_end = clockGetus();TICK_COUNT time_passed=time_end-time_start;PID_system(time_passed);//your code, feed time passed into your PID equation
If i put this in any of the webbot functions (appint_hardware or software) i get complier errors saying the registers (like TCCR3A and the rest) are not defined as a variable. If i put it outside the webbot functions, i get (for all the registers)../SAGAR.c:108: warning: type defaults to 'int' in declaration of 'TIMSK3'../SAGAR.c:111: warning: data definition has no type or storage classand a error of TCNT3:../SAGAR.c:111: warning: type defaults to 'int' in declaration of 'TCNT3'../SAGAR.c:111: error: initializer element is not constant
timerSetMode(TIMER3, TIMER_MODE_NORMAL);timerSetPrescaler(TIMER3, 8);// 8timerOverflowAttach(TIMER3, heading_controller, NULL);
It has a granularity of around 18ms
If portability is what you main goal is, could you not write a function likeattachTimerInterrupt(int frequency, &function);that would see what timers were unused, find one with a (either 8 or 16 bit) divider that would give the correct frequency and attach the function either by compare interrupt, or overflow with a re-seed after the function executes?
The biggest issue i have with your scheduler is this:QuoteIt has a granularity of around 18ms
It gets a call at least once, as i have a rprintf right before the scheduleJob at the end of myCallBack function ; and it prints out the test message once, so that also tells me it's not getting stuck in my code either. I am not hijacking any timers. Any idea what i should look for to get that working?
Also, in your sample code in the pdf for scheduler, you havescheduleJob(&myCallback, someData, timerGetus(),1000);but for what i can tell, there is not timerGetus() function, so did you mean clockGetus()??
And you're still not really selling me on the scheduler thing. I don't want my controller to drift past +- 10% of the intended frequency (+-3ms of the period) in order to keep it a stable control system. I can setup a test now, but I would have to repeat the test every time i added a new layer of complexity to the foreground process, to make sure it does cause the scheduler to 'drift' into the worse case.Can you, with a very high degree of certainty, tell me that the scheduler can stay within that limit, even as my foreground code grows to include complex stuff like sensor based mapping, and even other jobs getting pushed on the scheduler? If not, then it's just not suited for what I want, and I rather stick to a timer interrupt (which guarantees accuracy now and in the future), and just deal with having my code not 100% portable.