Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Analog to Digital Convertion

Status
Not open for further replies.

demestav

Member
Hi. I have a 16f84a pic and i want read a value from a distance sensor. That sensor has analog voltage output which is proportional to the distance. which ADC ic should i use? is it too complex to use? thank you... If it is no trouble, can you give me some general outlines how this will work best?
Thank you
 
If you already have a circuit using a 16F84A then I would suggest you to get a serial ADC. If you can change the PIC, you should get the 16F877 for example, that has a internal ADC to lower your IC count. NOw that I remember the PIC16F628, has the same pin-to-pin location as the 16F84A but it has analog inputs, so that you don't have to change anything 8)

Now if you really want to go the ADC IC route then for your distance sensor you will be satisfied with a **broken link removed** It is a 8 bit serial ADC. You are going to need 3 I/O from your PIC, one will be a clock, which you send a pulse for each bit of data, the other one will be the Data pin, and last the CS pin.

From the data sheet:
A conversion is initiated by setting CS low, which enables all logic circuits. CS must be held low for the complete
conversion process. A clock input is then received from the processor. An interval of one clock period is
automatically inserted to allow the selected multiplexed channel to settle. DO comes out of the high-impedance
state and provides a leading low for one clock period of multiplexer settling time............... As the conversion proceeds,
conversion data is simultaneously output from DO, with the most significant bit (MSB) first. After eight clock
periods, the conversion is complete. When CS goes high, all internal registers are cleared. At this time, the
output circuits go to the high-impedance state. If another conversion is desired, CS must make a high-to-low
transition followed by address information.

But as I said before it would be better to have the PIC do the conversion, with its own ADC. If your distance sensor is a SHARP chances are that the voltage is NOT proporcional to the voltage. For what you will have to create a table of values. :? 8-Bits ADC will be more than enough, If you use 5V then 8-Bit ADC will give you 256 different values, being 5V a 255, 0V a 0 and 2.5V a 127 value. So you will have a value for every 0.019V change in the voltage at the sensor.

I hope it helps some,

Ivancho
 
Re

Thnx for the reply. I understand everything you wrote. The pulse that will be fed in the ADC should be generated by the uC? Like i should write a piece of code that will send pulses to the ADC and at the same time reading the values out of the ADC?
Thnx
 
Exactly...... you send a pulse to the ADC with the uC and as response you get a bit of data. You pulse the ADC 8 times and you get you data, and if I am not wrong you will have the Most Significat Bit (MSB) first.

You should do something like:

1. Pull CS line LOW
2. Pulse the Clock line
3. Data line is set to 0V
4. Pulse the Clock line
5. Data line is set to BitX where X goes from 8 to 1
6. Store BitX
7. Repeat step 4-6 until X =1
8. Pull CS line HIGH

Hope it helps

Ivancho
 
reading a resistance and sending it digitally to serial port

Hi, im a bit of a noob with this, just starting off, and i would like to know if this does also work for reading a resistor and sending it's resistance on a serial port digitally? Same PIC 16F84A
 
Re: reading a resistance and sending it digitally to serial

Diceman said:
Hi, im a bit of a noob with this, just starting off, and i would like to know if this does also work for reading a resistor and sending it's resistance on a serial port digitally? Same PIC 16F84A

For a start throw the 16F84 away and buy a modern device, a 16F819 or 16F88 uses the same 18 pin package but have internal 10 bit A2D.

To measure a resistor pass a current through it and measure the voltage dropped across it - a simple potential divider is often enough, depending what you are wanting to do.
 
variable resistance

i see...thanks, but can it be done with the 16F84A because thats what i have at my desposal. I just want to meaure a variable resistance and send it digitally through a serial port so that i can have a readable value on the serial port...thats it.
 
Re: variable resistance

Diceman said:
i see...thanks, but can it be done with the 16F84A because thats what i have at my desposal. I just want to meaure a variable resistance and send it digitally through a serial port so that i can have a readable value on the serial port...thats it.

You can use an external A2D, but that often is more expensive than buying a modern PIC!.

How accurate do you need to be?, and what EXACTLY are you trying to do? - you might have a look at my joystick tutorial which reads a resistor without an A2D.
 
re:

well im trying to measure this little suckers resistance

https://www.microchemical.com/coandnox.htm
https://www.microchemical.com/technology.htm

... and send it trough the serial port, so that i can read the values on a PC trought the serial port.

Its basicaly a variable resistance, trubble is, the sensors are not cheap, and i'll try with a simple variable 10K resistor for testing first.I have a PIC programmer that burns PIC16x8x 's and i already have the PIC16F84A and thats why i asked, i hope i can get a more modern version.
But i didn't knew if i can measure variable resistance with this kind of PIC or not.

Well... thats what i'd like to try out... :)
 
I might be mistaken, but the "analog" inputs on the PIC16F628 go to comparators, not A2D Converters. I know you can play with the reference and do a crude SAR algorithm but that is not really the same as having an A2D converter.

I aggree with Nigel, if you don't have access to a PIC in production what makes you think you'll have access to an A/D converter worth a dime? On the theory that people should learn to crawl before they try to run a marathon, I make the following prediction. You will get your application up and running faster by using a PIC with an onboard A/D converter then you will by bit banging any serial A/D you can find out there.

If you still want an A/D suggestion I have had very good results with the SPI products from Maxim including D2A Converters(MAX5222), Input Multiplexers(MAX7301), Display Controllers(MAX6954), and UARTS(MAX3100). They make good stuff, the datasheets are excellent, every part has worked first time with no PCB changes.
 
me again

i found something that i think might help me, maybe if i addapt the probe to be my resistor i could acomplish something what do you think? is it possible?

**broken link removed**

it uses a PIC12F675

i hope it does...:)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top