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:
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?
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.