AnsweredAssumed Answered

LPC4088 PWM Frequency

Question asked by Federico Fiorini on Jun 11, 2019
Latest reply on Jun 11, 2019 by soledad

Hello all,
I'm currently working on a project that requires PWM to work at very high frequencies in order to switch the signal given to a relay, allowing to save some power (the hardware implementation is left intentionally vague, as it's not relevant to the question).

 

I've been tasked to find a way to increase the current PWM frequency, which we measured to be at 100Hz (at least that's the value provided by the oscilloscope when probing), to be in the order of kHz at the very least. 

 

For what's my understanding, the PWM's "frequency" is defined by the number placed in register LPC_PWM1->MR0 (is this clock ticks? Or something else?), with the prescaler used to further reduce the frequency of the updates to the TC register. 
Am I correct, or is there something I'm missing out? 

 

During testing, it turned out that there's no way to increase the frequency to more than 100Hz. 

 

This is the portion of code we use as PWM driver, which is entirely based on the LPCOpen functionalities: 

void set_dutycycle(LPC_PWM_T * reg, uint32_t value, uint8_t channel)

{

   Chip_PWM_SetMatch(reg, channel, value);

   Chip_PWM_LatchEnable(reg, channel, PWM_OUT_ENABLED);

}

 

void init_PWM_Pin(PCON pcon, LPC_PWM_T * reg, uint8_t channel, uint16_t frequency)

{

   LPC_SYSCTL->PCONP |= pcon;

   Chip_PWM_Init(reg);

   Chip_PWM_SetCountClockSrc(reg, PWM_CAPSRC_RISING_PCLK, 0);

   Chip_PWM_PrescaleSet(reg, ((Chip_Clock_GetPeripheralClockRate() / 1000) / frequency));

 

   Chip_PWM_ResetOnMatchEnable(reg, 0);

 

   Chip_PWM_SetMatch(reg, 0, 100);

   Chip_PWM_SetMatch(reg, channel, 0);

   Chip_PWM_LatchEnable(reg, 0, PWM_OUT_ENABLED);

   Chip_PWM_LatchEnable(reg, channel, PWM_OUT_ENABLED);

   Chip_PWM_SetControlMode(reg, channel, PWM_SINGLE_EDGE_CONTROL_MODE, PWM_OUT_ENABLED);

   Chip_PWM_Enable(reg);

}

As far as I've tried (based on what I know about the PWM driver of the LPC4088 OEM board), I've changed the Chip_PWM_SetMatch for MR0 as well as changing the prescale value, but both seem not to be giving the desired result. 

My question is: is there a way to increase such PWM frequency (10-100kHz would be optimal) and, if so, how?

Thanks in advance for the answers.

P.S: source code is not entirely available at the moment, but I can provide it to you if really needed. 

P.P.S: I've tried to look for examples on the Internet, but it seems PWM has been removed / never been included in the LPCOpen / EA Dev Kit examples. Any suggestions? 

Outcomes