Page 1 of 1

PWM signals on MOD54415

Posted: Mon Apr 15, 2013 7:34 am
by fd9750
Hi,

For my application I need to generate three signals by means of the PWM outputs. One +/- 4 MHz clock signal, one +/- 8 MHz clock signal and a start pulse.
I have looked carefully at the NCF54418 reference manual and it seems relatively straightforward to get that done.
I have come up with the code below to do so but I must be missing something because I am not getting any sort of signal at all.
The code is definitely being executed because I do get to see both Development board LED's lighting up.
Any suggestions as to what I am doing wrong or overlooking ?

Code: Select all

void InitPWMs (void)
{
LED1 = LED_ON;
sim1.gpio.par_sdhcl = 0x02;		// set pin function to PWM for A0
sim1.gpio.par_sdhch = 0x88;		// set pin functions to PWM for A1,A2
// configure PWM A0 to generate a 7.8125 Mhz clock signal (50% duty cycle)
sim1.mcpwm.sm[0].cr1 = 0x0404;
sim1.mcpwm.sm[0].cr2 = 0x2000;
sim1.mcpwm.sm[0].init = 0;			// start counter value (reload)
sim1.mcpwm.sm[0].val[1] = 16;		// end counter value Clock = 125 MHz, divide by 16 => 7.8125 MHz
sim1.mcpwm.sm[0].val[2] = 0;		// PWM A ON counter value
sim1.mcpwm.sm[0].val[3] = 8;		// PWM A OFF counter value
sim1.mcpwm.sm[0].ocr = 0;
sim1.mcpwm.sm[0].dismap=0xFFF0;
// configure PWM A1 to generate a 3.90625 Mhz clock signal (50% duty cycle)
sim1.mcpwm.sm[1].cr1 = 0x0404;
sim1.mcpwm.sm[1].cr2 = 0x2000;
sim1.mcpwm.sm[1].init = 0;			// start counter value (reload)
sim1.mcpwm.sm[1].val[1] = 32;    // end counter value Clock = 125 MHz, divide by 32 => 3.90625 MHz
sim1.mcpwm.sm[1].val[2] = 0;     // PWM A ON counter value
sim1.mcpwm.sm[1].val[3] = 16;    // PWM A OFF counter value
sim1.mcpwm.sm[1].ocr = 0;
sim1.mcpwm.sm[1].dismap=0xFFF0;
// configure PWM A2 to generate a start pulse signal (base clock = 7,8125 MHz)
sim1.mcpwm.sm[2].cr1 = 0x0404;
sim1.mcpwm.sm[2].cr2 = 0x2000;
sim1.mcpwm.sm[2].init = 0;			// start counter value (reload)
sim1.mcpwm.sm[2].val[1] = 20000; // end counter value = 1250 periods of 7.8125 MHz
sim1.mcpwm.sm[2].val[2] = 1;     // PWM A ON counter value
sim1.mcpwm.sm[2].val[3] = 2;     // PWM A OFF counter value
sim1.mcpwm.sm[2].ocr = 0;
sim1.mcpwm.sm[2].dismap=0xFFF0;
sim1.mcpwm.outen = 0x0700;			// enable PWM outputs A0,A1,A2
sim1.mcpwm.mcr = 0x0007;			// set LDOK for PWM outputs A0, A1, A2
sim1.mcpwm.mcr = 0x0700;			// start PWM clocks (RUN flags)
LED2 = LED_ON;
}

Re: PWM signals on MOD54415

Posted: Tue Apr 16, 2013 2:36 am
by fd9750
Hi,

I have cracked it. As I assumed the code was correct except for a few details:

1) before writing to sim1.mcpwm.mcr you must first read it.
2) then write to sim1.mcpwm.mcr, setting all of the appropriate LDOK flags.
3) then write to sim1.mcpwm.mcr, setting the appropriate PWM module run flags and leaving the LDOK flags at 0.

As usual: once you know it is simple but it can take a while before you know.

All for now

Re: PWM signals on MOD54415

Posted: Wed Apr 17, 2013 9:18 am
by nicobari
Hi,
I have a question. Doesn't MOD54415 runs at 250 Mhz?

Re: PWM signals on MOD54415

Posted: Wed Apr 17, 2013 9:26 am
by dciliske
It does. The 125MHz is (I'm assuming) because the peripheral clock is f_sys/2. Most of the peripheral clocks are this way.

Re: PWM signals on MOD54415

Posted: Thu May 30, 2013 7:28 pm
by nicobari
I figured that to change PWM value we need to update the VAL registers and then set LDOK again. I am updating at each PWM instant. For my application I need a very rapid change in PWM to control brushless motor speed, is there any other way to speed up PWM values update?

Re: PWM signals on MOD54415

Posted: Fri May 31, 2013 8:29 am
by dciliske
How rapid is rapid? If the change is in the MHz region, you probably want to see about using DMA to read/write blocks directly to the registers.