adc not working on hardware but works on proteus

Home Forums Microcontrollers PIC Microcontroller adc not working on hardware but works on proteus

Tagged: , , , ,

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #15789
    Linda11
    Participant

    I’m doing ADC with PIC 18F46K22, 16×2 lcd, LM3 temperature sensor, 20 MHz oscillator, MPLAB XC8 and PicKit3 programmer. I can do the generate the hex file and simulate it on Proteus and it works fine, but on hardware it doesn’t work. The LCD is switched on, but doesn’t display the analog value.

    I wrote a small program to switch the led on off with delay and write something on the LCD on off with delay and this works on Proteus and hardware.

    Please assist

    #15807
    Ligo George
    Keymaster

    It is very difficult to analyse the problem with above details. Kindly attach a photo of your LCD and the program you are using.

    #15850
    Linda11
    Participant

    Find attached is my adc code and proteus simulation file.

    #15852
    Linda11
    Participant

    I’m struggling to send the proteus file.

    #15888
    BaseMell
    Participant

    Hi..in my case I found that the microcontroller is powered by +5V. I had to change the Power Rail Voltage to +3.3V.
    I changed the voltage from the “Design->Configure Power rails” menu entry. From the drop down list, I picked VCC/VDD and changed the voltage from 5 to 3.3. Now it works correctly.

    #15891
    Linda11
    Participant

    Thank the hardware is working. I had to modify the codes.

    #15900
    Omeken
    Participant

    I am with LM35, LCD 16*2, and 16F877A. I want to use different value (read temperature and reference temperature) of the temperature to on or off the two LED. The code is only controlling one LED RD0.

    // LCD module connections
    sbit LCD_RS at RB0_bit;
    sbit LCD_EN at RB1_bit;
    sbit LCD_D4 at RB2_bit;
    sbit LCD_D5 at RB3_bit;
    sbit LCD_D6 at RB4_bit;
    sbit LCD_D7 at RB5_bit;
    
    sbit LCD_RS_Direction at TRISB0_bit;
    sbit LCD_EN_Direction at TRISB1_bit;
    sbit LCD_D4_Direction at TRISB2_bit;
    sbit LCD_D5_Direction at TRISB3_bit;
    sbit LCD_D6_Direction at TRISB4_bit;
    sbit LCD_D7_Direction at TRISB5_bit;
    // End LCD module connections
    
    unsigned int read_value=0, ref_value;
    unsigned int value=0;
    unsigned int temp;
    char aux[7];
    
    void main()
    {
      RD0_bit = 0;
      RD1_bit =0;
      ADCON1 = 0x00; // All channels are config as analog I/p.
    
      ADC_Init();
      Lcd_Init(); // Initialize LCD
      Lcd_cmd(_lcd_clear);
      Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
      Lcd_out(1,3,"Temperature:");
      LCD_Out(2,1,"Eff:    Ref:");
    
      while(1)
      {
        read_value = Adc_Get_Sample(2)>>2;
        ref_value  = ADC_Get_Sample(4)>>2;
    
        if (read_value < ref_value)
        {
          PORTD.RD0 = 1;
          if (read_value > ref_value)
            PORTD.RD1 = 1;
          else
            PORTD.RD1 =  0;
          PORTD.RD0 = 0;
        }
    
        value = (unsigned int) read_value * (500./255); // Resolution for 5 volts, 8 bits
        ByteToStr(value,Ltrim(aux));
        LCD_Out(2,5, aux); //shows reading temperature
    
        value = (unsigned int) ref_value * (500./255);
        ByteToStr(value,Ltrim(aux));
        LCD_Out(2,13, aux); //shows reference temperature
    
        delay_ms(50);
      }
    }
    
    #15908
    Omeken
    Participant

    I have rectified the problem, the design is now working . I changed to
    RD0_bit = 0;
    RD1_bit =0 ; to TRISD = 0;

    • This reply was modified 4 years, 8 months ago by Ligo George.
    #15909
    Omeken
    Participant

    I mean changing RD1_bit = 0; to TRISD = ;

     

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
>