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.

10 bits adc using 16f877

Status
Not open for further replies.

sixty9sandals

New Member
hi..

i have a problem in converting the 10bits analog value into digital and display it in a row of 10 LEDs..what happen is, its just able to display maximum 8bits value, which mean only a value range in 8bits will succesfull been display.
as example: if the value is 760, the displays result suppose to be
10 1111 1000, but what have been display is 00 1111 1000. im using a combination of PORTB, PORTD.0 and PORTD.1:

anyone who can help me,pls?
 
sixty9sandals said:
hi..

i have a problem in converting the 10bits analog value into digital and display it in a row of 10 LEDs..what happen is, its just able to display maximum 8bits value, which mean only a value range in 8bits will succesfull been display.
as example: if the value is 760, the displays result suppose to be
10 1111 1000, but what have been display is 00 1111 1000. im using a combination of PORTB, PORTD.0 and PORTD.1:

anyone who can help me,pls?

Well, with ADFM set to 1 for the nice, easier ordering, you could copy the value of ADRESL into PORTB, and ADRESH into PORTD, and PORTD should be find because the 6 MSB's that are unused are just 0's, meaning that the 2 bits from the 10-bit A/D conversion would go into PORTD.0 and PORTD.1. Got that? I'm not quite sure though.
 
You might check my ADC PIC tutorial, it explains it more simply than the datasheet (which can be a bit confusing) - try posting your code, it sounds like you may not be selecting the correct bank for the upper bits?.
 
Nigel Goodwin said:
You might check my ADC PIC tutorial, it explains it more simply than the datasheet (which can be a bit confusing) - try posting your code, it sounds like you may not be selecting the correct bank for the upper bits?.

hi there..thanks for ur help..ive visit your site..but the problem is all the tutorial are using an assembler. i try to work out using a compiler name MicroCode Studio from pic

so..in the simple way to understand..the code is something like below..

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

MEASURED_VALUE VAR BYTE
REMAINDER0 VAR BYTE
MEASURED0 VAR BYTE

REMAINDER1 VAR BYTE
MEASURED1 VAR BYTE

REMAINDER2 VAR BYTE
MEASURED2 VAR BYTE

REMAINDER3 VAR BYTE
MEASURED3 VAR BYTE

REMAINDER4 VAR BYTE
MEASURED4 VAR BYTE


REMAINDER5 VAR BYTE
MEASURED5 VAR BYTE

REMAINDER6 VAR BYTE
MEASURED6 VAR BYTE

REMAINDER7 VAR BYTE
MEASURED7 VAR BYTE

REMAINDER8 VAR BYTE
MEASURED8 VAR BYTE

REMAINDER9 VAR BYTE
MEASURED9 VAR BYTE

TRISA = 255
TRISB = %00000000
TRISD.0 = %0
TRISD.1 = %0

ADCON1 = 0
ADCIN 0 , MEASURED_VALUE
PORTD.0 = %1
PORTD.1 = %1
PORTB = %11111111

START:


MEASURED_VALUE = 376

REMAINDER0 = MEASURED_VALUE // 2
PORTB.0 = ~REMAINDER0
MEASURED0 = ( MEASURED_VALUE / 2 )
if MEASURED0 < 1 THEN GOTO START

REMAINDER1 = MEASURED0 // 2
PORTB.1 = ~REMAINDER1
MEASURED1 = ( MEASURED0 / 2 )
if MEASURED1 < 1 THEN GOTO START

REMAINDER2 = MEASURED1 // 2
PORTB.2 = ~REMAINDER2
MEASURED2 = ( MEASURED1 / 2 )
if MEASURED2 < 1 THEN GOTO START

REMAINDER3 = MEASURED2 // 2
PORTB.3 = ~REMAINDER3
MEASURED3 = ( MEASURED2 / 2 )
if MEASURED3 < 1 THEN GOTO START

REMAINDER4 = MEASURED3 // 2
PORTB.4 = ~REMAINDER4
MEASURED4 = ( MEASURED3 / 2 )
if MEASURED4 < 1 THEN GOTO START

REMAINDER5 = MEASURED4 // 2
PORTB.5 = ~REMAINDER5
MEASURED5 = ( MEASURED4 / 2 )
if MEASURED5 < 1 THEN GOTO START

REMAINDER6 = MEASURED5 // 2
PORTB.6 = ~REMAINDER6
MEASURED6 = ( MEASURED5 / 2 )
if MEASURED6 < 1 THEN GOTO START

REMAINDER7 = MEASURED6 // 2
PORTB.7 = ~REMAINDER7
MEASURED7 = ( MEASURED6 / 2 )


REMAINDER8 = MEASURED7 // 2
PORTD.0 = ~REMAINDER8
MEASURED8 = ( MEASURED7 / 2 )


REMAINDER9 = MEASURED8 // 2
PORTD.1 = ~REMAINDER9


GOTO START


END

so..any suggestion on solving this problem
 
sixty9sandals said:
DEFINE ADC_BITS 10

MEASURED_VALUE VAR BYTE

You're trying to store a 10-bit number into a byte and the most significant bits are lost. Try to define MEASURED_VALUE as a 16-bit variable (integer?)
 
As stated earlier, changed

Code:
MEASURED_VALUE VAR BYTE

To

Code:
MEASURED_VALUE VAR WORD

and if your just trying to display the binary equiv of a 10-bit register, why cant you just do this?

PORTB.0 = MEASURED_VALUE.0
PORTB.1 = MEASURED_VALUE.1
PORTB.2 = MEASURED_VALUE.2
.
.
.

Goto Start

Instead of this for every bit

Code:
REMAINDER0 = MEASURED_VALUE // 2
PORTB.0 = ~REMAINDER0
MEASURED0 = ( MEASURED_VALUE / 2 )
if MEASURED0 < 1 THEN GOTO START
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top