2024-12-10 08:09 PM
Hello,
I have the NUCLEO-G474RE kit and am trying out basic exercises such as toggling GPIO pins, setting up timers and generating PWM gating pulses. I got GPIOs and timers working. I got basic complementary PWM working on Channel A with the HRTIM. But once I insert a deadtime, the pulses stop.
Here is my code
// Setting PA8 and PA9 as HRTIM1_CHA1 and HTIM1_CHA2
RCC->AHB2ENR = RCC->AHB2ENR | (uint32_t) 0x1U;
GPIOA->MODER = GPIOA->MODER & (uint32_t) 0xfffaffffU;
GPIOA->OSPEEDR = GPIOA->OSPEEDR | (uint32_t) 0xf0000U;
GPIOA->AFR[1] = (uint32_t) 0xddU;
// Enabling timer for HRTIM1
RCC->APB2ENR = 0x04000000U;
// Continuous mode and CPC=101/170MHz/5.88ns
HRTIM1->sMasterRegs.MCR = (uint32_t) 0xdU;
// Period for 5kHz
HRTIM1->sMasterRegs.MPER = 34000U;
HRTIM1->sTimerxRegs[0].TIMxCR = (uint32_t) 0xdU;
HRTIM1->sTimerxRegs[0].PERxR = 34000U;
HRTIM1->sTimerxRegs[0].CMP1xR = 27000U;
HRTIM1->sTimerxRegs[0].SETx1R = (uint32_t) 0x4U;
HRTIM1->sTimerxRegs[0].RSTx1R = (uint32_t) 0x8U;
// HRTIM1->sTimerxRegs[0].SETx2R = (uint32_t) 0x8U;
// HRTIM1->sTimerxRegs[0].RSTx2R = (uint32_t) 0x4U;
HRTIM1->sCommonRegs.OENR = (uint32_t) 0x3U;
HRTIM1->sTimerxRegs[0].OUTxR = (uint32_t) 100U;
HRTIM1->sTimerxRegs[0].DTxR = (uint32_t) 0xff0cffU;
HRTIM1->sMasterRegs.MCR = HRTIM1->sMasterRegs.MCR | 0x00030000U;
I have set the DTPRSC to be 011 such that tDTG will the same as tHRTIM. I am trying to generate a 5kHz PWM with sawtooth carrier. I have commented out the SETx2R and RSTx2R statements. Without deadtime and with these SETx2R and RSTx2R statements, I get perfect PWM waveforms. But with deadtime, I get nothing.
I have tried moving the OUTxR and DTxR statements around in case the sequence matters. But nothing works.
The reference manual merely states that DTEN has to be set in OUTxR and then DTxR can be used to configure the rising and falling edge delays. Am I missing any other setting?
Thanks in advance.
2024-12-11 01:26 PM
I realized I made a very silly mistake when I was rewriting the code. On line 33 of the above code block:
HRTIM1->sTimerxRegs[0].OUTxR = (uint32_t) 100U;
This statement is wrong and should be:
HRTIM1->sTimerxRegs[0].OUTxR = (uint32_t) 0x100U;
I missed the 0x when writing a hex number. Works perfectly now.
2024-12-11 02:57 PM
Thanks for coming back to report what fixed the issue.