|
|
View previous topic :: View next topic |
Author |
Message |
Greg Kuric Guest
|
AD Conversion not functioning as expected on 16C773 |
Posted: Wed Mar 12, 2003 10:17 am |
|
|
<font face="Courier New" size=-1>I'm in the beginning stages of building a handheld, recording PRESSURE gauge, battery powered, with IR download link. I've built a prototype board with the PIC16C773 as the brain, an 8x2 LCD for display, and a 10K pot for the A/D input. When I run the following code, my LCD scales from 0 to 65535 (approx.). This is not what I was expecting. If the A/D is 12 bit, the scale should be from 0 to 4095.
#include <16c773.h>
// Note: Modified the following line in 16c773.h to add the 'ADC=12'. Without mod. the A/D scale was 0 to 255
// #device PIC16C773 ADC=12
#include "Lcd.c"
#use delay (clock=3686400)
void main(void){
long value;
lcd_init();
delay_ms(500);
setup_adc_ports( AN0_ANALOG | VSS_VDD );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
while (TRUE) {
value = read_adc( ADC_START_AND_READ );
printf( lcd_putc, "\n\%8lu", value );
delay_ms(1000);
}
}
The second question I have is with changing the voltage reference. When I change the following line to activate RA3 to be the high reference, the pin reads 0.00v and not the 4.096 that I was expecting.
.................... setup_adc_ports( AN0_ANALOG | VSS_VRH );
0162: MOVLW 4E
0163: BSF 03.5
0164: MOVWF 1F
Here is the enviroment I'm working with:
> CCS PCM C Compiler, Version 3.147, 17877
> Using MPLAB IDE 6.10
> Programming Chip on PICSTART Plus, w/ version3.10
Any help that could be given is greatly appreciated.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12571 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: AD Conversion not functioning as expected on 16C773 |
Posted: Wed Mar 12, 2003 1:18 pm |
|
|
:=<font face="Courier New" size=-1>I'm in the beginning stages of building a handheld, recording PRESSURE gauge, battery powered, with IR download link. I've built a prototype board with the PIC16C773 as the brain, an 8x2 LCD for display, and a 10K pot for the A/D input. When I run the following code, my LCD scales from 0 to 65535 (approx.). This is not what I was expecting. If the A/D is 12 bit, the scale should be from 0 to 4095.
</font>
----------------------------------------------------------
The most likely reason is that the ADFM bit is set to 0.
This is the default power-up state, and it causes the A/D
result to be left-justified in a 16-bit word. That's what
you're seeing.
Fix this by setting the ADFM bit to 1.
Example:
#bit ADFM_BIT = 0x9F.7
main()
{
// Put A/D setup code here.
// Put this line after the other A/D init code.
ADFM_BIT = 1; // Right justify the A/D result
// Put other code here.
while(1);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12580 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|