Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: FTM timer problems

  1. #1

    FTM timer problems

    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:

    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);
      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.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Try using 558 for FTM1_MOD.

    Or use this:

    void setup() {
      analogWriteFrequency(3, 85828);
      analogWrite(3, 128);
    void loop() {

  3. #3
    Thank you Paul!

    Yes, with FTM1_MOD=558 the frequency is correct. I figured why the frequency didn’t match. I made a stupid mistake – I used 43Mhz instead of 48Mhz, for F_BUS.
    Also the duty cycle wasn’t 50% due to some other components (transistor, resistors). When I put the probe on the output pin everything match perfectly.

    I tried analogwrite and it works very nice, but I have some problems using it.
    Last edited by so999; 09-27-2018 at 01:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts