TLC5940 PWM Frequency does not alter on Teensy 3.2

Status
Not open for further replies.
Library: https://github.com/PaulStoffregen/Tlc5940 (comes with Teensyduino installation)

I connected a TLC5940NT from TI to a Teensy 3.2. While the LEDs light up, I observed that the PWM frequency is 977 Hz as expected by default. I tried changing the PWM frequency by modifying the TLC_config.h file, using the following guide as reference: https://www.oxgadgets.com/2011/10/u...able-frequency-pwm-signals-using-arduino.html.

As per the guide, to obtain 244 Hz PWM, I changed TLC_PWM_PERIOD to 32768 and TLC_GSCLK_PERIOD to 3. However, when observed with an oscilloscope, the PWM frequency is still 977 Hz.

I then set both the constants to 0, and still the PWM frequency was 977 Hz.

Does the library for teensy use the two constants from the config file at all? The math also does not add up, given Teensy 3.2 can run at 96 MHz and not 16 MHz.
 
I don't have an answer to your question, but I'm curious how you like using the TLC5940. I thought about using it, but then I found the TLC5947 which seemed to be a better fit for me. I built a custom PCB based on that, but during testing found that the TLC5947 (and I think the TLC5940 also) don't have the ability to do smooth fades. So I re-designed the board around the PCA9685, which is working out really well so far. Did you find a way around the limitations, or are fades not important in your application?

Edit: Here's a link to my Reddit post on this topic.
 
Last edited:
Does the library for teensy use the two constants from the config file at all? The math also does not add up, given Teensy 3.2 can run at 96 MHz and not 16 MHz.

Those constants are for the AVR timers. For the Teensy timers you'll need to mess with pinouts/Teensy_KinetisK20.h
 
This library is using the FTM1 timer. For documentation on FTM1 on Teensy 3.2, you need the MK20DX256 manual. Get it here:

https://www.pjrc.com/teensy/datasheets.html

The 2 registers which matter are FTM1_SC and FTM1_MOD, which are documented on pages 780 and 782.

Inside the library, you'll find this code which actually programs the timer:

Code:
    FTM1_SC = 0;
    [B]FTM1_MOD = TLC_TIMER_TEENSY3_NORMAL_MOD;[/B]
    FTM1_CNT = 0;
    FTM1_C0SC = 0x24;
    FTM1_C1SC = 0x24;
    FTM1_C0V = TLC_TIMER_TEENSY3_NORMAL_MOD - TLC_TIMER_TEENSY3_NORMAL_CV;
    FTM1_C1V = TLC_TIMER_TEENSY3_NORMAL_MOD - TLC_TIMER_TEENSY3_NORMAL_CV - 1;
    [B]FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_CPWMS;[/B]
    NVIC_ENABLE_IRQ(IRQ_FTM1);
    CORE_PIN4_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE;

By writing a larger number to FTM1_MOD, the clock will run slower. But it is only 16 bits. The 3 bit "PS" field in FTM1_SC can scale the clock down by up to 128 times. Details on page 781.

So to get a slower clock, write to those 3 bits to get into the approximate speed range you want, and then tune FTM1_MOD to get the exact speed you need.
 
I am using the TLC5940 as a coarse PWM generator for DRV8601 LRA driver. Fades are not important. I just need to modify the duty cycle coarsely, which the TLC5940 can do.

@Paul thanks I will look into the code.
 
Status
Not open for further replies.
Back
Top