Confusion with hardware level PWM using FTM

Status
Not open for further replies.

charlesrwest

New member
Hello,

I'm working on a project to build a weather balloon that communicates using APRS. As part of this, I am trying to implement a discrete sine approximation function to help generate tones for AFSK. I've gotten PWM modulation working using FTM timers, but I am getting some behavior that seems rather odd (and was hoping someone might know what was going on).

As I understand it, with the FTM modules, the timer starts at CNTIN and the channel goes high. Once the timer reaches the value FTM1_C0V (assuming FTM1_C0V < FTM1_MOD), it sets the channel low. The channel stays low until the timer reaches FTM1_MOD, then CNTIN is loaded again and the cycle repeats.

By that logic, if you set CNTIN at 0, FTM_MOD at 255, the voltage of the apparent output should increase linearly from 0.0 v to 3.3 v as FTM1_C0V goes from 0 to 255. As FTM1_C0V goes past 255, it should just stay at 3.3 v (pin never goes low). Also, the PWM frequency should be about every 255 timer clock cycles.

When I tested this, the LED output did increase linearly with FTM1_C0V but kept increasing past 255. I do not have an O-Scope, so I do not know what frequency it is operating at. My multimeter doesn't seem to like measuring a PWM output, so LED brightness is about all I have to go on.

There is also this confusing line from the manual: The EPWM period is determined by (MOD − CNTIN + 0x0001) and the pulse width (duty cycle) is determined by (CnV − CNTIN).

It makes sense if CnV < MOD, but otherwise would seem to indicate that the chip behavior is rather different from my understanding of it (by my understanding, duty cycle should be (MOD -(CnV-CNTIN))).

If I may ask, does anyone know where I am going wrong here?

Thanks,
Charlie West

src:
Code:
#include "wiring.h"


void timer_setup() {

//Counter start of cycle value
//FTM1_CNT = 0;
FTM1_CNTIN=0;//Defaults to zero, but to make sure...

//Sets the limit of how high the counter will go before overflowing
FTM1_MOD = 255;

//Indicate how the timer is to be used.  This configuration sets it to edge aligned PWM with high-true pulses (clears on value match)
FTM1_C0SC = 0x28; 

FTM1_SC = (1<<3); //Set timer clock to be the system clock without a prescaler

//Set external pin 3 to PWM.  Voltage gets higher the closer this value gets to that of FTM1_MOD
FTM1_C0V = 254*8;

CORE_PIN3_CONFIG = PORT_PCR_MUX(3) | PORT_PCR_DSE | PORT_PCR_SRE;
}
 

extern "C" int main(void)
{
pinMode(3, OUTPUT);
timer_setup();


while(1)
{

}

}
 
Status
Not open for further replies.
Back
Top