No output from hrtim module on portenta lite

I am using a portenta lite from arduino with portenta breakout.
I am already using TIM3_CHA1 for encoder input and
TIM8_ch1 on PJ8 for other pwm output.
So I need to use hrtim for this pwm signal.

I want to setup high resolution timer to output a square wave at
20 mhz with 50% duty cycle.

using oscilloscope on pwm1 (pc6) I don't get any output.

I have attached the code that I wrote to initialize the high resolution timer.

chat gpt can't find anything wrong with the code.

testhrtim.ino (2.6 KB)

if I change line 52
from
if (HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_MASTER, &pTimeBaseCfg) != HAL_OK)
to
if (HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &pTimeBaseCfg) != HAL_OK)

it works

I also had to add new lines after line 66 since preload register is enabled by default, in which case you cannot update the pulse width.

  // pwms don't update unless you disable the preload register
  hhrtim.Instance->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].TIMxCR &= ~HRTIM_TIMCR_PREEN;

I also wrote a routine to set the hrtim pulse width on the fly.

void setHrtimWidth(long index, long width)
// index is HRTIM_TIMERINDEX_TIMER_A, .. HRTIM_TIMERINDEX_TIMER_E
// width is pulse width
{
hhrtim.Instance->sTimerxRegs[index].CMP1xR = width > 2 ? width : 3;
}

here is completed code
testhrtim.ino (3.1 KB)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.