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

Thread: Teensy 3.6 - Potentiometer set up..

  1. #1

    Teensy 3.6 - Potentiometer set up..

    Hey folks,

    I just got my Teensy 3.6, and to get myself familiar with it, I've been testing some demo Arduino code and seeing how it compares.

    I've set up a simple circuit to read a potentiometer and output the value to the serial monitor. I've tried connecting the middle pin on the Pot to the pin 14 or (I believe Analog 0)... and doing an analogRead(0). But I get nothing but seemingly random values.. adjusting the pot has no effect.

    It then occurred to me that on the Arduino, I normally connect the POT to 5v power out of the Arduino. Of course, I cant get 5v out of the Teensy, only 3.3v. Could this be why the Teensy is not reporting the POT values? If I were to run 5v to the Pot externally, would I be risking sending 5v to the analog pin on the Teensy? The Guide says to not run anything higher than 3.3v to any Teensy 3.6 pin.

    Whats the workaround on this? The tutorials on the PJRC site seem geared to earlier Teensies...

    Sorry if its a newbie question, just getting started on Arduino, and Teensy is newer still...

    Thanks

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,386
    Don't hook 5v/Vin to any of your T3.6 pins! try this simple sketch
    Code:
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      Serial.println(analogRead(A0));
      delay(1000);
    }
    With nothing attached to A0 you should get random numbers. Carefully jumper A0 to GND on the T3.6. The sketch should show 0 or 1ish for values. Even more carefully, jumper A0 to 3v3 (careful, stay away from Vin/5v). Sketch should show 1023.

    so if you still can't get pot to give non-random values (pot hooked to 3v3 and GND, center pin to A0), then maybe attach a photo of your setup. Also check the voltage on center pin with voltmeter.

  3. #3
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461
    First, following the forum rule, you should post your code. Most probably, analogRead(A0) will work, but it’s a guess.
    Forget about Arduino and outdated 5V technology. 3.3V is the advanced hobbyist technology while the professional world is already migrating their stuff to 1.8V.
    Thus, the hot end of the potentiometer has to go to 3.3V, the cold end to AGND, and the wiper to the analog input pin of the Teensy. These ADCs inside Kinetis MCUs are more sophisticated and more sensitive than the ones inside Arduino AVR hardware (16/13 instead of 10 bits), but the do the conversion in SAR mode, and thus, the potentiometer impedance matters, especially if it is bigger than 10kOhm. In that case, the application note recommends an additional capacitor between the analog pin and AGND to get more stable and precise readings.

  4. #4
    Thanks, that did it! As Theremingenieur suggested, I should have posted my code - turns out I wasnt addressing the pin properly.. Though now for some reason, the values from the Pot arent going from 0-1023, but from ~10 to ~1011. Thought it might be a faulty pot, tried two others and got the same thing..

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461
    Your readings show an error of 1% at the bottom end and 2% at the top end. This sounds like a sub-optimal wiring of the hot and cold ends of the potentiometer (too high wire resistance). Or an impedance problem of the potentiometer itself. But without a picture of your setting and without knowing the overall resistance of your potentiometers, everything is only pure guesswork...

    Did you check the wiper voltage to AGND with a digital multimeter while doing the reads above? Which readings do you get if you jumper the analog pin (without potentiometer connected) to AGND or to +3.3V as manitou suggested?

  6. #6
    Thanks Theremingenieur... about 90% of the last bit of your post went completely over my head, but I'll post code in future I think the additional capacitor might be a good idea.. I'll try that. I'm using 10k pots. What is SAR mode?

  7. #7
    Click image for larger version. 

