Timer added the timerSetHz()

interrupts
key 4 years ago
parent c1d7904314
commit 7d85aa1c0f

@ -45,10 +45,6 @@ void timerReset(timerNo_t timer);
void timerActivateBus(timerNo_t timer); void timerActivateBus(timerNo_t timer);
void timerEnableTimer(timerNo_t timer); void timerEnableTimer(timerNo_t timer);
void timerDisableTimer(timerNo_t timer); void timerDisableTimer(timerNo_t timer);
// -> clock source is set by the clock tree and cant be individually set. This should be done
// in the clock domain and nt here in the timerdomain. For reference one can look at the nucleo
// stm32f042k6 clock tree diagramm in reference Manual
//void timerSetClkSource(timerNo_t timer, clkSources_t clk);
void timerSetMode(timerNo_t timer, timerMode_t mode); void timerSetMode(timerNo_t timer, timerMode_t mode);
void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction); void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction);
void timerSetPrescaler(timerNo_t timer, uint32_t prescaler); void timerSetPrescaler(timerNo_t timer, uint32_t prescaler);

@ -30,10 +30,6 @@ void timerDisableTimer(timerNo_t timer)
BASE->CR1 &=~ 0x01; //all the timers have the same CEN bit in CR1 register pos 0 BASE->CR1 &=~ 0x01; //all the timers have the same CEN bit in CR1 register pos 0
} }
void timerSetClkSource(timerNo_t timer, clkSources_t clk)
{
}
void timerSetMode(timerNo_t timer, timerMode_t mode) void timerSetMode(timerNo_t timer, timerMode_t mode)
{ {
@ -82,18 +78,32 @@ void timerClearUpdateInterrupt(timerNo_t timer)
} }
/* Second stage configuration */ /* Second stage configuration */
/* Bus Clock
* ------------------------------ = Duty (Hz)
* (Prescaler-1) * (Period-1)
*/
void timerSetHz(timerNo_t timer, uint16_t hz) void timerSetHz(timerNo_t timer, uint16_t hz)
{ {
uint32_t prescaler; uint32_t prescaler = 8000000;
uint32_t period; uint32_t period = 0;
uint32_t temp = 0;
do{
prescaler = prescaler / 10;
}while(prescaler > 0xffff);
do{
period = period + 1;
temp = 8000000/(prescaler*(period));
}while(temp >= hz);
timerActivateBus(timer); timerActivateBus(timer);
timerSetPrescaler(timer, 1599); timerSetPrescaler(timer, prescaler-1);
timerSetAutoReload(timer, 9999); timerSetAutoReload(timer, period-1);
timerClearCounter(timer); timerClearCounter(timer);
timerEnableTimer(timer);
} }
void timerSetMs(timerNo_t timer, uint16_t ms) void timerSetMs(timerNo_t timer, uint16_t ms)

@ -15,10 +15,8 @@ int main(int argc, char *argv[])
delayInitMs(8000000, 1000); delayInitMs(8000000, 1000);
timerActivateBus(timer_2);
timerSetPrescaler(timer_2, 8000-1); timerSetHz(timer_2,10);
timerSetAutoReload(timer_2, 1000-1);
timerClearCounter(timer_2);
timerEnableTimer(timer_2); timerEnableTimer(timer_2);
pinConfig(pinB3, output, pushPull, def_res, def_speed); pinConfig(pinB3, output, pushPull, def_res, def_speed);

Loading…
Cancel
Save