ftm

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ftm

2,127 Views
ogj
Contributor IV

I'm trying to generate a PWM signal using FTM0, chan 0 on the Vybrid VF6. I'm basing it on App Note AN5142, section 3.1. The issue is I don't get any output. Here is the setup I'm using:

   ftm = FTM0_BASE;
   ftm->CONF = 0xC0;   //set BDM to 11
   ftm->FMS = 0x00;    //clear WPEN (MOD_WPDIS will be set)
   ftm->MODE |= 0x05;
     
   ftm->SC = 0;
   ftm->MOD = 2000;
   ftm->CONTROLS[0].CnSC = 0x28;
   ftm->CONTROLS[0].CnV = 1000;
     
   // The output of FTM0, chan 0 is on PTB0.
   IOMUXC_RGPIO(22) = GPIO_OUT | IOMUX_DRIV_37 | IOMUX_ALT_FUNC_1;
    
   ftm->CNTIN = 0;
   ftm->SC = 0x0F;

I can see the counter counting (CNTIN changes), and appears to stay within the range 0 - 2000. The output on RPGIO(22) should change when CNTIN reaches 1000, but instead always stays low. One thing I noticed is that, even though I write 1000 to CONTROLS[0].CnV (C0V), it always shows 0x0 when looking at it with my debugger. I would assume it would read back 1000. Any ideas?

Labels (1)
0 Kudos
1 Reply

550 Views
ogj
Contributor IV

In looking around in the forum I found that Edward Karpicz (3/26/14) had the same issue. It takes multiple writes to the CnV register before the value actually gets written. The above code was running on the A5 processor; processor speed was 396 MHz. The clock going into FTM0 was 66 MHz, then divided by 128. I solved the problem by doing the following:

i = 20;

do

{

    ftm->CONTROLS[0].CnV = value;

    i--;

} while((ftm->CONTROLS[0].CnV != value) && (i > 0));

I haven't checked the value of i when the loop is exited, but CnV always has the new value.

0 Kudos