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

Thread: T4: are there particular pins that are preferred for accurate hw edge timing?

Hybrid View

  1. #1

    T4: are there particular pins that are preferred for accurate hw edge timing?

    I'm porting a 3.6 project that used capacitive touch input to t4; hardware-wise, I'm happy to switch to a 2 pin arrangement as used by the old Capacitive Touch library by paul, with a drive output pin thru big resistor and a sense input pin.

    however that code seems to use an interrupts-disabled busy loop to time how long it takes for the sense pin to transition. since I'm hoping to run a fairly heavy audio handler, im contemplating if i can use hardware to help do the timing instead of busy looping

    I noticed the teensy freqcounter library specifies a particular pin to use, but doesnt yet list anything for t4. I'm assuming it's using some timer peripheral to make the pin stop the count. would that be a good strategy on t4? does it need particular pins?

    alternatively, i guess i could set up an interrupt on edges of more or less any digital pin, tho i was worried about isr latency especially if the audio library leaves interrupts disabled for long ish periods... i have a hunch that's a non starter.

    any advice on which-t4-peripheral-can-help-very-accurate-pin-state-transitions-while-audio-lib-is-busy gratefully received. if, following advice, i manage to make something work id be more than happy to share the code here. thanks!

  2. #2
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    676
    I don't know the general answer to your question but I do know on Teensy 4 the FreqMeasure input is pin 22, hopefully the FreqMeasure page gets updated soon given that each Teensy model is different.

  3. #3
    thanks so much for the tip! I'll set up my design with the capacitive sense pin on 22, in the hope it's useful for the peripheral. browsing the forum a little, I find all the FlexPWM/FlexTimer/QTimer terms a little opaque (not sure what the differences are between them etc), and I can't find a helpful user guide (nxp site has a datasheet that seems very sparse on detail, and the userguide requires a login). do you know where I could find docs for the CPU, in the hope that I can figure out how to configure the hardware to measure high-time on a pin?

    otherwise I guess I'm at the mercy of lovely helpful people like you to poke me in the right direction. I noticed a T3 library called PulsePosition that might give me some pointers on hardware setup, perhaps....
    Thanks again!

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,273
    Quote Originally Posted by mmalex View Post
    thanks so much for the tip! I'll set up my design with the capacitive sense pin on 22, in the hope it's useful for the peripheral. browsing the forum a little, I find all the FlexPWM/FlexTimer/QTimer terms a little opaque (not sure what the differences are between them etc), and I can't find a helpful user guide (nxp site has a datasheet that seems very sparse on detail, and the userguide requires a login). do you know where I could find docs for the CPU, in the hope that I can figure out how to configure the hardware to measure high-time on a pin?

    otherwise I guess I'm at the mercy of lovely helpful people like you to poke me in the right direction. I noticed a T3 library called PulsePosition that might give me some pointers on hardware setup, perhaps....
    Thanks again!
    Paul has a copy of the IMXRT 1060 manual on the pjrc.com site, so you don't need a login:

  5. #5
    Quote Originally Posted by MichaelMeissner View Post
    Paul has a copy of the IMXRT 1060 manual on the pjrc.com site...
    ah that is so awesome, and doh I should have thought to look there. I looked on the Teensy4 page & shop page, but not on the datasheets page. doh.
    I also found this sketch buried in the beta thread https://github.com/manitou48/teensy4...qtmr_count.ino and indeed the Qtimer looks like it can be told to 'capture' on a pin event.

    I guess in terms of pin choice, it seems like that sketch uses pin 9, not pin 22. the magic incantation seems to be:
    Code:
    IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_11 = 1;    // QT4 Timer2 on pin 9
    with a comment that says:
    Code:
    // count ticks from external pin with  QTIMER4 chnl 2  pin 9 GPIO_B0_11
    so the last bit of the puzzle for me I think is to figure out how the person who wrote that sketch knew (s)he could use pin 9 with the QTimer 4? and why writing 1 to that config register causes it to be routed towards the QTimer 4.
    IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_11 appears in core_pins.h of the teensy4 github once, here:
    https://github.com/PaulStoffregen/co...re_pins.h#L569
    where it is used to define pin 9 config!
    Code:
    #define CORE_PIN9_CONFIG	IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_11
    anway so does that mean I can use the 'IOMux' to route almost any gpio pin to a qtimer?
    is there any list anywhere of which qtimers teensy4 needs to leave untouched - in other words, why does that sketch use qtimer 4, and not qtimer 1 2 or 3?

    sorry for all the questions! I guess the short version is - now you've pointed me at the datasheet (thankyou!) - now I just have to figure out which choices in teh various bits of timer code are arbitrary & have a free choice, vs which are constrained for some reason. (eg where did the pin 22 restriction come from, up-thread?)

Posting Permissions

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