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.

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: 174
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.
 
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.
 
Check this project: PIC-based Digital Voltmeter (DVM) :Embedded-Lab
It is a digital voltmeter project and shows how to measure an input voltage greater than 0 through a PICmicro ADC channel. If you have problem writing code in assembly, you can write in C (I am hoping that you know C).
- Raj

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
    AAesp03.gif
    27.8 KB · Views: 168
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.
 
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top