Name:	IMG_4172.JPG 
Views:	32 
Size:	250.2 KB 
ID:	12405

    Here's the project so far. I have a stepper connected through a TMC2100 board. For now, just want to be able to control the stepper with the Pot.

  8. #8
    Using Manitou's suggestions.. I'm getting 1's with A0 grounded to analog ground, and 1022 when connecting A0 to the 3.3v on the Teensy. Values are solid with no jitter.

    Reconnecting the Pot.. this time grounding to the Teensy's analog ground, I get values ranging from 2-999

    Code:
    void setup() {
      // put your setup code here, to run once:
    
    #define knob 14
    
    Serial.begin(9600);
    Serial.println("Knob input");
    }
    
    int val;
    
    void loop() {
      // put your main code here, to run repeatedly:
    int val = analogRead(knob);
    //val = map(val,25,1011,1000,10000);
    Serial.print("Knob Value:");
    Serial.println(val);
    delay(2);
    
    }
    There's also a fair bit of jitter noise in the values coming of the pot.
    Last edited by vfxwolf; 12-28-2017 at 01:16 AM.

  9. #9
    Quote Originally Posted by Theremingenieur View Post
    the application note recommends an additional capacitor between the analog pin and AGND to get more stable and precise readings.
    I'm working with a starter kit and asuch only have a small assortment of capacitors - which capacitor would be best for what you suggest?

    I'm still stocking up my electronics workshop and would be open to suggestions as to where source assorted diodes, capacitors, resistors etc. in a variety of shapes and sizes.
    Last edited by vfxwolf; 12-28-2017 at 01:22 AM.

  10. #10
    Member
    Join Date
    Jan 2017
    Location
    Maastricht
    Posts
    84
    I suggest you try the ResponsiveAnalogRead library, it works really great for smoothing the values.

    Kind regards,

    Gerrit

  11. #11
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461
    Seen that there is a stepper motor consuming high current peaks in proximity which tends to induce voltage spikes, it is very bad practice to have this long "wild" wiring (acts as antennas for noise) for the potentiometer. A shielded cable and a 10nF capacitor from the analog pin to AGND (as mentioned in the Kinetis K application note) will already give much better results.

  12. #12
    Quote Originally Posted by Theremingenieur View Post
    Seen that there is a stepper motor consuming high current peaks in proximity which tends to induce voltage spikes, it is very bad practice to have this long "wild" wiring (acts as antennas for noise) for the potentiometer. A shielded cable and a 10nF capacitor from the analog pin to AGND (as mentioned in the Kinetis K application note) will already give much better results.
    Agree. My intention at this point is work out the code and determine the best input devices. In the final project, the motors (4 of them) will be connected to the teensy control box via 5 conductor shielded cable, on a camera platform some 3 to 15 feet away from the box. I've been trying to find the application note you mention - is this it? https://www.nxp.com/docs/en/application-note/AN4745.pdf

  13. #13
    Quote Originally Posted by Gerrit View Post
    I suggest you try the ResponsiveAnalogRead library, it works really great for smoothing the values.

    Kind regards,

    Gerrit
    Brilliant, Gerrit.. Thank you! Will give that a try today...

  14. #14
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461

  15. #15
    Quote Originally Posted by Theremingenieur View Post
    and a 10nF capacitor from the analog pin to AGND (as mentioned in the Kinetis K application note) will already give much better results.
    Is this how the capacitor should be added, Theremingenieur?

    Click image for larger version. 

Name:	cappot.jpeg 
Views:	10 
Size:	223.0 KB 
ID:	12439

  16. #16
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461
    By the way: To get around this kind of problems, I decided to switch over to these cheap Alps rotary encoder knobs, after I wrote an extremely quick and memory saving template class to read, debounce, and to decode these beasts.

  17. #17
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461
    Yes, the wiring is correct. But on the picture, there is an electrolytic capacitor. These have a bad impulse response and too much capacitance for that purpose (you wonít want to wait 2 minutes for new potentiometer values to settle)... only 10nF are recommended by NXP. These are normally polyester or ceramic capacitors labelled with ď103Ē

  18. #18
    Quote Originally Posted by Theremingenieur View Post
    Yes, the wiring is correct. But on the picture, there is an electrolytic capacitor. These have a bad impulse response and too much capacitance for that purpose (you won’t want to wait 2 minutes for new potentiometer values to settle)... only 10nF are recommended by NXP. These are normally polyester or ceramic capacitors labelled with “103”
    Ahh.. well, my kit only provides 22pF and 104pF ceramic capacitors.. would either of these work?

  19. #19
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461
    Omg, thatís not a huge choice, insufficient equipment for a circuit designer... try rather the 104. You canít break anything with that. In the worst case, it just wonít have the desired effect.

  20. #20
    Quote Originally Posted by Theremingenieur View Post
    Omg, that’s not a huge choice, insufficient equipment for a circuit designer...
    That's why I'm a filmmaker, dabbling in electronics

    I did find these on Digikey - is this what you're recommending? https://www.digikey.com/products/en/...=0&pageSize=25

  21. #21
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461
    Iíd not recommend SMD parts for breadboarding but the classic variant with wires like, for example, this one: https://www.amazon.com/Value-2100-Ce.../dp/B019G8GJ24

  22. #22
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,461
    Quote Originally Posted by vfxwolf View Post
    That's why I'm a filmmaker, dabbling in electronics
    And Iím basically a (pure theory oriented) mathematician... so, no excuses!

  23. #23
    Quote Originally Posted by Gerrit View Post
    I suggest you try the ResponsiveAnalogRead library, it works really great for smoothing the values.

    Kind regards,

    Gerrit
    That library is just what the Doctor ordered, Gerrit.. thanks again. Works fantastically well! Prompted me to look at what other libraries Damien Clarke may have done and found another invaluable one.. AnalogMultiButton.. perfect!

Posting Permissions

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