adc programming help

Status
Not open for further replies.

vista102

New Member
sir,

iam new in assembly language pic progrmming and i used pic 16f877a crystel frequancy is 20mhz.I write the program for adc reading (pin RA1 battery voltage )
and my problam is how check the battery voltage below 11v and 10v(ie 1f ((adc<=614)&&(adc>=408)) ).please help me?
 

Attachments

  • Untitled.ASM
    1.6 KB · Views: 220
Last edited:
Your code is very difficult to follow as you have used hex values instead of the supplied names.

Some suggestions,
Put the config line back in the code.
Change all the hex values to the register names.
Give cblock a value like 0x20.
Location 188h doesn't even exist!

Mike.
 
Firstly, for the ADC to be able to read those voltages you need a resistor divider or your PIC will burn out!!! Did you consider this?
 
hard ware side to iam do it sir. i used resister devider to read battery voltage .battery voltage 20v (charger on time 14v,but any problam in charger i think 20v)pic get 5v
 
To read 0-20V with the pic use a 27K and 9.1 K resistor (1/4 divider) across the voltage and tap the adc from the junction of the resistors.

that gives u 0-5V on the adc representing 0-20V across the divider. Then you can run your code and display the volts.


For more precision you can also use a potentiometer, get a 50K trimmer and adjust it to read 10K on one side and 40K on the other. That gives a 1/5 divider. Ground the low side pin. Hi volts on the opposing pin.

Adc from the centre pin. Your asm code may need to X5 here...a simple matter of 2 rlf and a addwf.
 
Last edited:
To read 0-20V with the pic use a 27K and 9.1 K resistor across the voltage and tap the adc from the junction of the resistors.

that gives u 0-5V on the adc representing 0-20V across the divider. Then you can run your code and display the volts.

You need to consider the source impedance, those values are much too high - although if you're only using a single analogue input, and don't need to read it too fast, it should be OK.
 

hi Raj,
My PC security software is warning me, that the site on that link is 'highly suspicious' and I should unlink from it.
 

Attachments

  • AAesp03.gif
    27.8 KB · Views: 218
Last edited:
Nigel:
Why u think it's 2 high, that 9.1k across the adc to gnd nearly matches the 10K impedance spec of the pin.
 
On the spec sheet it says "suggested maximum input impedance = 10k ohms". 9.1k is cutting it darn close. If your sampling slower though this shouldn't be an issue.
 
Nigel:
Why u think it's 2 high, that 9.1k across the adc to gnd nearly matches the 10K impedance spec of the pin.

Hi Mosaic,

I didn't check that specific PIC, but the normal maximum source impedance is only 2K - perhaps that one is higher?.
 
Here is code I use for acquistion delay, it works out to about 27uS at 2MIPS.


Code:
	movlw .10 ; port change delay for ADC
	movwf Tmp
slow	goto $+1
	decfsz Tmp,f
	goto slow
	return

Although the acquisition delay for the ports appear to be as fast as 5uS from the 16f886 datasheet the simulators I use seem to like 20uS+ delays.

Can anyone suggest a 'correct' acquisition delay time for the 16f886 at 75 degrees C? Based on the datasheet that works out to <6uS. Is this correct?

I'd like to minimise this delay as I have to do about 4 of em at a time.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…