Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 14th January 2008, 03:40 AM   (permalink)
Question New To A/D Need Some Guide

Hi guys this is my first attempt in A/D.

My target is to build a 0-99 Celsius temperature display. (Two digits & no need decimal point)

My temperature sensor is giving 10mV per Celsius. My supply is 5V.
My analog input is AN0.

For 99 C it has to measure = 99 X 10 = 990 mV. So an eight bit resolution is more than enough.

I just checked my input (AN0) by connecting a V/R. My BCD coding gives me 0 to 255 values when I turning the preset (V/R).

My problem is how to convert this 8 bit value to temperature?

I did a small math as in the graph please tell is that correct or not? If you like you can share a method how to convert this 8 bit value to temperature.

Many Thanks
Attached Images
File Type: jpg AD Values.JPG (11.9 KB, 29 views)

Last edited by Suraj143; 14th January 2008 at 05:14 AM.
Suraj143 is online now  
Old 14th January 2008, 09:57 AM   (permalink)
Default

hi Suraj,
Have you considered setting the +Vref to +2.5V, this will double the ADRESL value.
If you just want 8 bit resolution you could also Left Justify the ADC into ADRESH.

EDIT:
If you are going to display the ADRESX value as ASCII Temperature, on a LCD, you will need a binary to ascii conversion routine in your program.
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 14th January 2008 at 10:04 AM.
ericgibbs is offline  
Old 14th January 2008, 10:01 AM   (permalink)
Default

Hi Eric thanks for your response.Actually I didn't set +Vref because i have never used Vref stuff before.

Is my data table ok?

I think i can use RLF command to make it double.

please help me.
Suraj143 is online now  
Old 14th January 2008, 10:10 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
Hi Eric thanks for your response.Actually I didn't set +Vref because i have never used Vref stuff before.

Is my data table ok?

I think i can use RLF command to make it double.

please help me.
hi,
If its a 10bit ADC, this will give a value of 1023 decimal for a an ADC input voltage of +5V, when using the internal Vref of +5V.

So, for a Vin of 1V the ADC value will be: Value = (Vin/5)* 1023
equals 204 decimal 0xCC hex.

Calculate the rest of your graph/table using the same formula,

Does this help.?
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 14th January 2008, 10:20 AM   (permalink)
Default

Hi Eric I have BCD versions.I don't need ascii i just need decimals.

Now its displaying 0 to 255 in the segments because i'm using 8 bits.I gave inputs through a V/R(preset).when I turn the preset value varies 0 to 255.I can see from the seven segments.

I need to replace the V/R to my temperature sensor.My sensor 10mV per Celsius.
For 8 bits 5/255 = 0.0196 is this correct?
Suraj143 is online now  
Old 14th January 2008, 10:30 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
Hi Eric I have BCD versions.I don't need ascii i just need decimals.

Now its displaying 0 to 255 in the segments because i'm using 8 bits.I gave inputs through a V/R(preset).when I turn the preset value varies 0 to 255.I can see from the seven segments.

I need to replace the V/R to my temperature sensor.My sensor 10mV per Celsius.
For 8 bits 5/255 = 0.0196 is this correct?
Hi,
I think you are using a LM35 temp sensor.?
If your maximum Temp is going to be 100Cdeg thats 100 * 0.01 = 1volt
So Max Value= (1/5) *1023 = 204.6.. IF you have right justified the ADC output or
Value = (1/5) *255 = 51 ... IF you have Left Justified the ADC output..

For the Temp range you are working over I would right justify and just use ADRESL output.
You will have to convert the binary value to BCD for your display.
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 14th January 2008, 10:39 AM   (permalink)
Default

Quote:
Originally Posted by ericgibbs
Hi,
I think you are using a LM35 temp sensor.?
Exactly.

Quote:
Value = (1/5) *255 = 51 ... IF you have Left Justified the ADC output..
Exactly

Quote:
For the Temp range you are working over I would right justify and just use ADRESL output. You will have to convert the binary value to BCD for your display.
Exactly.
Suraj143 is online now  
Old 14th January 2008, 10:40 AM   (permalink)
Default

My Maximum value is 51 now what do I have to do?this must divide into 100 pcs.
Suraj143 is online now  
Old 14th January 2008, 10:49 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
My Maximum value is 51 now what do I have to do?this must divide into 100 pcs.
Use an opamp to scale the voltage to a suitable range - fairly obviously you can't divide 51 into 100 pieces!.

Check my PIC tutorials for the hardware I use for A2D in the tutorials.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 14th January 2008, 11:01 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
My Maximum value is 51 now what do I have to do?this must divide into 100 pcs.
Why dont you right justify the ADC registers and just use the lower ADRESL register, this will give you 205 steps/increments for 0 to 100Cdeg.???
You will get 100/205... approx, 0.49Cdeg/increment in ADRESL

The resolution of the Tempr using 51 to represent 100Cdeg is a poor way to go, consider the Tempr resolution.
100/51= 2Cdeg resolution per increment!!!
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 14th January 2008, 12:14 PM   (permalink)
Default

Hi Eric I'll re read your above post & I'll give a try.Please give me some time to work out.
Suraj143 is online now  
Old 14th January 2008, 01:20 PM   (permalink)
Smile Well...

Welll..

Try this...

www.freewebs.com/maheshwankhede

Regards,

Simran..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Old 16th January 2008, 04:14 AM   (permalink)
Default

Hi Eric great news!

I just right justify & read the ADRESL value. I wrote my own coding & it worked. But I have only one problem.

When the value changes in the segments its flickering.

For example if the temperature is 29 Celsius when it goes to 30 the both digits flickering so in the flickering time I can see both 88 (all the segments displaying).After the value changes its ok it will display nicely.

Is it a hardware error or coding error?

