![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Einly Guest
|
ADC/ LCD |
Posted: Mon Apr 21, 2003 12:43 am |
|
|
Dear all,
I connected a potentiometer to pin A0 of pic 16f876 to vary the input voltage and use the ADC to convert the analog signal to 8 bit digital value. The converted value is displayed using LCD016L.
Pin Connection:
MCLR - 5V, A0-potentiometer, OSC1-OSC2-20MHz crystal & 15pF capacitor, B0-enable(LCD), B1-rs(LCD), B2-rw(LCD), B4-DB4(LCD), B5-DB5(LCD), B6-DB6(LCD), B7-DB7(LCD)
Program:
#include<16f876.h>
#device adc=8
#use delay(clock=20000000)
#FUSES NOPROTECT,NOWDT,hs,nolvp
#include <lcd.c>
#byte porta=5
#byte portb=6
main()
{
int i,value,volt1=0,volt2=0,volt3=0;
char result[3];
set_tris_b(0); //set pin b0-b7 as output
setup_port_a(ALL_ANALOG); //use bit A0 as analogue input
setup_adc(ADC_CLOCK_INTERNAL); //use internal clock
set_adc_channel(0); //select A0 as current input
lcd_init();
//clear port b output data
PORTB=0;
//wait to start
delay_ms(2000);
lcd_putc("\fHave a nice day");
delay_ms(2000);
do
{
value=read_adc(); //read analogue input
for(i=0; i
{
volt1=volt1+1;
if(volt1==10)
{
volt2=volt2+1;
volt1=0;
if(volt2==10)
{
volt3=volt3+1;
volt1=0;
volt2=0;
}
}
}
result[0]=volt1+'0';
result[1]=volt2+'0';
result[2]=volt3+'0';
lcd_putc("\f");
lcd_putc(result[2]);
delay_ms(100);
lcd_putc(result[1]);
delay_ms(100);
lcd_putc(result[0]);
delay_ms(100);
//delay 2 seconds
delay_ms(1000);
volt1=0;
volt2=0;
volt3=0;
}while(1);
}
The program works but the value vary greatly - about +/-10. I have used a voltmeter to measure the input voltage at pin A0. Although the value does not vary much (only 0.01V), the display value vary greatly.
Can anybody help me to solve this problem?
Thanks a lot.
Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 13853 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: ADC/ LCD |
Posted: Mon Apr 21, 2003 1:13 am |
|
|
:=The program works but the value vary greatly - about +/-10. I have used a voltmeter to measure the input voltage at pin A0. Although the value does not vary much (only 0.01V), the display value vary greatly.
:=
------------------------------------------------
Instead of using the internal A/D clock,
setup_adc(ADC_CLOCK_INTERNAL);
try doing this:
setup_adc(ADC_CLOCK_DIV_32);
See if that improves the accuracy.
If that doesn't work, then add a small capacitor between
the A/D input pin and Ground. Try .01 uf, initially.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13855 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|