Fixed non-blocking delays not working
* fixed ARR value - removed reset function
This commit is contained in:
parent
3682d10a27
commit
9523dc8a78
@ -109,18 +109,21 @@ int timer_wait_ms(TIM_TypeDef* tmr, uint16_t ms, OnTick cb) {
|
||||
else return -1; // no such timer
|
||||
}
|
||||
|
||||
} else { //non-blocking
|
||||
if(timer_config_cb(tmr, &clk, cb)) return -1;
|
||||
}
|
||||
|
||||
// set mode
|
||||
tmr->CR1 |= (1<<7); //buffering
|
||||
tmr->CR1 |= (1<<3); //one pulse mode
|
||||
|
||||
// set period
|
||||
tmr->ARR = 0xFFFFFFFF;
|
||||
|
||||
// set prescaler 1us
|
||||
} else { //non-blocking
|
||||
if(timer_config_cb(tmr, &clk, cb)) return -1;
|
||||
|
||||
// set period
|
||||
tmr->ARR = ms-1;
|
||||
}
|
||||
|
||||
// set mode
|
||||
tmr->CR1 = (1<<7) | (1<<2); //buffering and update settings
|
||||
tmr->CR1 |= (1<<3); //one pulse mode
|
||||
|
||||
// set prescaler 1ms
|
||||
tmr->PSC = 8*(clk/1000)-1; //PSC = clk/f - 1 | don't know why 8 times..
|
||||
|
||||
timer_start(tmr);
|
||||
@ -149,17 +152,20 @@ int timer_wait_us(TIM_TypeDef* tmr, uint16_t us, OnTick cb) {
|
||||
else return -1; // no such timer
|
||||
}
|
||||
|
||||
// set period
|
||||
tmr->ARR = 0xFFFFFFFF;
|
||||
|
||||
} else { //non-blocking
|
||||
if(timer_config_cb(tmr, &clk, cb)) return -1;
|
||||
|
||||
// set period
|
||||
tmr->ARR = us-1;
|
||||
}
|
||||
|
||||
// set mode
|
||||
tmr->CR1 |= (1<<7); //buffering
|
||||
tmr->CR1 = (1<<7) | (1<<2); //buffering and update settings
|
||||
tmr->CR1 |= (1<<3); //one pulse mode
|
||||
|
||||
// set period
|
||||
tmr->ARR = 0xFFFFFFFF;
|
||||
|
||||
// set prescaler 1us
|
||||
tmr->PSC = 8*(clk/1000000)-1; //PSC = clk/f - 1 | don't know why 8 times..
|
||||
|
||||
@ -229,7 +235,7 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
||||
tmr->SR &= !1;
|
||||
|
||||
// set mode
|
||||
tmr->CR1 = (1<<7); //buffering
|
||||
tmr->CR1 = (1<<7) | (1<<2); //buffering and update settings
|
||||
tmr->DIER = (1<<0); //Enable interrupts
|
||||
|
||||
// set prescaler 1ms
|
||||
|
||||
@ -42,6 +42,10 @@ void timer_start(TIM_TypeDef *tmr);
|
||||
void timer_stop(TIM_TypeDef *tmr);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/** timer_enc_init
|
||||
* setup timer to read encoder output and keep track of it's position in the
|
||||
* CNT register whithout using CPU time
|
||||
*/
|
||||
int timer_enc_init(TIM_TypeDef* tmr);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user