Author Topic: Reading analog signal on PIC Micro  (Read 6683 times)

0 Members and 1 Guest are viewing this topic.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Reading analog signal on PIC Micro
« on: August 22, 2007, 03:48:29 PM »
What is the assembly language code for reading an analog signal on a PIC microcontroller? I have a PIC 16F627 and I need it to read the analog signal from a Maxsonar EZ1(connected to port a.0) and then react by lighting an LED connected to port A.1 whenever the value becomes too low.

Please help, I was searching online for hours already..  :(

,Eric
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline snow

  • Full Member
  • ***
  • Posts: 73
  • Helpful? 0

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: Reading analog signal on PIC Micro
« Reply #2 on: August 23, 2007, 05:20:05 AM »
OK thank you.
and what is the code for reading the analog signal? (in assembly language please)
Thank you so much,
Eric
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline JonHylands

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 562
  • Helpful? 3
  • Robot Builder/ Software Developer
Re: Reading analog signal on PIC Micro
« Reply #3 on: August 23, 2007, 06:28:01 AM »
The face that it has no A/D channels indicates that you can't read analog signals with it. The hardware to support that just isn't available on that specific model.

- Jon

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: Reading analog signal on PIC Micro
« Reply #4 on: August 23, 2007, 02:54:10 PM »
I have selected the PIC16F685. Now how can I use that chip to read an analog signal? I know how to read digital signals but not analog.
please help me. :P
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Reading analog signal on PIC Micro
« Reply #5 on: August 23, 2007, 07:19:30 PM »
There are lots of examples to use the a/d using c rather than assembly, maybe you could compile one of the c examples into assembly using picclite and then find out that way.

Offline snow

  • Full Member
  • ***
  • Posts: 73
  • Helpful? 0
Re: Reading analog signal on PIC Micro
« Reply #6 on: August 24, 2007, 05:26:53 AM »
Read datasheet?

It has topic 9.2.6 A/D CONVERSION PROCEDURE and example in assembly.
« Last Edit: August 24, 2007, 05:28:41 AM by snow »

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Reading analog signal on PIC Micro
« Reply #7 on: August 24, 2007, 05:34:42 AM »
here is an example i just found for the 16f877a usin a/d ports

http://www.piclist.com/techref/microchip/16f877adsamp.htm

Offline Robotboy86

  • Robot Overlord
  • ****
  • Posts: 139
  • Helpful? 0
Re: Reading analog signal on PIC Micro
« Reply #8 on: August 25, 2007, 05:50:56 PM »
You can also buy an external A/D IC.

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Reading analog signal on PIC Micro
« Reply #9 on: September 30, 2007, 04:49:23 PM »
for 8 bit a/d pics you need to:

set the a/d ports to inputs i.e.                TRISA = 0b11111111
configure the a/d converter ie                 ADCON1 = 0b10000000
Select which port to read from ie             ADCON0 = 0b00000001
mask the interrupt                                 ADIE = 0
reset the interrupt flag                           ADIF = 0
reset the read adress value ie                  ADRES = 0
start the conversion ie                            ADGO = 1

wait for the conversion to happen
once the conversion is finished the ADIF bit should read as 1 so you can implement some code to wait until ADIF goes high.

once ADIF = 1 the 8 bit result will be waiting in ADRES (either a binary or hex value i.e. Result1 = ADRESH : Result1 = 0b00111011 )

for 10 bit results , the low bits are stored in ADRESL and the 2 high bits in ADRESH

THE ABOVE SAMPLES PORT A0 ONLY

Offline yesus

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Reading analog signal on PIC Micro
« Reply #10 on: February 21, 2009, 04:48:49 PM »
would it be possible to convert analog signals to digital siganls BEFORE connecting the device to the input of the PIC?
just like here:http://users.tpg.com.au/users/talking/a_to_d.html

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Reading analog signal on PIC Micro
« Reply #11 on: February 21, 2009, 08:19:26 PM »
The tutorial link that you provided was to turn an analog signal into a boolean signal or i/o signal. This is completely against the principal of an a/d port. of course you can convert a signal like in that tutorial but you can only record 2 states either state 1 or state 0. an a/d port woulkd allow you to convert the voltage into a number. 5v would produce the number 255 and 0 volts would produce the number 0 where any voltage in between would produce a linear example. so 1.25v would produce a reading of 63 in software.

If you wanted to boost a very low voltage signal in order to register than you should look into using a boosting transistor.

So the example you provided is easy to do with a microcontroller you can just connect that up to a normal digital port but you limit you reading to just reading 1 for a high sweep and 0 for a low sweep. If however you amplify your signal correctly you can get a linear number reading from an analog to digital port

Offline yesus

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Reading analog signal on PIC Micro
« Reply #12 on: February 22, 2009, 04:30:07 AM »
i'm totally new to this but could u use that converter to create simple action as:
if there is high signal on the input THEN do some action(like when light in the room darkens,turn the other lights on)
i'm asking that because that's something i'm working on myself

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Reading analog signal on PIC Micro
« Reply #13 on: February 22, 2009, 10:00:16 AM »
yes but you dont even need a converter. just connect the high/low signal to an i/o pin and read it.

Offline yesus

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Reading analog signal on PIC Micro
« Reply #14 on: February 22, 2009, 02:09:30 PM »
ok,but when input isn't really high,like say 0.5-1V ie.when you use photoresistor and you want to use that change in light intensity(which is followed but change in resistance and voltage drop) as an input and trigger some action through it ,can you connect the output from that photoresistor to IC input port directly and read from it??

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Reading analog signal on PIC Micro
« Reply #15 on: February 22, 2009, 02:18:11 PM »
Sort of, you will need a voltage divider circuit. which is basically 2 resistors. If you look at the $50 robot tutorial on this site. It uses 2 photoresistors to read light intensities. You can see a step by step guide how to do it. The only difference is that tutorial doesnt use a PIC but the principles are the same

 


Get Your Ad Here

data_list