ambilys
New Member
Hi
I wish to take the samples from pic16f877a,4Mhz HS( if it is given a sine wave input) and plot the same.I am giving 230vp sine wave 50hz as input and transformed it into 5v range and level shifted it into positive voltages.
This is my code
I have checked the values in hyperterminal and see that the controller not even sample the peak voltage.I wish to have the samples correctly so that I can able to plot the waveform correctly.
I wish to take the samples from pic16f877a,4Mhz HS( if it is given a sine wave input) and plot the same.I am giving 230vp sine wave 50hz as input and transformed it into 5v range and level shifted it into positive voltages.
This is my code
Code:
// Loop variable
float val,val1;//Declare the adcvalue stored variables
char uart_rd[50],uart_rd1[50];
void main()
{
TRISA=0XFF;//porta as input
ADCON1 = 0x82; // AN0->AN4 selected as analog input
ADCON0 = 0b11000001; // Configue analog mode
UART1_Init(9600); // Initialize UART module at 9600 bps
while(1)
{
val=ADC_Read(0);
val1=(val*325.0)/1023.0;
FloatToStr(val1,uart_rd1);
strncpy(uart_rd,uart_rd1,3);
UART1_Write(val1);
//UART1_Write(10);
UART1_Write(13);
delay_us(1);
}
}
I have checked the values in hyperterminal and see that the controller not even sample the peak voltage.I wish to have the samples correctly so that I can able to plot the waveform correctly.