Praveen Kumar P S
Member level 4
- Joined
- Aug 21, 2014
- Messages
- 79
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Location
- India
- Activity points
- 627
#include <18f4550.h>
#device ADC=10
#fuses XT, HS, NOWDT, NOPROTECT, BROWNOUT, NOLVP, PUT
#use delay(clock=48000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)
#include<flex_lcd216.c>
void main()
{
float32 T , val;
delay_ms(500);
lcd_init();
lcd_setcursor_vb(1,1);
printf(lcd_putc,"\f ");
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
for(;;)
{
set_adc_channel(0);
delay_ms(2);
T=read_adc();
delay_ms(10);
val=T*20*(5/1023);
lcd_gotoxy(1,1);
delay_ms(10);
printf(lcd_putc,"Adc Read:%3.2f ",T);
lcd_gotoxy(1,2);
delay_ms(10);
printf(lcd_putc,"Tem Read:%3.2f \xDFC",val);
delay_ms(500);
output_toggle(PIN_D1);
delay_ms(10);
output_toggle(PIN_E1);
delay_ms(10);
}
}
Please Zip and post complete CCS C project files so that the code can be compiled and tested.
delay_ms(10);
val=T*20*(5/1023);
lcd_gotoxy(1,1);
Code C - [expand] 1 delay_cycles() use delay_us(500).
Please Zip and post flex_lcd216.c file. I can't compile without that file
I changed the code a little and compiled for 20 MHz and it worked. If you use 48 MHz crystal or HSPLL then you need to adjust delay_cycles() in the flex_lcd216.c file. Increase the delay and it will work fine. Instead of
Code C - [expand] 1 delay_cycles() use delay_us(500).
Code:delay_ms(10); val=T*20*(5/1023); lcd_gotoxy(1,1);
change above lines with val= (T*5)/1000;
May solve ur problem
Post your circuit.
I changed the delays in flex_lcd216.c file and it worked in Proteus 8.1. If it still doesn't work then increase the delays. I compiled for 48 MHz.
hello,
What is the ref for ADC , is it 5V as +Vref and -Vref=0
so, you get 205 points for 100 °C
calculus becomes
Temp= ReadADC*100/205;
if you can use +4.096V for +VRef
you will get 250 points for 100°C
so more easy
Temp=ReadADC* 100/250;
or Temp= ReadADC *0.4;
or without floating point use:
Temp as an integer value.
Temp=ReadADc*40;
result is ! 87*40=3480
place the decimal point after the 2 first digits..
Use my code. It shows the correct value for Temperature. You don't have to give 5V to Vref+ pin as you have not enabled Vref+ pin. 500 ms delay is too much. Try using 30 ms delay and see if it works.
No, it is internaly connected to Vdd (+5V) by default config..
Except if you want to use external +VRef ( it is RAx pin ) as a voltage reference of 4.01V
you get 87 points , is the ambiant temperature around 34°C ?
also i have this strange doubt..that i have given supply of 3.6V to Pic...so my internal Vref may be 3.6V..not 5V.correct...??
Code C - [expand] 1#fuses HS, PLL5, CPUDIV1, NOWDT, NOPROTECT, BROWNOUT, NOLVP, PUT, NOMCLR
but the problem is my calculation,i suppose..Lm35dz will vary by 1 deg cel/10 mV..
but i m geting adc read between 80 and 90...i.e for 85 adc value i have a temprature of 8.5 deg cel...
Did you try my code ? Try my code in while(1) loop.
- - - Updated - - -
Read this and configure fuses properly. https://www.mikroe.com/forum/viewtopic.php?t=10646
Try attached .hex file with a 4 MHz crystal and reply.
- - - Updated - - -
Test also this .hex file which is compiled for 20 MHz crystal.
Yes, Internal Vref+ will be VDD. If you have given 3.6V as VDD then 3.6V will represent 1023 raw adc value.
Provide 5V VDD and use below fuses and a 20 MHz Crystal.
Code C - [expand] 1#fuses HS, PLL5, CPUDIV1, NOWDT, NOPROTECT, BROWNOUT, NOLVP, PUT, NOMCLR
Try rev1 code with 20 MHz crystal and 3.6V VDD.
setup_adc_ports(AN0 | VSS_VDD)
T = T / 2.84167; //2.046;
hello,
you are mixing points and mV.
ADC read gives points as result ..in your case, with +Vref=internal Vdd=3,6V
1023 pts for 3,6V or 3600mV
this full scale 3600mV represente 360°C or 1023 pts
so scaling is : Temp(°C)= ADC reading (Pts) *360/1023
if ADC read 85 pts => 85*360/1023=> 29.9°C
AN0|VSS_VDD----> Is it for directly using internal Vref...
2.84167----->why is this used?
5V = 1023 = x
1.5V = 306.9 = 150 deg C
x = 1023 * 150 / 306.9 = 500
You can use temp = adcVal * 500 / 1023
500 / 1023 = 0.4887585532746823
adcVal * 500 / 1023 can be replaced by 0.4887585532746823 or
1 / 2.046 (1/0.4887585532746823 = 2.046)
I was getting 308 instead of 306.9 as raw adc value for 150 deg C, so to adjust I used 2.84167.
setup_adc_ports(AN0 | VSS_VDD);
Embedded C Programming and the Microchip PIC by Barnett, O'Cull, Cox and of course CCS C Compiler Manual.ould u plz suggest me a good book for ccs c compiler
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?