Please help with FlexPWM & QuadTimer

Status
Not open for further replies.

AVSTech

Member
Hi everyone! :)

I'm trying to port code from Teensy 3.x to Teensy 4.0
I need help with the following lines of code that are for Teensy 3.x. They need to be refined so that they work on Teensy 4.0

Code:
//BLANK_PIN -> pin 18 (A4) -> QuadTimer3 Module1
//XLAT_PIN -> pin 19 (A5) -> QuadTimer3 Module0
//GSCLK_PIN -> pin 5 -> FlexPWM2 Module1


//XLAT_PIN -> pin 19 (A5) -> QuadTimer3 Module0
#define set_XLAT_interrupt()    FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_CPWMS | FTM_SC_TOIE | (FTM1_SC & FTM_SC_PS(7))
#define clear_XLAT_interrupt()  FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_CPWMS | (FTM1_SC & FTM_SC_PS(7))
#define enable_XLAT_pulses()    CORE_PIN3_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE
#define disable_XLAT_pulses()   CORE_PIN3_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_DSE|PORT_PCR_SRE


//GSCLK_PIN -> pin 5 -> FlexPWM2 Module1
      SIM_SCGC4 |= SIM_SCGC4_CMT;
      CMT_MSC = 0;
      CMT_PPS = 0;
      CMT_CGH1 = TLC_TIMER_TEENSY3_NORMAL_CGH1;
      CMT_CGL1 = TLC_TIMER_TEENSY3_NORMAL_CGL1;
      CMT_CMD1 = 1;
      CMT_CMD2 = 0;
      CMT_CMD3 = 0;
      CMT_CMD4 = 0;
      CMT_OC = 0x60;
      CMT_MSC = 0x01;
      CORE_PIN5_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_DSE|PORT_PCR_SRE;

//BLANK_PIN -> pin 18 (A4) -> QuadTimer3 Module1
      FTM1_SC = 0;
      FTM1_MOD = TLC_TIMER_TEENSY3_NORMAL_MOD;
      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;
      FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_CPWMS;
      NVIC_ENABLE_IRQ(IRQ_FTM1);
      CORE_PIN4_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE;

I need this to run the TLC5940 chips
If I can I can fine-tune the standard library I tried to optimize these lines by looking at the code of the TimerOne TimerThree library and the code from manitou48 (https://github.com/manitou48/teensy4). But my attempts to understand in vain, firstly I don't understand which line is responsible for what, and secondly because there is no manual on how to configure timers on Teensy 4.0

Please, help :eek:
 
The chip datasheets have the details of the timers and their registers for each variant - alas its complex and they can be different and the documents are thousands of pages... There are links to each processor's datasheet from the relevant Teensy product pages under the headings "Technical information"

Normally TLC5940's and other such shift registers would be driven from SPI, not PWM, so the code you have may already be nonportable and pulling low-level tricks for some reason (high bandwidth?).
 
The chip datasheets have the details of the timers and their registers for each variant - alas its complex and they can be different and the documents are thousands of pages... There are links to each processor's datasheet from the relevant Teensy product pages under the headings "Technical information"

Normally TLC5940's and other such shift registers would be driven from SPI, not PWM, so the code you have may already be nonportable and pulling low-level tricks for some reason (high bandwidth?).

Hi MarkT!

Indeed, the chip is controlled by the SPI bus - it transmits data about which LED to turn on, what its brightness, etc. (in my case the chip controls the backlight) However, the chip to generate the switching of the LEDs to ground must receive the reference signal (GSCLK - 4096 clock cycles), and some control signals (XLAT/BLANK) with a certain interval = GSCLK - 4096 clock cycles, BLANK - lasting about 3 clock cycles and XLAT - lasting about 1 clock cycle located within the interval BLANK.
I made a working sketch for Teensy 4.0

https://forum.pjrc.com/threads/6909...pt-for-TLC5940?p=296530&viewfull=1#post296530

But the problem is that my library is a tool based on standard functions and is used in a loop (); and if any operation, for example turning the encoder and then drawing the display menu, longer than 4096 clock cycles generated in the loop (); my LEDs go off, until the loop goes back to the method Tlc.begin(); of my library from the link above. I need the signal to be generated continuously and configured in setup (); as it is done in the original library for Teensy 3.x But unfortunately the last 4 months of helping me with this library and configuring timers did not lead to results. I hope there are people in the community who understand timers for Teensy 4.0 and help me with 20 lines of code to port the standard TLC5940 library to Teensy 4.x, as I see them on the forum.
 
Last edited:
Status
Not open for further replies.
Back
Top