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

Thread: Teensy 4.1 XBAR between PWM and QuadTimer

  1. #1
    Junior Member
    Join Date
    Sep 2020
    Posts
    8

    Teensy 4.1 XBAR between PWM and QuadTimer

    Hello,

    I am generating PWM using analogWrite and would like to count the number of ticks using Quad Timer Capture.
    So far, I cascaded TMR1 and TMR2 channels to extend it to 32bits. Using PIT and an interval of 1s, the system evaluates the counts and raises a flag to put it on serial in the main loop.
    The code was tested by wiring the output of the analogwrite (pin 8) to the input of the quadtimer (pin9) using a jumper. Everything is working fine so far.

    Next, I would like to use XBAR to replace the jumper wire between pin 8 and pin9 and instead connect PWM output to the input to the Quad Timer in software, using XBAR.
    I guess this should be possible, but I don't know how to set it up.
    Any advice?


    Here is the code I have so far:

    Code:
    // this code counts ticks from external pin with  QTIMER4 chnl 2  pin 9 GPIO_B0_11
    // test with PWM on pin 8  jumper to 9
    
    #define PRREG(x) Serial.print(#x" 0x"); Serial.println(x,HEX)
    IMXRT_TMR_t * TMRx = (IMXRT_TMR_t *)&IMXRT_TMR4;
    
    uint32_t prev1,prev2;
    
    IntervalTimer it1;
    volatile uint32_t ticks12, dataReady;
    int i=0;
    
    // This is the interrupt handlign routine,called by PIT on a// regular interval.it calculates the counter value (here TMR1 and TMR2 are cascaded to 32 bit value)
    // and raises the flag to be read in the main loop
    
    void it1cb() { 
      ticks12=TMRx->CH[1].CNTR | TMRx->CH[2].CNTR<<16; //cascaded 1 and 2 for 32bit coutners!
      dataReady = 1;
    }
    
    
    void setup() {
    
      int cnt;
      Serial.begin(9600); //sets up the serial communication
      while (!Serial);
      delay(1000);
    
      //turn on the PWM ping using 5khz frequency
      analogWriteFrequency(8, 5000);  // test jumper 8 to 9, max 75mhz
      analogWrite(8, 128); //set the PWM to 50%
    
      //timer configuration
      CCM_CCGR6 |= CCM_CCGR6_QTIMER4(CCM_CCGR_ON); //enable QTMR4
      IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_11 = 1;    // QT4 Timer2 on pin 9
    
      cnt = 65536 ; // full cycle
      TMRx->CH[1].CTRL = 0; // stop
      TMRx->CH[1].CNTR = 0; // set count to 0
      TMRx->CH[1].LOAD = 0;  // start val after compare
      TMRx->CH[1].COMP1 = cnt - 1;  // count up to this val and start again
      TMRx->CH[1].CMPLD1 = cnt - 1;
      TMRx->CH[1].SCTRL = 0 ;  // enable oflow interrupt 
    
      TMRx->CH[2].CTRL = 0; // stop
      TMRx->CH[2].CNTR = 0; // set count to 0
      TMRx->CH[2].LOAD = 0;  // start val after compare
      TMRx->CH[2].COMP1 = cnt - 1;  // count up to this val and start again
      TMRx->CH[2].CMPLD1 = cnt - 1;
      TMRx->CH[2].SCTRL = 0 ;  // enable oflow interrupt 
    
    
      // control
      TMRx->CH[1].CTRL |= TMR_CTRL_CM(1); // count mode: count rising edges of primary source
      TMRx->CH[1].CTRL |= TMR_CTRL_PCS(2); // primary count source counter 2 input pin 
      
      TMRx->CH[2].CTRL  = TMR_CTRL_CM(7); // Count Mode: Cascaded counter mode
      TMRx->CH[2].CTRL |= TMR_CTRL_PCS(5); //Primary Count Source: CH[1] output  
      
    
      it1.begin(it1cb, 1000000);  // 1s interval
    }
    
    void loop() {
      if (dataReady) {
        i = i + 1;
        Serial.print("ticks: ");
        Serial.println(ticks12);
        dataReady = 0;
    
        //just for fun, turn the counting direction every 30s.
        if (i > 30){
           i = 0;
           Serial.println("Changed counting direction");
           TMRx->CH[1].CTRL ^= TMR_CTRL_DIR; // change the direction of the counting
           TMRx->CH[2].CTRL ^= TMR_CTRL_DIR; // change the direction of the 
          }
      }
    }
    Last edited by jakap; 01-05-2021 at 06:12 PM.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,458
    Sorry, I am not sure exactly what you are looking to do with XBAR? And avoid the hardware?

    Note: analogWrite on pin 8 is actually another timer: FLEXPWM1_PWMA03

    Again sorry, I am not understanding.

  3. #3
    Junior Member
    Join Date
    Sep 2020
    Posts
    8
    Sorry if I was not clear. I went back and edited my original post.
    The question is, is it possible to connect the FLEXPWM1-PWMA03 (pin8) to Qtimer4 Ch.1 Input pin (pin 9) using XBAR, and if, how to do so?
    Any help would be much appreciated.

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,458
    Whenever I am playing with XBAR,

    I look into the Teensy 4 sources at pwm.c
    And I either copy the function or extern the function:

    That in my sketch or .cpp files something like:

    Code:
    extern "C" {
        extern  void xbar_connect(unsigned int input, unsigned int output);
    }
    As for what is valid In and OUT you can look in the pdf file or I look in the imxrt.h file:
    Code:
    / XBAR1 Inputs and Outputs Table 3-4 Starting Page 62
    #define XBARA1_IN_LOGIC_LOW 0
    #define XBARA1_IN_LOGIC_HIGH 1
    #define XBARA1_IN_IOMUX_XBAR_IN02 2
    #define XBARA1_IN_IOMUX_XBAR_IN03 3
    #define XBARA1_IN_IOMUX_XBAR_INOUT04 4
    #define XBARA1_IN_IOMUX_XBAR_INOUT05 5
    #define XBARA1_IN_IOMUX_XBAR_INOUT06 6
    #define XBARA1_IN_IOMUX_XBAR_INOUT07 7
    #define XBARA1_IN_IOMUX_XBAR_INOUT08 8
    #define XBARA1_IN_IOMUX_XBAR_INOUT09 9
    #define XBARA1_IN_IOMUX_XBAR_INOUT10 10
    #define XBARA1_IN_IOMUX_XBAR_INOUT11 11
    #define XBARA1_IN_IOMUX_XBAR_INOUT12 12
    #define XBARA1_IN_IOMUX_XBAR_INOUT13 13
    #define XBARA1_IN_IOMUX_XBAR_INOUT14 14
    #define XBARA1_IN_IOMUX_XBAR_INOUT15 15
    #define XBARA1_IN_IOMUX_XBAR_INOUT16 16
    #define XBARA1_IN_IOMUX_XBAR_INOUT17 17
    #define XBARA1_IN_IOMUX_XBAR_INOUT18 18
    #define XBARA1_IN_IOMUX_XBAR_INOUT19 19
    #define XBARA1_IN_IOMUX_XBAR_IN20 20
    #define XBARA1_IN_IOMUX_XBAR_IN21 21
    #define XBARA1_IN_IOMUX_XBAR_IN22 22
    #define XBARA1_IN_IOMUX_XBAR_IN23 23
    #define XBARA1_IN_IOMUX_XBAR_IN24 24
    #define XBARA1_IN_IOMUX_XBAR_IN25 25
    #define XBARA1_IN_ACMP1_OUT 26
    #define XBARA1_IN_ACMP2_OUT 27
    #define XBARA1_IN_ACMP3_OUT 28
    #define XBARA1_IN_ACMP4_OUT 29
    //#define XBARA1_IN_Reserved 30
    //#define XBARA1_IN_Reserved 31
    #define XBARA1_IN_QTIMER3_TIMER0 32
    #define XBARA1_IN_QTIMER3_TIMER1 33
    #define XBARA1_IN_QTIMER3_TIMER2 34
    #define XBARA1_IN_QTIMER3_TIMER3 35
    #define XBARA1_IN_QTIMER4_TIMER0 36
    #define XBARA1_IN_QTIMER4_TIMER1 37
    #define XBARA1_IN_QTIMER4_TIMER2 38
    #define XBARA1_IN_QTIMER4_TIMER3 39
    #define XBARA1_IN_FLEXPWM1_PWM1_OUT_TRIG0 40
    #define XBARA1_IN_FLEXPWM1_PWM1_OUT_TRIG1 40
    #define XBARA1_IN_FLEXPWM1_PWM2_OUT_TRIG0 41
    #define XBARA1_IN_FLEXPWM1_PWM2_OUT_TRIG1 41
    #define XBARA1_IN_FLEXPWM1_PWM3_OUT_TRIG0 42
    #define XBARA1_IN_FLEXPWM1_PWM3_OUT_TRIG1 42
    #define XBARA1_IN_FLEXPWM1_PWM4_OUT_TRIG0 43
    #define XBARA1_IN_FLEXPWM1_PWM4_OUT_TRIG1 43
    #define XBARA1_IN_FLEXPWM2_PWM1_OUT_TRIG0 44
    #define XBARA1_IN_FLEXPWM2_PWM1_OUT_TRIG1 44
    #define XBARA1_IN_FLEXPWM2_PWM2_OUT_TRIG0 45
    #define XBARA1_IN_FLEXPWM2_PWM2_OUT_TRIG1 45
    #define XBARA1_IN_FLEXPWM2_PWM3_OUT_TRIG0 46
    #define XBARA1_IN_FLEXPWM2_PWM3_OUT_TRIG1 46
    #define XBARA1_IN_FLEXPWM2_PWM4_OUT_TRIG0 47
    #define XBARA1_IN_FLEXPWM2_PWM4_OUT_TRIG1 47
    #define XBARA1_IN_FLEXPWM3_PWM1_OUT_TRIG0 48
    #define XBARA1_IN_FLEXPWM3_PWM1_OUT_TRIG1 48
    #define XBARA1_IN_FLEXPWM3_PWM2_OUT_TRIG0 49
    #define XBARA1_IN_FLEXPWM3_PWM2_OUT_TRIG1 49
    #define XBARA1_IN_FLEXPWM3_PWM3_OUT_TRIG0 50
    #define XBARA1_IN_FLEXPWM3_PWM3_OUT_TRIG1 50
    #define XBARA1_IN_FLEXPWM3_PWM4_OUT_TRIG0 51
    #define XBARA1_IN_FLEXPWM3_PWM4_OUT_TRIG1 51
    #define XBARA1_IN_FLEXPWM4_PWM1_OUT_TRIG0 52
    #define XBARA1_IN_FLEXPWM4_PWM1_OUT_TRIG1 52
    #define XBARA1_IN_FLEXPWM4_PWM2_OUT_TRIG0 53
    #define XBARA1_IN_FLEXPWM4_PWM2_OUT_TRIG1 53
    #define XBARA1_IN_FLEXPWM4_PWM3_OUT_TRIG0 54
    #define XBARA1_IN_FLEXPWM4_PWM3_OUT_TRIG1 54
    #define XBARA1_IN_FLEXPWM4_PWM4_OUT_TRIG0 55
    #define XBARA1_IN_FLEXPWM4_PWM4_OUT_TRIG1 55
    #define XBARA1_IN_PIT_TRIGGER0 56
    #define XBARA1_IN_PIT_TRIGGER1 57
    #define XBARA1_IN_PIT_TRIGGER2 58
    #define XBARA1_IN_PIT_TRIGGER3 59
    #define XBARA1_IN_ENC1_POS_MATCH 60
    #define XBARA1_IN_ENC2_POS_MATCH 61
    #define XBARA1_IN_ENC3_POS_MATCH 62
    #define XBARA1_IN_ENC4_POS_MATCH 63
    #define XBARA1_IN_DMA_DONE0 64
    #define XBARA1_IN_DMA_DONE1 65
    #define XBARA1_IN_DMA_DONE2 66
    #define XBARA1_IN_DMA_DONE3 67
    #define XBARA1_IN_DMA_DONE4 68
    #define XBARA1_IN_DMA_DONE5 69
    #define XBARA1_IN_DMA_DONE6 70
    #define XBARA1_IN_DMA_DONE7 71
    #define XBARA1_IN_AOI1_OUT0 72
    #define XBARA1_IN_AOI1_OUT1 73
    #define XBARA1_IN_AOI1_OUT2 74
    #define XBARA1_IN_AOI1_OUT3 75
    #define XBARA1_IN_AOI2_OUT0 76
    #define XBARA1_IN_AOI2_OUT1 77
    #define XBARA1_IN_AOI2_OUT2 78
    #define XBARA1_IN_AOI2_OUT3 79
    #define XBARA1_IN_ADC_ETC0_COCO0 80
    #define XBARA1_IN_ADC_ETC0_COCO1 81
    #define XBARA1_IN_ADC_ETC0_COCO2 82
    #define XBARA1_IN_ADC_ETC0_COCO3 83
    #define XBARA1_IN_ADC_ETC1_COCO0 84
    #define XBARA1_IN_ADC_ETC1_COCO1 85
    #define XBARA1_IN_ADC_ETC1_COCO2 86
    #define XBARA1_IN_ADC_ETC1_COCO3 87
    
    #define XBARA1_OUT_DMA_CH_MUX_REQ30 0
    #define XBARA1_OUT_DMA_CH_MUX_REQ31 1
    #define XBARA1_OUT_DMA_CH_MUX_REQ94 2
    #define XBARA1_OUT_DMA_CH_MUX_REQ95 3
    #define XBARA1_OUT_IOMUX_XBAR_INOUT04 4
    #define XBARA1_OUT_IOMUX_XBAR_INOUT05 5
    #define XBARA1_OUT_IOMUX_XBAR_INOUT06 6
    #define XBARA1_OUT_IOMUX_XBAR_INOUT07 7
    #define XBARA1_OUT_IOMUX_XBAR_INOUT08 8
    #define XBARA1_OUT_IOMUX_XBAR_INOUT09 9
    #define XBARA1_OUT_IOMUX_XBAR_INOUT10 10
    #define XBARA1_OUT_IOMUX_XBAR_INOUT11 11
    #define XBARA1_OUT_IOMUX_XBAR_INOUT12 12
    #define XBARA1_OUT_IOMUX_XBAR_INOUT13 13
    #define XBARA1_OUT_IOMUX_XBAR_INOUT14 14
    #define XBARA1_OUT_IOMUX_XBAR_INOUT15 15
    #define XBARA1_OUT_IOMUX_XBAR_INOUT16 16
    #define XBARA1_OUT_IOMUX_XBAR_INOUT17 17
    #define XBARA1_OUT_IOMUX_XBAR_INOUT18 18
    #define XBARA1_OUT_IOMUX_XBAR_INOUT19 19
    #define XBARA1_OUT_ACMP1_SAMPLE 20
    #define XBARA1_OUT_ACMP2_SAMPLE 21
    #define XBARA1_OUT_ACMP3_SAMPLE 22
    #define XBARA1_OUT_ACMP4_SAMPLE 23
    //#define XBARA1_OUT_Reserved 24
    //#define XBARA1_OUT_Reserved 25
    #define XBARA1_OUT_FLEXPWM1_PWM0_EXTA 26
    #define XBARA1_OUT_FLEXPWM1_PWM1_EXTA 27
    #define XBARA1_OUT_FLEXPWM1_PWM2_EXTA 28
    #define XBARA1_OUT_FLEXPWM1_PWM3_EXTA 29
    #define XBARA1_OUT_FLEXPWM1_PWM0_EXT_SYNC 30
    #define XBARA1_OUT_FLEXPWM1_PWM1_EXT_SYNC 31
    #define XBARA1_OUT_FLEXPWM1_PWM2_EXT_SYNC 32
    #define XBARA1_OUT_FLEXPWM1_PWM3_EXT_SYNC 33
    #define XBARA1_OUT_FLEXPWM1_EXT_CLK 34
    #define XBARA1_OUT_FLEXPWM1_FAULT0 35
    #define XBARA1_OUT_FLEXPWM1_FAULT1 36
    #define XBARA1_OUT_FLEXPWM1_FAULT2 37
    #define XBARA1_OUT_FLEXPWM2_FAULT2 37
    #define XBARA1_OUT_FLEXPWM3_FAULT2 37
    #define XBARA1_OUT_FLEXPWM4_FAULT2 37
    #define XBARA1_OUT_FLEXPWM1_FAULT3 38
    #define XBARA1_OUT_FLEXPWM2_FAULT3 38
    #define XBARA1_OUT_FLEXPWM3_FAULT3 38
    #define XBARA1_OUT_FLEXPWM4_FAULT3 38
    #define XBARA1_OUT_FLEXPWM1_EXT_FORCE 39
    #define XBARA1_OUT_FLEXPWM2_PWM0_EXTA 40
    #define XBARA1_OUT_FLEXPWM3_PWM0_EXTA 40
    #define XBARA1_OUT_FLEXPWM4_PWM0_EXTA 40
    #define XBARA1_OUT_FLEXPWM2_PWM1_EXTA 41
    #define XBARA1_OUT_FLEXPWM3_PWM1_EXTA 41
    #define XBARA1_OUT_FLEXPWM4_PWM1_EXTA 41
    #define XBARA1_OUT_FLEXPWM2_PWM2_EXTA 42
    #define XBARA1_OUT_FLEXPWM3_PWM2_EXTA 42
    #define XBARA1_OUT_FLEXPWM4_PWM2_EXTA 42
    #define XBARA1_OUT_FLEXPWM2_PWM3_EXTA 43
    #define XBARA1_OUT_FLEXPWM3_PWM3_EXTA 43
    #define XBARA1_OUT_FLEXPWM4_PWM3_EXTA 43
    #define XBARA1_OUT_FLEXPWM2_PWM0_EXT_SYNC 44
    #define XBARA1_OUT_FLEXPWM2_PWM1_EXT_SYNC 45
    #define XBARA1_OUT_FLEXPWM2_PWM2_EXT_SYNC 46
    #define XBARA1_OUT_FLEXPWM2_PWM3_EXT_SYNC 47
    #define XBARA1_OUT_FLEXPWM2_EXT_CLK 48
    #define XBARA1_OUT_FLEXPWM3_EXT_CLK 48
    #define XBARA1_OUT_FLEXPWM4_EXT_CLK 48
    #define XBARA1_OUT_FLEXPWM2_FAULT0 49
    #define XBARA1_OUT_FLEXPWM2_FAULT1 50
    #define XBARA1_OUT_FLEXPWM2_EXT_FORCE 51
    #define XBARA1_OUT_FLEXPWM3_EXT_SYNC0 52
    #define XBARA1_OUT_FLEXPWM3_EXT_SYNC1 53
    #define XBARA1_OUT_FLEXPWM3_EXT_SYNC2 54
    #define XBARA1_OUT_FLEXPWM3_EXT_SYNC3 55
    #define XBARA1_OUT_FLEXPWM3_FAULT0 56
    #define XBARA1_OUT_FLEXPWM3_FAULT1 57
    #define XBARA1_OUT_FLEXPWM3_EXT_FORCE 58
    #define XBARA1_OUT_FLEXPWM4_EXT_SYNC0 59
    #define XBARA1_OUT_FLEXPWM4_EXT_SYNC1 60
    #define XBARA1_OUT_FLEXPWM4_EXT_SYNC2 61
    #define XBARA1_OUT_FLEXPWM4_EXT_SYNC3 62
    #define XBARA1_OUT_FLEXPWM4_FAULT0 63
    #define XBARA1_OUT_FLEXPWM4_FAULT1 64
    #define XBARA1_OUT_FLEXPWM4_EXT_FORCE 65
    #define XBARA1_OUT_ENC1_PHASEA_INPUT 66
    #define XBARA1_OUT_ENC1_PHASEB_INPUT 67
    #define XBARA1_OUT_ENC1_INDEX 68
    #define XBARA1_OUT_ENC1_HOME 69
    #define XBARA1_OUT_ENC1_TRIGGER 70
    #define XBARA1_OUT_ENC2_PHASEA_INPUT 71
    #define XBARA1_OUT_ENC2_PHASEB_INPUT 72
    #define XBARA1_OUT_ENC2_INDEX 73
    #define XBARA1_OUT_ENC2_HOME 74
    #define XBARA1_OUT_ENC2_TRIGGER 75
    #define XBARA1_OUT_ENC3_PHASEA_INPUT 76
    #define XBARA1_OUT_ENC3_PHASEB_INPUT 77
    #define XBARA1_OUT_ENC3_INDEX 78
    #define XBARA1_OUT_ENC3_HOME 79
    #define XBARA1_OUT_ENC3_TRIGGER 80
    #define XBARA1_OUT_ENC4_PHASEA_INPUT 81
    #define XBARA1_OUT_ENC4_PHASEB_INPUT 82
    #define XBARA1_OUT_ENC4_INDEX 83
    #define XBARA1_OUT_ENC4_HOME 84
    #define XBARA1_OUT_ENC4_TRIGGER 85
    #define XBARA1_OUT_QTIMER1_TIMER0 86
    #define XBARA1_OUT_QTIMER1_TIMER1 87
    #define XBARA1_OUT_QTIMER1_TIMER2 88
    #define XBARA1_OUT_QTIMER1_TIMER3 89
    #define XBARA1_OUT_QTIMER2_TIMER0 90
    #define XBARA1_OUT_QTIMER2_TIMER1 91
    #define XBARA1_OUT_QTIMER2_TIMER2 92
    #define XBARA1_OUT_QTIMER2_TIMER3 93
    #define XBARA1_OUT_QTIMER3_TIMER0 94
    #define XBARA1_OUT_QTIMER3_TIMER1 95
    #define XBARA1_OUT_QTIMER3_TIMER2 96
    #define XBARA1_OUT_QTIMER3_TIMER3 97
    #define XBARA1_OUT_QTIMER4_TIMER0 98
    #define XBARA1_OUT_QTIMER4_TIMER1 99
    #define XBARA1_OUT_QTIMER4_TIMER2 100
    #define XBARA1_OUT_QTIMER4_TIMER3 101
    #define XBARA1_OUT_EWM_EWM_IN 102
    #define XBARA1_OUT_ADC_ETC_TRIG00 103
    #define XBARA1_OUT_ADC_ETC_TRIG01 104
    #define XBARA1_OUT_ADC_ETC_TRIG02 105
    #define XBARA1_OUT_ADC_ETC_TRIG03 106
    #define XBARA1_OUT_ADC_ETC_TRIG10 107
    #define XBARA1_OUT_ADC_ETC_TRIG11 108
    #define XBARA1_OUT_ADC_ETC_TRIG12 109
    #define XBARA1_OUT_ADC_ETC_TRIG13 110
    #define XBARA1_OUT_LPI2C1_TRG_INPUT 111
    #define XBARA1_OUT_LPI2C2_TRG_INPUT 112
    #define XBARA1_OUT_LPI2C3_TRG_INPUT 113
    #define XBARA1_OUT_LPI2C4_TRG_INPUT 114
    #define XBARA1_OUT_LPSPI1_TRG_INPUT 115
    #define XBARA1_OUT_LPSPI2_TRG_INPUT 116
    #define XBARA1_OUT_LPSPI3_TRG_INPUT 117
    #define XBARA1_OUT_LPSPI4_TRG_INPUT 118
    #define XBARA1_OUT_LPUART1_TRG_INPUT 119
    #define XBARA1_OUT_LPUART2_TRG_INPUT 120
    #define XBARA1_OUT_LPUART3_TRG_INPUT 121
    #define XBARA1_OUT_LPUART4_TRG_INPUT 122
    #define XBARA1_OUT_LPUART5_TRG_INPUT 123
    #define XBARA1_OUT_LPUART6_TRG_INPUT 124
    #define XBARA1_OUT_LPUART7_TRG_INPUT 125
    #define XBARA1_OUT_LPUART8_TRG_INPUT 126
    #define XBARA1_OUT_FLEXIO1_TRIGGER_IN0 127
    #define XBARA1_OUT_FLEXIO1_TRIGGER_IN1 128
    #define XBARA1_OUT_FLEXIO2_TRIGGER_IN0 129
    #define XBARA1_OUT_FLEXIO2_TRIGGER_IN1 130
    Again not sure if the input one of: XBARA1_IN_FLEXPWM1_PWM3_OUT_TRIG1
    Is the correct one? for your usage or not...
    likewise: XBARA1_OUT_QTIMER4_TIMER1
    For your timer pin...
    But if so you plug those into the function mentioned.

  5. #5
    Junior Member
    Join Date
    Sep 2020
    Posts
    8
    Thank you KurtE, I think that is the right way to go.
    I copied the function you suggested, and called it in the last line of the setup function:

    Code:
    xbar_connect(XBARA1_IN_FLEXPWM1_PWM3_OUT_TRIG1, XBARA1_OUT_QTIMER4_TIMER1);
    From my understanding, the registers you suggested should be correct, but unfortunately it does not work. I also tried several other register combinations, no success.

    I did not find any specific registers to tell xbar to wire pwm digital output to input capture pin of TMR4ch1. Is this handled somehow automatically by xbar?


    Any other ideas what to try?

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,458
    Again often times you have to also look at the sub-system that you wish to use the FlexIO with and potentially setup some register settings.

    Example at one point I added support to the T4.x to give the option to use an XBAR IO pin with the menu system for either an RX pin or a CTS pin.

    In this case we are using the IO pins in XBAR mode, so needed to setup the mapping as mentioned. But also needed to use the INPUT_SELECT pin for the pin to direct the signal to it,
    And in the Serial code you had to set the PINCFG register with a value to say to use it... You can look at HardwareSerial.cpp

    In the case with the ADC library, a few of us setup code to use a Quad timer to generate the timing for doing ADC conversions, when the user says they wish to do a ADC operation at some frequency.
    Again there are several things to setup. In this case the Quad Timer using XBAR needs to go to the ADC_ETC subsystem, which needs to be setup to use ADC...
    You can find more of these details in the ADC library file ADC_Module.cpp

    Often times you can find a lot of good information in some of the examples that @manitou has done: https://github.com/manitou48/teensy4

    But in this case some of it is clear as mud to me... Like lots of the manual.
    That is you are telling the system to rout the PWM3_OUT... to QTIMER4_TIMER1 Now I am not sure if this is specific to a specific TIMER1 or is this
    Or is this to setup the logical COUNTER 1 INPUT pin..
    If that is the case You may then need to look at the TMRx_CTRLn register at the Primary Count Source, and set it to Counter 1 input pin (1)...

    But again that is a guess... would probably need to experiment and see if that helps.
    When I start debugging things like this, after I setup everything, I would have debug code print out the settings of all of the different registers...

  7. #7
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,615
    here is example of "slow PWM" for Teensy4 using XBAR https://github.com/manitou48/teensy4...r/qtmrxpwm.ino
    discussed in https://forum.pjrc.com/threads/25164...l=1#post247337

    i don't think there is an XBAR IN-mapping of flexpwm output. XBARA1_IN_FLEXPWM1_PWM3_OUT_TRIG1 is for triggering ADC.
    Last edited by manitou; 01-06-2021 at 12:46 PM.

  8. #8
    Junior Member
    Join Date
    Sep 2020
    Posts
    8
    Thank you for your assistance.
    Studying Manitous code, I figured out I forgot to turn on the XBARA clock:
    Code:
    CCM_CCGR2 |= CCM_CCGR2_XBAR1(CCM_CCGR_ON);
    I also changed the Input pin of the counter to 1 as suggested by KurtE, but no success so far. I guess the XBAR is not intended for what I want, as pointed out by Manitou.
    So I guess I will have to stick to the jumper-wire solution for now.
    Thank you all for help!

Posting Permissions

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