samerafach
Member
I found this nice document: https://cache.nxp.com/docs/en/application-note/AN5142.pdf
which shows many example codes for different FTM configurations. However, I'm not succeeding in getting any of them to work on my Teensy 3.6.
For example, on page 5, there's an example on how to make an edge-aligned signal. I expect to copy that code to my sketch, assign FTM0 pins with the following:
PORTC_PCR1 |= 0x400;
PORTC_PCR2 |= 0x400;
PORTC_PCR3 |= 0x400;
which I got for the reference manual (K66) saying that FTM0_CH0,1,2 connected to PTC1,2,3 at ALT4; and after this, to get signals coming out of pins 22/23/9. But, none of this is happening. The pins don't show any signal. Why? What else am I missing?
The following is my code (copied from the pdf + pins assignment):
Thanks in advance!
which shows many example codes for different FTM configurations. However, I'm not succeeding in getting any of them to work on my Teensy 3.6.
For example, on page 5, there's an example on how to make an edge-aligned signal. I expect to copy that code to my sketch, assign FTM0 pins with the following:
PORTC_PCR1 |= 0x400;
PORTC_PCR2 |= 0x400;
PORTC_PCR3 |= 0x400;
which I got for the reference manual (K66) saying that FTM0_CH0,1,2 connected to PTC1,2,3 at ALT4; and after this, to get signals coming out of pins 22/23/9. But, none of this is happening. The pins don't show any signal. Why? What else am I missing?
The following is my code (copied from the pdf + pins assignment):
Code:
#include "Arduino.h"
void PWMOutput_EdgeAlignment(void) {
SIM_SCGC6 |= 0x03000000; // enable FTM0 and FTM0 module clock
FTM0_CONF = 0xC0; // set up BDM in 11
FTM0_FMS = 0x00; // clear the WPEN so that WPDIS is set in FTM0_MODE register
FTM0_MODE |= 0x05; // enable write the FTM CnV register
FTM0_MOD = 1000;
FTM0_C0SC = 0x28; // edge-alignment, PWM initial state is High, becomes low
// //after match
FTM0_C1SC = 0x28;
FTM0_COMBINE = 0x02; // complementary mode for CH0&CH1 of FTM0
FTM0_COMBINE |= 0x10; // dead timer insertion enabled in complementary mode
// for //CH0&CH1 of FTM0
FTM0_C1V = 500;
FTM0_C0V = 500;
FTM0_C2SC = 0x28;
FTM0_C3SC = 0x28;
FTM0_COMBINE |= 0x0200;
FTM0_COMBINE |= 0x1000;
FTM0_DEADTIME = 0x00;
FTM0_C3V = 250;
FTM0_C2V = 250;
FTM0_CNTIN = 0x00;
FTM0_SC = 0x08; // PWM edge_alignment, system clock driving, dividing by 1
PORTC_PCR1 |= 0x400;
PORTC_PCR2 |= 0x400;
PORTC_PCR3 |= 0x400;
}
void setup() { PWMOutput_EdgeAlignment(); }
void loop() {}
Thanks in advance!