Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

measure negative voltage with 16f876?

Status
Not open for further replies.

leemarrow

Full Member level 3
Joined
May 3, 2001
Messages
174
Helped
11
Reputation
22
Reaction score
9
Trophy points
1,298
Activity points
985
16f876 adcon1

Hi, i need to read negative voltage with a 16f876 on PORT RA1 connected to a LM35CZ (supply + 5 V and -5V).
i have used picbasic but it don't want read negative value:

Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS


adval var word 'Create adval to store result

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result

Pause 500 ' wait .5 second
Lcdout $fe, 1 'Clear screen

loop:
ADCIN 1, adval 'Start Conversion on RA1
pause 5

adval=(adval*10) */ 1250 'quantize
lcdout $fe,2 'cursore a home
lcdout $fe,$80,"Int ", dec2 (adval/100),".", dec1 (adval//100),$DF,"C"
'Display the decimal value on line 1
Pause 200 'Wait .1 second

Goto loop 'Do it forever
End
 

16f876 vref

Use an external ADC with negative rail or use a zero crossing detector.
 

Convert/shift the input range of -/+5V to 0-5V using opamp(s) ..
 

hi,

i ve worked on similar problem, it works. ther can b 3 solutions:firstly Ill give soltuion that i used.

1.
Another simple soltuion is to use precision rectifier and zero crosssing detector with 5v zener at o/p.

so when u start conversion, also read the pin to which u ve connected ZCD op. depending on logic level u ll come 2 know the polarity and measured analog signal will give u magnitude.
_______________________________________
2.
scale the analog signal by half using opamp.so it will become +- 2.5v.Shift the analog signal by +2.5v using opamp, so that it becomes 0 to 5v.
To measeure the actual value......just u have 2 do is:

if measured signal is greater than 2.5 v reference value, then signal is positive and its value is (measured value-2.5v ref value),

else signal is negative and it is calculated as (2.5v ref value-measured value).now u can display -ve sign b4 displaying this magnitude on LCD.

u may measure 2.5 vref value by ADC and store it in Non-volatile memory....or hardcode it to possible value.....it would be near to ox3fff/2.

Also if ur assembler can act on negative numbers then u can directly use 1st formula only.

_____________________________________________
3.
to use bipolar external ADC.....u can use TIs ADC or Analog devices ADC.
but they r costlier...
so what i suggest is u go for sol no 1.this seems to be simple.coz u dont have 2 generate 2.5v ref and all the stuff related to that.and its low cost also.


Best regards.
 

The easiest way to do this (hardware wise) is to simply link the -ve voltage to a +ve voltage rail through a voltage divider connecting to the ADC pin in the middle. Choosing the devider resistors so that the output voltage will always stay within 0-Vref.
The only downfall of this method is to calculate the "actual" voltage takes a bit of maths, and will be less accurate. (and the ussumption that your +ve voltage rail is allways constant)
So this is kind of the quick and easy approch but it will work when you aren't too woried about the accuracy of the ADC sample, or the maths involved.

Maui
 

hi, thank you, i have read the datasheet and i have found the solution setting RA2 as negative Vref.
:)
 

leemarrow said:
hi, thank you, i have read the datasheet and i have found the solution setting RA2 as negative Vref.
:)
I think you have to read it again; Vref- must be in (Vss - 0.2V, Vdd - 2V) interval, so it can't be negative.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top