View Full Version : 10 bits ADCIN with 18F2520
hwhisperer
- 6th April 2011, 17:39
Hello, I hope my question is not something stupid...
I tryed to check in the old posts but I found not one answer....
I was using ADCIN (8 Bits) with this code:
TRISA=255
ADCON1=0
DEFINE OSC 40
DEFINE ADC_BITS 8
DEFINE ADC_SAMPLEUS 50
and:
ADCIN 0, STORE_0
where STORE_0 is a byte sized variable, and it works perfet.
Now I tryed to perform a 10 bit conversion, I used a word sized variable and the define was modified in:
DEFINE ADC_BITS 10
...but it store again one value large one byte, no more...
Can someone help me posting a piece of working code for 18F2520?
Thanks
Stefano
Kamikaze47
- 6th April 2011, 17:50
I'm not sure if this is the problem, but try:
ADCON2.7=1
timmers
- 6th April 2011, 18:28
I never had any luck with DEFINE ADC_BITS 8 it allways wanted to work in 10 bit. But if you only need 8 bit, do an ADCIN with DEFINE_BITS 10 to a word variable then divide the answere by 4.
hwhisperer
- 6th April 2011, 21:05
I'm not sure if this is the problem, but try:
ADCON2.7=1
I tryed... should be someting else becouse it dont works...
thanks
Stefano
hwhisperer
- 6th April 2011, 21:08
I never had any luck with DEFINE ADC_BITS 8 it allways wanted to work in 10 bit. But if you only need 8 bit, do an ADCIN with DEFINE_BITS 10 to a word variable then divide the answere by 4.
Thanks but my problem is the opposite... it works with DEFINE ADC_BITS 8 and give me a byte value... but I need more precision and DEFINE_BITS 10 dont works in my code! :-(
Bye
Stefano
mackrackit
- 7th April 2011, 00:07
where STORE_0 is a byte sized variable, and it works perfet.
Now I tryed to perform a 10 bit conversion, I used a word sized variable and the define was modified in:
DEFINE ADC_BITS 10
...but it store again one value large one byte, no more...
Try a WORD size variable.
hwhisperer
- 7th April 2011, 00:38
Try a WORD size variable.
I did it.
The value is stored in one word size variable but the value never come bigger than 255 (the same value I had when I used the 8 bits define).
stefano
mackrackit
- 7th April 2011, 00:55
This is for a different chip but it might help. I like dealing with the registers directly, an example of both are here.
http://www.picbasic.co.uk/forum/showthread.php?t=11947&p=79694#post79694
Darrel Taylor
- 7th April 2011, 02:27
This works for 10-bit A/D on an 18F2520, using 9600 baud serial to a PC to view the results.
DEFINE OSC 40
SerPin VAR PORTC.6
DEFINE ADC_BITS 10 ; 10-bit results
ADCON2.7 = 1 ; right justify
ADval VAR WORD
Main:
ADCIN 0, ADval
SEROUT2 SerPin, 84,[DEC ADval,13,10]
PAUSE 500
GOTO Main
hwhisperer
- 9th April 2011, 08:15
Thanks to all...
I will try the code and I will reply!
Stefano
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.