+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Member level 4
    Points: 640, Level: 5

    Join Date
    Nov 2012
    Posts
    68
    Helped
    5 / 5
    Points
    640
    Level
    5

    Mikroc adc uart problem

    I wish to display the adc values coming from serial port to hyper terminal.I have created a level shifter circuit with sine wave (5 vp-p) and 2.5 v dc as inputs and input the data to the pic 16f877a

    wat i m getting from the terminal are in the range of 2.5-8.6v,since i gave input below 5.0v ,i got more than tat i expected.

    i have attached mikroc code,can ayone tell me how to fix this issue

    Code:
    char uart_rd[50],uart1_rd,uart_rd1[50];  //Declare the character strings
    float val,val1;//Declare the adcvalue stored variables
    
    
    
    void main()
    {
        TRISA=0XFF;//porta as input
        ADCON1=0X80;
        UART1_Init(9600);               // Initialize UART module at 9600 bps
    
        while(1)
        {
    
    
      val= ADC_Read(1);
      val1=(val*5.0)/1023.0;
    
      FloatToStr(val1,uart_rd1);
      //i++;
      strncpy(uart_rd,uart_rd1,4);
      UART1_Write_Text(uart_rd);
      UART1_Write(10);
      UART1_Write(13);
      
    
      delay_ms(1000);
    
    }
    
    
    }

    •   AltAdvertisment

        
       

  2. #2
    Newbie level 4
    Points: 187, Level: 2

    Join Date
    Apr 2014
    Posts
    7
    Helped
    0 / 0
    Points
    187
    Level
    2

    Re: Mikroc adc uart problem

    What values do you get when you dont do the calculation " val1=(val*5.0)/1023.0;" and just send "val" to uart (with string conversion)



    •   AltAdvertisment

        
       

  3. #3
    Advanced Member level 4
    Points: 7,943, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,299
    Helped
    263 / 263
    Points
    7,943
    Level
    21

    Re: Mikroc adc uart problem

    hello,



    show you level shifter schematic..

    do you add +2,5V to your signal 5V AC peak to peak ?



    have alook on this interface
    it's to measure main AC 230V => reduce to 1,6V efficace + 2,50V
    so adc input keept in the range 0 to 5V



--[[ ]]--