Teensy 3.6 - Potentiometer set up..

Status
Not open for further replies.

vfxwolf

Well-known member
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
 
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.
 
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.
 
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..
 
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?
 
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?
 
IMG_4172.JPG

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.
 
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:
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:
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.
 
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
 
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.
 
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”
 
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?
 
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.
 
Status
Not open for further replies.
Back
Top