View previous topic :: View next topic |
Author |
Message |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
ADC -127 +127 |
Posted: Wed May 15, 2019 6:04 am |
|
|
What is the best fit for an ADC reading for -127 and 127?
ADC=8.
signed int8 i;
......
i = read_adc() - 127; // ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Wed May 15, 2019 7:18 am |
|
|
NONE !!!
All PIC internal ADC peripherals are NOT bipolar. They ONLY read from zero volts to VDD ( or Vref). Typically +5 for F PICS, 3.3 for LF PICs.
You need to post your PIC, though while all the 'common' ones don't read +-, there may be some 'fancy' PICs that do.
Now you can use an omp amp to offset the input from say +-2.5 to fed the PIC a 0-5 signal. Google 'signal conditioning op amp' or similar keywords.
Jay |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Wed May 15, 2019 7:58 am |
|
|
I'll use it for a joystick.
I will send the analog control position. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Wed May 15, 2019 8:12 am |
|
|
OK. What you will need to do, is add a bias to the Joystick output voltage
to bring it to half the Vref (whether you use the supply of an external Vref).
The ADC will then return 0 to 255, and give typically 128 or 128 when
the joystick is in the centre (because these are _never_ accurate, you may
well want to consider having a 'calibrate the zero' option, which asks the
user to let the joystick 'centre', and then records the value being read).
Then you subtract this 'centre' value from the value being read, to give
your +/- result. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Thu May 16, 2019 5:35 am |
|
|
In what voltage range is the output of your joystick? Does it actually output negative voltages? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Thu May 16, 2019 7:48 am |
|
|
Most are actually just potentiometers, so will swing between what is given
'to' them as endpoint voltages. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Thu May 16, 2019 11:34 am |
|
|
Yes, I know. That is why I asked what is it in this specific case. If it is from 0V to something, no level shifting is needed. It is just a matter of preference of the OP, how he wants to interpret values from AD. Treat all values above center as "a move to one side" and below as a "move to another side". Or subtract center value from the readings and deal with signed integers. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Thu May 16, 2019 11:48 am |
|
|
Totally agree.
However most don't actually give their mid value when at the midpoint,
so storing this point as the 'zero', will give better results. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Thu May 16, 2019 12:04 pm |
|
|
Yes, as a center value I meant whatever reading there is when the joystick is in the middle position (calibration value), be it 115 or 138. An extra button to store that value would be nice. I have a bike trainer where you can move the handlebars to actually turn on VR terrains. It has only one pot there, and the values when I calibrate it vary I think up to 20%. The cheapest pot in a unit that costs 600€ probably saved the company a fortune :-). |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Thu May 16, 2019 12:31 pm |
|
|
If it's a Tacx, I have the same. Reads about 10% right, until it is calibrated... |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Thu May 16, 2019 1:29 pm |
|
|
Tacx it is. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Thu May 16, 2019 2:10 pm |
|
|
The number of programming issues I have solved on that or my 'real' bike,
is remarkably high. When you are stuck, going and getting really hot
is a very powerful tool!..
Glad to hear another poster here does the same. |
|
|
|