AnsweredAssumed Answered

FTM automatically disable after "n" pulses

Question asked by Andrew Alexander on Mar 31, 2014
Latest reply on Apr 9, 2014 by Andrew Alexander

Hello, I have been working for some time now on the FTM to control an LED display driver (FAN5341 by Fairchild). The basic premise is that to control LED brightness, the driver needs to receive up to 32 rising edges on a single pin. I have implemented the FTM to do this, but the only implementation I have gotten to work involves servicing an interrupt. Here is an outline of what I have done to accomplish this (On a TWR-VF65GS10 running the VF6xxx processor):



1. Set up GPIO to output FTM and set up all FTM settings:


2. Do an init routine to ensure that the LEDs are at the maximum brightness setting by disabling outmask, setting SWOCTRL, bringing pin low for 5ms, then back high, resetting OUTMASK to 1, then clearing SWOCTRL register.

     2a. NOTE: the driver starts at maximum brightness after a power cycle, and once a level has been set, the input needs to remain high

3. Disable clock (so that no more interrupts are generated)

4. Enable interrupt (had to do this last so the initialization routine in 2 did not trigger the interrupt)


set_brightness function:

1. Calculate number of pulses needed to get to desired brightness level

     1a. This number gets inserted into the CONF[CONF_NUMTOF] register so that the TOF interrupt is generated after n pulses

2. Enable clock

3. Disable OUTMASK so pulses are seen by driver


interrupt handler:

1. enable OUTMASK

2. Clear interrupt

3. Disable Clocks again


This has worked quite well when doing bare-metal testing, and I have gotten the FTM to provide the exact functionality I am looking for (theoretically). However, when implemented with an OS, the processor may have to service many interrupts, and I am nervous about having to set the OUTMASK and disable the clock using an interrupt alone. I have looked in many places to try to find a way for the output to be masked automatically, but haven't had too much success.


The ultimate goal would be to just call the set_brightness function with "num_pulses = n" as an input, have the FTM generate those n pulses, then return high WITHOUT the need for an interrupt to be serviced in software. The easiest way I could imagine this to be implemented is to have the TOF interrupt set the OUTMASK bit, but I have not found a way to implement this without using a software ISR.


If there is any other way to automatically generate n pulses unattended, please let me know. I have looked into resources about stepper motors, imagining that there would be some insight there, but all that I was able to find involved feedback that I do not have (Quadrature encoder mode, for instance). I also tried the output compare mode, but this also just left me in the same place because while I had more fine control of the pulse width, they still would not terminate without an interrupt routine. This LED driver expects the software to keep track of the brightness levels, and with the way things have been configured, I do not have access to any feedback from the driver about what the current brightness level is.


Thanks in advance for any help that can be provided!