anjalimidhuna
Member level 3
- Joined
- Jan 4, 2014
- Messages
- 62
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 8
- Location
- india
- Activity points
- 358
i want to display the ac voltage
i want to display the value of average ac from the mains ultimately(230V, 50 Hz). .
What is the ADC input signal voltage you have given (For getting the value 9 )?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 /********************program to test adc functioning*********************/ #include<pic.h> #include<htc.h> #include<stdlib.h> #include"lcdfn.h" #include"ADC.h" unsigned long value; char *int_to_string(unsigned long int i, unsigned char buf[]); void convert(unsigned long adc_value); //MAIN STARTS HERE void main() { Lcd_Init(); adc_init(); LCD(Lcd_clear,ModCmd); Delay_ms(100); LCD(FstLin_FstColumn,ModCmd); while(1) { value=AdcRead(ch0); convert(value); } } void convert(unsigned long adc_value) { unsigned int int_part,deci_part; unsigned char strngIntPart[],strngDeciPart[]; unsigned char strngInt[4],strngDeci[4]; int_part=adc_value/100; deci_part=adc_value%100; int_to_string(int_part,strngIntPart); int_to_string(deci_part,strngDeciPart); Disp_STRING(strngIntPart); LCD('.',ModData); Disp_STRING(strngDeciPart); } char *int_to_string(unsigned long int i, unsigned char buf[]) { unsigned char temp; unsigned char s = 0,t = 0; while(i) { buf[s++] = i % 10 + 0x30; i /= 10; } buf[s] = 0; s-=1; for(;t<s;t++,s--) { temp = buf[s]; buf[s]=buf[t]; buf[t]=temp; } return buf; }
Post code of ADCRead() function.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 /*INITIALISE ADC*/ void adc_init() { TRISA=0XFF; TRISE0=1; ADCON1=0X80; } /* READ ADC VALUES*/ unsigned char AdcRead() { ADCON0=0x55; while(GODONE==1); temp=((ADRESH<<8)+ADRESL); return temp; }
unsigned char AdcRead()
{
ADCON0=0x55;
while(GODONE==1);
temp=((ADRESH<<8)+ADRESL);
return temp;
}
[B]unsigned int [/B]AdcRead()
{
[B]unsigned int temp;[/B]
ADCON0=0x55;
while(GODONE==1);
temp=((ADRESH<<8)+ADRESL);
return temp;
}
hello
Code:unsigned char AdcRead() { ADCON0=0x55; while(GODONE==1); temp=((ADRESH<<8)+ADRESL); return temp; }
return value must be integer 16 bits not unsigned char
Where is defined temp ?
in the main you use a long int to receive result of AdcRead..
so
Code:[B]unsigned int [/B]AdcRead() { [B]unsigned int temp;[/B] ADCON0=0x55; while(GODONE==1); temp=((ADRESH<<8)+ADRESL); return temp; }
char *int_to_string(unsigned long int i, unsigned char* buf)
{
unsigned char temp;
unsigned char s = 0,t = 0;
while(i)
{
buf[s++] = i % 10 + 0x30;
i /= 10;
}
buf[s] = 0;
s-=1;
for(;t<s;t++,s--)
{
temp = buf[s];
buf[s]=buf[t];
buf[t]=temp;
}
return buf;
}
Value=513;int_to_string(Value, buf);
k=fprintf(_H_USART,(const rom unsigned char *)"ADC= %ld %s\r\n",Value,buf);
Value=1023;
int_to_string(Value, buf);
k=fprintf(_H_USART,(const rom unsigned char *)"ADC= %ld %s\r\n",Value,buf);
Value=Mesure_ADC(0);
int_to_string(Value, buf);
k=fprintf(_H_USART,(const rom unsigned char *)"ADC= %ld %s\r\n",Value,buf);
CRLF()
ADC= 513 513
ADC= 1023 1023
ADC= 224 224
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?