parent
c278296553
commit
8c1d74acda
@ -0,0 +1 @@
|
|||||||
|
../shared/softtimer.c
|
||||||
@ -0,0 +1 @@
|
|||||||
|
../shared/softtimer.h
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
#include "softtimer.h"
|
||||||
|
|
||||||
|
volatile uint16_t timer1_acc;
|
||||||
|
uint16_t softtimer_last[SOFTTIMERNUMS];
|
||||||
|
|
||||||
|
void softtimer_reset(uint8_t timernum){
|
||||||
|
softtimer_last[timernum] = timer1_acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t softtimer(uint8_t timernum, uint16_t interval){
|
||||||
|
uint16_t timer1_acc_tmp = timer1_acc; // because of volatile
|
||||||
|
if((uint16_t)(timer1_acc_tmp - (uint16_t)(softtimer_last[timernum]) >= interval )){
|
||||||
|
softtimer_last[timernum] = timer1_acc_tmp;
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SOFTTIMER( <YOUR TIMER NUM>, <YOUR INTERVAL>);
|
||||||
|
// #define SOFTTIMER(n,a) if(softtimer((n),(a*8)))
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
// NOTES:
|
||||||
|
// Please #define SOFTTIMERNUMS aNum before including this!
|
||||||
|
|
||||||
|
#ifndef __SOFTTIMER_H
|
||||||
|
#define __SOFTTIMER_H
|
||||||
|
|
||||||
|
extern volatile uint16_t timer1_acc;
|
||||||
|
extern uint16_t softtimer_last[SOFTTIMERNUMS];
|
||||||
|
|
||||||
|
|
||||||
|
void softtimer_reset(uint8_t timernum);
|
||||||
|
uint8_t softtimer(uint8_t timernum, uint16_t interval);
|
||||||
|
|
||||||
|
// SOFTTIMER( <YOUR TIMER NUM>, <YOUR INTERVAL>);
|
||||||
|
#define SOFTTIMER(n,a) if(softtimer((n),(a*8)))
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in new issue