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.

controlling R/C servo C languange

Status
Not open for further replies.

Beng123

Newbie level 4
Joined
Nov 18, 2006
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
adcon pic

Im new in edaboard and now has a question to ask .
As i know when the analogue convert to digital,the result wil store in ADRESH AND ADRESL.
Can someone tell me the what the different about them?
if i jz wan send one bit,
on and off only.
how i get the result 1 or 0 from ADCON stored place?
 

adcon register

u may see data sheet pic 16F877a.

'(*
' * Project name:
' ADC_on_Leds
' * Copyright:
' (c) mikroElektronika, 2005 - 2006
' * Revision History:
' 20050312:
' - initial release.
' * Description:
' This code demonstrates using library function for ADC conversion
' (10 bits) result is displayed on portd and portb
' (two most significant bits are displayed on portb).
' * Test configuration:
' MCU: PIC16F877A
' Dev.Board: EasyPIC3
' Oscillator: HS, 8.000 MHz
' Ext. Modules: None
' SW: mikroBasic v5.0 or higher
' * NOTES:
' - If you are using EasyPIC3, use provided jumper on top right to connect potentiometer to RA2
' *)
program ADC_on_Leds

dim temp_res as word

main:
ADCON1 = $80 ' configure analog inputs and Vref
TRISA = $FF ' designate PORTA as input
TRISB = $3F ' designate RB7, RB6 pins as outputs
TRISD = $0 ' designate PORTD as output
while true
temp_res = ADC_read(2)
'now you can use temp_res ...'
PORTD = temp_res ' send lower 8 bits to PORTD
PORTB = word(temp_res >> 2)
' send two most significant bits to PORTB, pins RB7,RB6
wend
end.
 

adcon in pic16f877a

Hi!
Since the adc result is 10 bit wide therefore it is stored in two different registers ADRESH and ADRESL. The ADRESH contains the most significant bits where as the ADRESL contains the least significant bits.

I don't understand why u want to get just 1 or 0 from the ADC result registers.
If u want to make a decision based on the result from the ADC then compare the result with some fixed level to get the decision e.g

unsigned int resut;
#define Max_value 177;

result=ADRESH;
result=(result<<8)|ADRESL;

result now contains total ADC CONVERSION result. U can compare it with anything to get a decision e.g

if(result>Max_value)
LED=1;
else
LED=0;

Hope it helps.
Regards.

Added after 22 minutes:

Sorry the actual line is
result=(result<<8|ADRESL);

i donot know how the smiley entered the equation?

Regards.
 

    Beng123

    Points: 2
    Helpful Answer Positive Rating
pic adcon

waseem said:
Hi!
Since the adc result is 10 bit wide therefore it is stored in two different registers ADRESH and ADRESL. The ADRESH contains the most significant bits where as the ADRESL contains the least significant bits.

I don't understand why u want to get just 1 or 0 from the ADC result registers.
If u want to make a decision based on the result from the ADC then compare the result with some fixed level to get the decision e.g

unsigned int resut;
#define Max_value 177;

result=ADRESH;
result=(result<<8)|ADRESL;

result now contains total ADC CONVERSION result. U can compare it with anything to get a decision e.g

if(result>Max_value)
LED=1;
else
LED=0;

Hope it helps.
Regards.

Added after 22 minutes:

Sorry the actual line is
result=(result<<8|ADRESL);

i donot know how the smiley entered the equation?

Regards.



after Analogue conversion are complete,
how to store the result into ADRESH and ADRESL?
if i use
movf ADRESL,w

then how about the ADRESH?

and the result=(result<<8|ADRESL); <<8is wat meaning?
 

adresl adresh

The values are automatically stored in the ADRESH and ADRESL after the conversion is complete. You don't have to move data IN to those registers, only read them.
You can also configure the ADC module to be left or right justified. With left, the ADC MSB is bit 7 of ADRESH, and the 2 LSB's are stored in bits 7,6 or ADRESL. Right justified is simply the other way around.

and 'result=(result<<8|ADRESL);' is C or basic I believe.

BuriedCode.
 

    Beng123

    Points: 2
    Helpful Answer Positive Rating
pic16f877a adcon

Buriedcode said:
The values are automatically stored in the ADRESH and ADRESL after the conversion is complete. You don't have to move data IN to those registers, only read them.
You can also configure the ADC module to be left or right justified. With left, the ADC MSB is bit 7 of ADRESH, and the 2 LSB's are stored in bits 7,6 or ADRESL. Right justified is simply the other way around.

and 'result=(result<<8|ADRESL);' is C or basic I believe.

BuriedCode.

then if i wan to take the result mean i need to add let both ADRESH and ADRESL add in together.
as u say 'result=(result<<8|ADRESL);' is C or basic then if i wan use in mplab what should i write?
 

mikrobasic adcon

Hi!

I thought that you were writing ur code in C language. If u r using assembly then the code will be totally different. Moreover as already posted that u donot have to store the result in ADRESH and ADRESL registers. The ADC automatically places the result in these registers after the conversion is complete. U have to read the result from these registers and place it in some variables before starting a new conversion.
If u are using assembly then i can give u a code that will not only save the result but also convert it to BCD. which can be easily displayed.

Regards.
 

    Beng123

    Points: 2
    Helpful Answer Positive Rating
the adcon register

waseem said:
Hi!

I thought that you were writing ur code in C language. If u r using assembly then the code will be totally different. Moreover as already posted that u donot have to store the result in ADRESH and ADRESL registers. The ADC automatically places the result in these registers after the conversion is complete. U have to read the result from these registers and place it in some variables before starting a new conversion.
If u are using assembly then i can give u a code that will not only save the result but also convert it to BCD. which can be easily displayed.

Regards.

OK,then can u give me the code as reference.
tqtq...
 

langage c adresh adresl

Hi Beng123,
Since Adc of Pic micro is of 10 bit, the result is also 10 bits and hence to keep the result, Pic is having 2x 8 bit register. Lower 8 bits are stored in Adresl and higher 2 bits are stored in Adresh register. Other 6 bits of of Adresh register remains blank. If you require the 10 bit result, you have to use both the registers. If you want 8 bit result, you can set the ADFM bit in Adcon1 register to make it right justification and then use only Adresl register to get the lower 8 bit result. Or you can make the ADDM bit 0 and hence the result will be left justified and you then use only Adresh register to get the higher 8 bits and leaving lower 2 bits in Adresl register.
Please follow the ADC portion of the Datasheet of the PIC you intend to use and you will be clear. It is very easy to understand. Thanks.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top