Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2071 add support for max overflow value for 32 bits timer #2072

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cores/arduino/HardwareTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class HardwareTimer {
void setPrescaleFactor(uint32_t prescaler); // set prescaler register (which is factor value - 1)
uint32_t getPrescaleFactor();

void setOverflow(uint32_t val, TimerFormat_t format = TICK_FORMAT); // set AutoReload register depending on format provided
uint32_t getOverflow(TimerFormat_t format = TICK_FORMAT); // return overflow depending on format provided
void setOverflow(uint64_t val, TimerFormat_t format = TICK_FORMAT); // set AutoReload register depending on format provided
uint64_t getOverflow(TimerFormat_t format = TICK_FORMAT); // return overflow depending on format provided

void setPWM(uint32_t channel, PinName pin, uint32_t frequency, uint32_t dutycycle, callback_function_t PeriodCallback = nullptr, callback_function_t CompareCallback = nullptr); // Set all in one command freq in HZ, Duty in percentage. Including both interrupt.
void setPWM(uint32_t channel, uint32_t pin, uint32_t frequency, uint32_t dutycycle, callback_function_t PeriodCallback = nullptr, callback_function_t CompareCallback = nullptr);
Expand Down
12 changes: 6 additions & 6 deletions libraries/SrcWrapper/src/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,18 +483,18 @@ void HardwareTimer::setPrescaleFactor(uint32_t prescaler)
* MICROSEC_FORMAT: return number of microsecondes for overflow
* HERTZ_FORMAT: return frequency in hertz for overflow
*/
uint32_t HardwareTimer::getOverflow(TimerFormat_t format)
uint64_t HardwareTimer::getOverflow(TimerFormat_t format)
{
// Hardware register correspond to period count-1. Example ARR register value 9 means period of 10 timer cycle
uint32_t ARR_RegisterValue = LL_TIM_GetAutoReload(_timerObj.handle.Instance);
uint32_t Prescalerfactor = LL_TIM_GetPrescaler(_timerObj.handle.Instance) + 1;
uint32_t return_value;
uint64_t return_value;
switch (format) {
case MICROSEC_FORMAT:
return_value = (uint32_t)(((ARR_RegisterValue + 1) * Prescalerfactor * 1000000.0) / getTimerClkFreq());
return_value = (uint64_t)(((ARR_RegisterValue + 1) * Prescalerfactor * 1000000.0) / getTimerClkFreq());
break;
case HERTZ_FORMAT:
return_value = (uint32_t)(getTimerClkFreq() / ((ARR_RegisterValue + 1) * Prescalerfactor));
return_value = (uint64_t)(getTimerClkFreq() / ((ARR_RegisterValue + 1) * Prescalerfactor));
break;
case TICK_FORMAT:
default :
Expand All @@ -518,10 +518,10 @@ uint32_t HardwareTimer::getOverflow(TimerFormat_t format)
* HERTZ_FORMAT: overflow is the frequency in hertz for overflow
* @retval None
*/
void HardwareTimer::setOverflow(uint32_t overflow, TimerFormat_t format)
void HardwareTimer::setOverflow(uint64_t overflow, TimerFormat_t format)
{
uint32_t ARR_RegisterValue;
uint32_t PeriodTicks;
uint64_t PeriodTicks;
uint32_t Prescalerfactor;
uint32_t period_cyc;
// Remark: Hardware register correspond to period count-1. Example ARR register value 9 means period of 10 timer cycle
Expand Down