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

Thread: PWM: Teensy to Drive Analog Gauge

  1. #1
    Junior Member
    Join Date
    Aug 2022
    Posts
    10

    PWM: Teensy to Drive Analog Gauge

    Hey all,

    Looking to set up an analog gauge driven by a Teensy. The idea is the Teensy receives data from various devices over CANbus and then translates it to a PWM signal to drive a gauge.

    Anyone done this, or something similar using a PWM output on the Teensy?

  2. #2
    I've use Teensy to write a PWM signal to a transistor to vary fan speed. Have a look at analogWrite on a digital pin.

  3. #3
    Junior Member
    Join Date
    Aug 2022
    Posts
    10
    Ah, so using a transistor as an intermediary (not running a PWM fan directly off of the Teensy), gotcha. Are you aware of the current limits with the 4.0 on the PWM analogWrite pins? The draw of the stepper motors on most gauges seems to be 20mA or less, wondering if a transistor is necessary.

  4. #4
    I believe the current capability of a digital pin is around 20 ma. If you are just trying to drive a mechanical gage (like a car speedometer), I'm guessing the Teensy will work from a current perspective. What voltage do the gages need? Teensy will only output 0 to 3v3 so a transistor may be needed.

  5. #5
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    1,253
    Quote Originally Posted by KrisKasprzak View Post
    I believe the current capability of a digital pin is around 20 ma
    When we are talking about a Teensy 4.x, than, according to this page, "The recommended maximum output current is 4mA."

    Quote Originally Posted by veroelectric View Post
    The draw of the stepper motors on most gauges seems to be 20mA or less, wondering if a transistor is necessary.
    If the motor of the analog gauge is indeed a stepper motor, you won't be able to drive that with a PWM signal. Better to use the TeensyStep library (and probably some transistors).

    Paul

  6. #6
    Junior Member
    Join Date
    Aug 2022
    Posts
    10
    Hey Paul-

    Thanks for the suggestion -- definitely sounds like the way to go. The TeensyStep library is (per the GitHub readme, at least) not compatible with Teensy 4.0/4.1. I'd like to avoid building anything new around old hardware which is hard to source currently, so wondering if there's another option or if the library is compatible with the 4.0 but just not listed.

    Reider

  7. #7
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    1,389
    Code:
    // TEENSY 3.0 - Teensy 3.6 ==================================================================================
    
    #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
    #include "timer/teensy3/TimerField2.h"
    
    // TEENSY 4 ================================================================================================
    
    #elif defined(__IMXRT1052__)
    #include "timer/teensy4/TimerField.h"
    As you can see from this snippet from TeensyStep,h it is compatible with Teensy 4.0/4.1.
    This code was taken from the GitHub site.

    EDIT: Oops Wrong Again. See #8 below.
    Last edited by BriComp; 04-20-2023 at 12:52 PM.

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    2,106
    No, TeensyStep is not compatible with T4.x. Are you sure that your gauge has a stepper motor? Do you have a datasheet?

  9. #9
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    1,253
    Quote Originally Posted by luni View Post
    Are you sure that your gauge has a stepper motor?
    @veroelectric: this page may help you further.

    Paul

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    2,106
    Looks like those steppers have some unusual step pattern. Here a library to drive them: https://github.com/clearwater/SwitecX25. This lib is directly driving the motor (not step/dir). However, you probably need some simple driver to attach them to a T4. Here a datasheet: https://4tronix.co.uk/zeropoint/x27_spec.pdf

  11. #11
    Junior Member
    Join Date
    Aug 2022
    Posts
    10
    Bit of a change of plans: doing some testing on a gauge like this (https://www.amazon.com/Samdo-Marine-...81&sr=8-8&th=1) and it seems like resistive-type gauges are the most readily available so would like to go this route. These gauges have a +12v, GND, and a sensor connector that varies the gauge readout based on the resistance to ground. For this gauge (which accepts resistances between 0-190ohm between the sensor pin and ground), 0ohm is the 'full' gauge position and 190ohm is the 'empty gauge position.

    To drive this with the Teensy my understanding is that the PWM pins on the 4.0 can be used to switch a low side switching transistor, which can simulate various resistances in this range based on the PWM duty cycle putting the signal pin to ground.

    Any thoughts/feedback? Working on a schematic now, I'll send it on here to get feedback once it's a bit more complete

Posting Permissions

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