CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ADC -127 +127

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

ADC -127 +127
PostPosted: Wed May 15, 2019 6:04 am     Reply with quote

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: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed May 15, 2019 7:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 15, 2019 7:58 am     Reply with quote

I'll use it for a joystick.
I will send the analog control position.
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Wed May 15, 2019 8:12 am     Reply with quote

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: 479
Location: Montenegro

View user's profile Send private message

PostPosted: Thu May 16, 2019 5:35 am     Reply with quote

In what voltage range is the output of your joystick? Does it actually output negative voltages?
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Thu May 16, 2019 7:48 am     Reply with quote

Most are actually just potentiometers, so will swing between what is given
'to' them as endpoint voltages.
PrinceNai



Joined: 31 Oct 2016
Posts: 479
Location: Montenegro

View user's profile Send private message

PostPosted: Thu May 16, 2019 11:34 am     Reply with quote

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: 19518

View user's profile Send private message

PostPosted: Thu May 16, 2019 11:48 am     Reply with quote

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: 479
Location: Montenegro

View user's profile Send private message

PostPosted: Thu May 16, 2019 12:04 pm     Reply with quote

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: 19518

View user's profile Send private message

PostPosted: Thu May 16, 2019 12:31 pm     Reply with quote

If it's a Tacx, I have the same. Reads about 10% right, until it is calibrated...
PrinceNai



Joined: 31 Oct 2016
Posts: 479
Location: Montenegro

View user's profile Send private message

PostPosted: Thu May 16, 2019 1:29 pm     Reply with quote

Tacx it is.
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Thu May 16, 2019 2:10 pm     Reply with quote

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. Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group