Samples of AC sinewave PIC16F877a

Discussion in 'Embedded Systems and Microcontrollers' started by @m@, Sep 27, 2011.

  1. @m@

    Thread Starter Member

    Mar 9, 2009
    15
    0
    Hi...!
    here is code of mine for reading channel 0 of adc works fine with dc but when I am applying AC sine wave I am not getting enough sample at terminal to correctly reconstruct it...
    Please tell me why I am not getting enough sample of sinewave to reconstruct it correctly ..
    Code ( (Unknown Language)):
    1. unsigned short temp_res;
    2. char buf[6];
    3. int i;
    4. void main() {
    5.   UART1_Init(9600);  // Initalize USART (9600 baud rate, 1 stop bit, ...
    6.    ADCON0.ADCS0=0;   // 32TOSC  :::Using External Crystal Oscillator of 20MHz:::
    7.    ADCON0.ADCS1=1;
    8.    CMCON = 0x07;      // Comparator OFF
    9.    TRISA  = 0xFF;     // PORTA is input
    10.    TRISC  = 0;        // PORTC is output
    11.    TRISB  = 0;        // PORTB is output
    12. do
    13.     {
    14.  
    15.     // Read ADC results of channel number 0 and send the upper byte via USART
    16.     temp_res = ADC_Read(0) >> 2;
    17.     PORTB = temp_res;         // Send lower 8 bits to PORTB
    18.     WordToStr(temp_res,buf);
    19.     for(i = 0; i < 6; i++)
    20.    {
    21.    // Write channel 1
    22.       UART1_Write(buf[i]);
    23.   }
    24.    UART1_Write(13); // New line
    25.      Delay_ms(1);
    26.     }
    27.       while (1);       // endless loop
    28. }[/i]

    Thank you.............!:confused:
     
Loading...