How do I get a smooth value change?

Here I have attached my hardware as well as my code.

Code:
				
		list		P=16F877A
		#include	<P16F877A.inc>
		errorlevel	-302
		__config 	_CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF 
			
		cblock	20h
		Digit1,Digit2,Digit3,ADL,lsd,msd,bigmsd,Del
		endc			
			
		org	0000h
		clrf	STATUS	
Init		bsf	STATUS,RP0
		clrf	TRISB
		clrf	TRISD
		movlw	b'00000001'		;make RA0 input (sensor)
		movwf	TRISA
		movlw	b'10001110'		;result right justified,Vref+=Vdd,Vref-=Vss
		movwf	ADCON1
		bcf	STATUS,RP0			
		movlw	b'01000001'		;ADON,RA0 Channel,FOSC/8
		movwf	ADCON0
		clrf	ADL
		clrf	Digit1
		clrf	Digit2
		clrf	Digit3				
		clrf	PORTB
		clrf	PORTD
		clrf	PORTA
		goto	Main		
				
;************
;Main program
;************			
			
Main		call	Multiplex		;show the display	
		call	Check_AD		;get the AD value		
		bcf	STATUS,0
		rrf	ADL,F			;devide the AD value by by 2
		call	BCD				;call BCD & make into decimals
		call	BCD_Split		;move BCD results to segment digits
		goto	Main
									
;**********************************
;move BCD results to segment digits
;**********************************			
			
BCD_Split	movf	lsd,W
		movwf	Digit1
		movf	msd,W
		movwf	Digit2
		movf	bigmsd,W
		movwf	Digit3
		return
							
;**********************
;Read AD value routine
;**********************			
			
Check_AD	clrf	ADL
		bsf	ADCON0,GO
		btfsc	ADCON0,GO
		goto	$-1
		bsf	STATUS,RP0
		movf	ADRESL,W
		bcf	STATUS,RP0
		movwf	ADL
		return

;****************************
;8 bit to 3 digit BCD version
;****************************

BCD		movf	ADL,W
		clrf	msd			;result register1
		clrf	lsd			;result register2
		clrf	bigmsd			;result register3
		call	convert_bcd
		movf	msd,W
		call	convert_big
		return			

convert_bcd	clrf	msd			; clear the msd
		movwf	lsd			; move the number to convert into lsd
ten		movlw	.10			; load the constant 10
		subwf	lsd,w			; subtract 10 from lsd
		btfss	STATUS,0		; check if answer negative
		goto	done			; conversion complete, jump to done
		movwf	lsd			; save the answer back in lsd and
		incf	msd,F			; increment the msd
		goto	ten			; do the routine again
done		return				; return to caller
convert_big	clrf	bigmsd			; clear hundreds 
		movwf	msd			; move the hundred number to msd
hundred		movlw	.10			; load the constant 10
		subwf	msd,w			; subtract 10 from msd
		btfss	STATUS,0		; check if answer negative
		goto	hundreddone		; conversion complete, jump to hundreddone
		movwf	msd			; save the answer back in msd and
		incf	bigmsd,F		; increment the bigmsd
		goto	hundred			; do the routine again
hundreddone	return				; return to caller

;*******************************************************						
;Multiplex routine 3 digits (last digit ignoring-Digit3)
;*******************************************************	
		
Multiplex	movlw	10h
		movwf	PORTD
		movf	Digit3,W
		call	Delay
		movf	Digit2,W
		call	Delay
		movf	Digit1,W			
		goto	Delay
			
Delay		call	Table
		movwf	PORTB
		decfsz	Del,F
		goto	$-1
		clrf	PORTB
		bcf	STATUS,C
		rlf	PORTD,F
		return	

;***************************************
;Data look up table for segment patterns
;***************************************
			
Table		addwf	PCL,F
		retlw	b'01111110'		;0
		retlw	b'01100000'		;1 	  ;dp    cbdeafg
		retlw	b'00111101'		;2	
		retlw	b'01110101'		;3			
		retlw	b'01100011'		;4			
		retlw	b'01010111'		;5			
		retlw	b'01011111'		;6			
		retlw	b'01100100'		;7			
		retlw	b'01111111'		;8			
		retlw	b'01110111'		;9			
			
			
		end
Attached Images
File Type: jpg LM35.JPG (5.7 KB, 13 views)
Suraj143 is online now  
Old 16th January 2008, 06:08 AM   (permalink)
Default

Quote:
How do I get a smooth value change?
You could write your code so the display is only updated every second or so. That way the bobble will be slower when the ADC is near a changer over in value. You could also write your code to take the average of 256 ADC readings and then update the display. You also could also have noise on the ADC input. A lowpass filter may help.
__________________
--- The days of the digital watch are numbered. ---

Last edited by kchriste; 16th January 2008 at 06:11 AM.
kchriste is offline  
Old 16th January 2008, 06:16 AM   (permalink)
Default

You mean that my Multiplexing routine I must call every one second?

Quote:
You could also write your code to take the average of 256 ADC readings and then update the display.
Sorry kchriste I cannot understand this.

In my diagram is it a low pass filter?
Suraj143 is online now  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Guide to using an MCP2515? Sam Jelfs General Electronics Chat 0 4th April 2007 09:14 PM
Hotair Soldering Desoldering Guide or Tutorial is Needed xpacer General Electronics Chat 1 20th October 2006 06:56 PM
Orcad PCB Layout Manual Guide, Help ! sinkopa General Electronics Chat 1 31st March 2004 10:20 AM
ASM guide McGuinn Micro Controllers 4 2nd February 2004 01:38 AM
anyone willing to help and guide me?? philipsi Micro Controllers 2 23rd December 2003 08:02 AM



All times are GMT. The time now is 03:01 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker