caramoan tour package

caramoan tour package

Author Topic: how to utilize Analog-to-Digital Converter Module of a Microcontroller ?  (Read 10176 times)

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
paano ba gamitin yung ADC module ng PicMicro (e.g pic16LF73/pic16F73) ?  ???
paano sya ia-activate / i-initialize ?  ???
saan dapat magsimula ang design/program ?  ???
ano ang mga design restrictions ?  ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum


Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
Ano programming language gagamitin mo? May na post ako dito na project using PIC16F877A.

Philippine Electronics Forum


Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger

Philippine Electronics Forum


Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Ano programming language gagamitin mo?..
CCS C ang gagamitin kong compiler..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum


Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum


Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
Ibig sabihin ata nyan ang sampling nya is 8 bit.

Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2585
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
This function will read the digital value from the analog to digital converter. Calls to setup_adc(), setup_adc_ports() and  set_adc_channel() should be made sometime before this function is called.   The range of the return value depends on number of bits in the chips A/D converter and the setting in the #DEVICE ADC= directive as follows:

#DEVICE
 8 bit
 10 bit
 11 bit
 12 bit
 16 bit
 
ADC=8
 00-FF
 00-FF
 00-FF
 00-FF
 00-FF
 
ADC=10
 x
 0-3FF
 x
 0-3FF
 x
 
ADC=11
 x
 x
 0-7FF
 x
 x
 
ADC=16
 0-FF00
 0-FFC0
 0-FFEO
 0-FFF0
 0-FFFF
 

Note:   x is not defined

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Ibig sabihin ata nyan ang sampling nya is 8 bit.
ahh.. parang resolution..  :D
ibig sabihin, pag ginawa kong:
Code: [Select]
#device adc=16tataas resolution ng ADC ko..  ;D
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
question:
sa CCS C, anong pinagkaiba ng code na:
Code: [Select]
value=read_adc();saka:
Code: [Select]
read_adc(ADC_START_ONLY);
delay_us(xx);
value=read_adc(ADC_READ_ONLY);
???
anong advantages saka disadvantages nila?  ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
question:
sa CCS C, anong pinagkaiba ng code na:
Code: [Select]
value=read_adc();saka:
Code: [Select]
read_adc(ADC_START_ONLY);
delay_us(xx);
value=read_adc(ADC_READ_ONLY);
???
anong advantages saka disadvantages nila?  ???

I am not sure of how the CCS library works.
But ADC needs a small delay for settling and hold time.
And conversion also takes a few cycles depending on ADCS setting.
The conversion is started by setting GO/~DONE to 1 then should wait for GO/~DONE bit to be cleared.
You should look at the resulting ASM or the library source.

Maybe code #1 incorporates all the steps.  Useful for beginners.

While on #2, it is broken down into each step of the conversion.  This way you can have full control of the A/D conversion by doing something while waiting for the ~DONE flag. Also the settling and hold time is not needed if you are not switching from one A/D input to another. So skipping this and the delay only on initialization, then using #2 makes the conversion faster.
The Cebuano Geek

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
regarding sa hardware:
magkakaproblema kaya ako kapag ganito circuit ko:  ???

input(tru coax) --- 2Mohm---2Mohm---------ADC port
                                                      |
                                                  1Mohm
                                                      |
                                                    GND
(i hope maintindihan nyo circuit ko)
voltage divider lang sya ?5 (parang voltage probe na x5 hehe)
ang concern ko is yung impedance, masyadong mataas!
di kaya magka-error na sa reading ng analog voltage ?  ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
regarding sa hardware:
magkakaproblema kaya ako kapag ganito circuit ko:  ???

input(tru coax) --- 2Mohm---2Mohm---------ADC port
                                                      |
                                                  1Mohm
                                                      |
                                                    GND
(i hope maintindihan nyo circuit ko)
voltage divider lang sya ?5 (parang voltage probe na x5 hehe)
ang concern ko is yung impedance, masyadong mataas!
di kaya magka-error na sa reading ng analog voltage ?  ???

why not choose lesser resistance values? The higher the series resistance, the smaller the current getting into the ADC pin, which means the charge holding capacitor of the ADC module will takes a significant amount of time to charge. This will lead either to significant error in the voltage reading or a slower sampling time.

If you are using PIC microcontroller, the recommended total source resistance seen by the ADC input pin should be lesser than 10k ohms. The smaller the source resistance the better.
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
why not choose lesser resistance values?...
hmmm.. gumagawa kasi ako ngayon ng DIY oscilloscope. hehe  ;D
tinaasan ko yung resistance nya para gayahin yung mga mamahaling voltage probe
(supposed to be 10Mohm)..
what if padaanin ko muna sa sa op-amp (or diff amp)?  ???
di kaya mas malaki ang error ko?
may opamp ba na kayang mag-operate down to 3.3V supply?
...which means the charge holding capacitor of the ADC module will takes a significant amount of time to charge. This will lead either to significant error in the voltage reading or a slower sampling time...
sa ngayon naka-set yung TAD ng ADC sa 3.2us, ok na kaya yun?
2us daw ang minimum ng pic16LF73 according sa datasheet..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
regarding sa hardware:
magkakaproblema kaya ako kapag ganito circuit ko:  ???

input(tru coax) --- 2Mohm---2Mohm---------ADC port
                                                      |
                                                  1Mohm
                                                      |
                                                    GND
(i hope maintindihan nyo circuit ko)
voltage divider lang sya ÷5 (parang voltage probe na x5 hehe)
ang concern ko is yung impedance, masyadong mataas!
di kaya magka-error na sa reading ng analog voltage ?  ???

If you look at the datasheet there is a +/-500nA leakage on the A/D input. This is like a 10M on parallel either to GND or VCC at 5V.
Also the A/D capacitance of 120pF will drop down the voltage during sampling.

Still on the datasheet, Microchip recommends a max. source impedance of 10Kohms to be accurate.  Your schematic shows a 1M impedance.
I think you need an opamp follower to decrease the impedance.
The Cebuano Geek

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
>what if padaanin ko muna sa sa op-amp (or diff amp)?  ???
Yes, it is needed. See my post above.

>di kaya mas malaki ang error ko?
No. Opamps should not affect. Voltage offset though affects at lower inputs near 0V. But you could correct this by using a negative voltage supply or floating ground (1/2Vcc) and subtract the 1/2Vcc in software.

>may opamp ba na kayang mag-operate down to 3.3V supply?
Yes there are. We are using mostly 3V opamp. LMV358 is the one we use.

>sa ngayon naka-set yung TAD ng ADC sa 3.2us, ok na kaya yun?
>2us daw ang minimum ng pic16LF73 according sa datasheet..
Yes, TAD is minimum 1.6uS in 877. Maybe same as your chip.
BTW, you can use the smallest TAD to be fast.  This does not affect your input impedance. But the 120pF sampling cap does affect in AC reading.
The Cebuano Geek

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
>di kaya mas malaki ang error ko?
No. Opamps should not affect. Voltage offset though affects at lower inputs near 0V. But you could correct this by using a negative voltage supply or floating ground (1/2Vcc) and subtract the 1/2Vcc in software.
paano yung floating ground???
right now, yung supply ko is only single +3.3V, almost near na sya sa maximum supply ng LCD display ko..
it would be impractical kung gagamit pa ko ng additional negative supply..  :(
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Add a 1.65V regulator or another opamp to output 1.65V and put the negative input (scope GND) of your scope there.
You main input opamp still is supplied at 3.3V. Your pic ground will not be the same as your input ground.
The Cebuano Geek

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Yes, TAD is minimum 1.6uS in 877. Maybe same as your chip.
1.6us kung 16F73
2us kung 16LF73 --> ito gamit ko ngayon, para pwede ko syang i-operate down to 3.3V..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Add a 1.65V regulator or another opamp to output 1.65V and put the negative input (scope GND) of your scope there.
You main input opamp still is supplied at 3.3V. Your pic ground will not be the same as your input ground.
hindi ko pa rin ma-imagine ito, kanina pa..  :'(
paano nya nako-correct yung offset voltage during when the input is near 0 volt?  ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
hindi ko pa rin ma-imagine ito, kanina pa..  :'(
paano nya nako-correct yung offset voltage during when the input is near 0 volt?  ???

If the opamp config is single supply and the non-inverting input reaches near zero, the output will have an error.
To solve this the input ground will be raised to 1.65V.
Like this:
Code: [Select]
                   |\
Scope IN+o---------|+\
                   |  +-+--o To ADC
                +--|-/  |
                |  |/   |                o 3.3V
                |       |                |
                +-------+               100K
                                /|       |
                               /+|-------+-----+
Scope IN- o----------------+--+  |       |     |
                           |   \-|--+   100K  1uF
                           |    \|  |    |     |
                           +--------+    |     |
                                        GND   GND

Edit: Using this, you can also read negative values or zero crossing AC waves. Just subtract half of the max reading in software.
The Cebuano Geek

Philippine Electronics Forum


 

Privacy Policy

Contact Us: elabph@yahoo.com