Hello
I tested ftm1 in order to understand how it works. I didn’t know how to connect the pin to the timer channel so I simply copied the define macro from “pins_teensy.c” (but I don’t understand what those define lines do).
This is my simple sketch which is supposed to put ftm1 in edge aligned mode and to produce a pulse with a frequency of about 85828 kHz. I thought that putting C0V at half it will produce a 50% duty cycle:
I measured the output with an oscilloscope and the problem is that the output frequency is about 95.8kHz. Also the duty cycle is about 22%.
I need some help to understand why the frequency and duty cycle don’t match.
I tested ftm1 in order to understand how it works. I didn’t know how to connect the pin to the timer channel so I simply copied the define macro from “pins_teensy.c” (but I don’t understand what those define lines do).
This is my simple sketch which is supposed to put ftm1 in edge aligned mode and to produce a pulse with a frequency of about 85828 kHz. I thought that putting C0V at half it will produce a 50% duty cycle:
Code:
uint8_t pulsePin1 = 3;
#define FTM1_CH0_PIN 3
#define FTM_PINCFG(pin) FTM_PINCFG2(pin)
#define FTM_PINCFG2(pin) CORE_PIN ## pin ## _CONFIG
void setup() {
pinMode(pulsePin1, OUTPUT);
FTM_PINCFG(FTM1_CH0_PIN) = PORT_PCR_MUX(3) | PORT_PCR_DSE | PORT_PCR_SRE;
FTM1_COMBINE=0;
FTM1_SC=B1001000;
FTM1_C0SC=B101000;
FTM1_MOD = 500;
FTM1_C0V = 250;
}
void loop() {
}
I measured the output with an oscilloscope and the problem is that the output frequency is about 95.8kHz. Also the duty cycle is about 22%.
I need some help to understand why the frequency and duty cycle don’t match.