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):
INIT:
1. Set up GPIO to output FTM and set up all FTM settings:
1a. Set CNTIN, POL, MOD, CnSC[ELSB, MSA], OUTINIT, CnV, SC[TOIE, PS(0), CLKS(1)], OUTMASK
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!
-Andrew
Hi Andrew,
After reviewing the Vybrid reference manual, I dont think the FTM hardware module is capable of achieving what you are looking for. Freescale FTM designers might have better say on this.
From a software perspective, my suggestion would be: Configure FTM to generate a pulse with a short low time (.5us) and a long high time (say >'x' ms). You would then need to enable the interrupt on low to high transition (timer channel interrupt can be used). In the ISR configure the OUTMASK to disable FTM output (similar to what you are currently doing). Doing so gives the kernel a better chance at servicing the ISR before the next low pulse occurs. The FAN5341 chip only decrements the brightness on a low pulse and does not have any restriction on duration of the high pulse.
The downside to this approach is calculating the worst case kernel ISR latency to obtain 'x'. Also if 'x' is a large number, it might not meet your needs if you are trying to frequently change the LED brightness.
Thanks,
Timesys Support
Thank you for the reply.
I do like this alternative approach if there is no other option. I will test it to make sure that it can still change the brightness fast enough without noticing a flicker. All we care about is whether or not there is a noticeable flicker when transitioning between two brightness settings. If there is any update from FTM designers about the hardware function I am looking for, please reply or direct them to this thread.
timesyssupport can you attend this case?