Fixed non-blocking delays not working
* fixed ARR value - removed reset function
This commit is contained in:
parent
3682d10a27
commit
9523dc8a78
@ -108,19 +108,22 @@ int timer_wait_ms(TIM_TypeDef* tmr, uint16_t ms, OnTick cb) {
|
|||||||
else if (tmr == TIM4) RCC->APB1ENR |= 1<<2;
|
else if (tmr == TIM4) RCC->APB1ENR |= 1<<2;
|
||||||
else return -1; // no such timer
|
else return -1; // no such timer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set period
|
||||||
|
tmr->ARR = 0xFFFFFFFF;
|
||||||
|
|
||||||
} else { //non-blocking
|
} else { //non-blocking
|
||||||
if(timer_config_cb(tmr, &clk, cb)) return -1;
|
if(timer_config_cb(tmr, &clk, cb)) return -1;
|
||||||
|
|
||||||
|
// set period
|
||||||
|
tmr->ARR = ms-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set mode
|
// set mode
|
||||||
tmr->CR1 |= (1<<7); //buffering
|
tmr->CR1 = (1<<7) | (1<<2); //buffering and update settings
|
||||||
tmr->CR1 |= (1<<3); //one pulse mode
|
tmr->CR1 |= (1<<3); //one pulse mode
|
||||||
|
|
||||||
// set period
|
// set prescaler 1ms
|
||||||
tmr->ARR = 0xFFFFFFFF;
|
|
||||||
|
|
||||||
// set prescaler 1us
|
|
||||||
tmr->PSC = 8*(clk/1000)-1; //PSC = clk/f - 1 | don't know why 8 times..
|
tmr->PSC = 8*(clk/1000)-1; //PSC = clk/f - 1 | don't know why 8 times..
|
||||||
|
|
||||||
timer_start(tmr);
|
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
|
else return -1; // no such timer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set period
|
||||||
|
tmr->ARR = 0xFFFFFFFF;
|
||||||
|
|
||||||
} else { //non-blocking
|
} else { //non-blocking
|
||||||
if(timer_config_cb(tmr, &clk, cb)) return -1;
|
if(timer_config_cb(tmr, &clk, cb)) return -1;
|
||||||
|
|
||||||
|
// set period
|
||||||
|
tmr->ARR = us-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set mode
|
// set mode
|
||||||
tmr->CR1 |= (1<<7); //buffering
|
tmr->CR1 = (1<<7) | (1<<2); //buffering and update settings
|
||||||
tmr->CR1 |= (1<<3); //one pulse mode
|
tmr->CR1 |= (1<<3); //one pulse mode
|
||||||
|
|
||||||
// set period
|
|
||||||
tmr->ARR = 0xFFFFFFFF;
|
|
||||||
|
|
||||||
// set prescaler 1us
|
// set prescaler 1us
|
||||||
tmr->PSC = 8*(clk/1000000)-1; //PSC = clk/f - 1 | don't know why 8 times..
|
tmr->PSC = 8*(clk/1000000)-1; //PSC = clk/f - 1 | don't know why 8 times..
|
||||||
|
|
||||||
@ -229,8 +235,8 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
|||||||
tmr->SR &= !1;
|
tmr->SR &= !1;
|
||||||
|
|
||||||
// set mode
|
// set mode
|
||||||
tmr->CR1 = (1<<7); //buffering
|
tmr->CR1 = (1<<7) | (1<<2); //buffering and update settings
|
||||||
tmr->DIER = (1<<0); //Enable interrupts
|
tmr->DIER = (1<<0); //Enable interrupts
|
||||||
|
|
||||||
// set prescaler 1ms
|
// set prescaler 1ms
|
||||||
tmr->PSC = 8*(clk/1000)-1; //PSC = clk/f - 1 | don't know why 8 times...
|
tmr->PSC = 8*(clk/1000)-1; //PSC = clk/f - 1 | don't know why 8 times...
|
||||||
|
|||||||
@ -42,6 +42,10 @@ void timer_start(TIM_TypeDef *tmr);
|
|||||||
void timer_stop(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);
|
int timer_enc_init(TIM_TypeDef* tmr);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user