Home › Forums › Microcontrollers › PIC Microcontroller › adc not working on hardware but works on proteus
- This topic has 8 replies, 4 voices, and was last updated 3 years, 9 months ago by Omeken.
-
AuthorPosts
-
December 20, 2018 at 6:01 pm #15789Linda11Participant
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
December 21, 2018 at 5:17 pm #15807Ligo GeorgeKeymasterIt is very difficult to analyse the problem with above details. Kindly attach a photo of your LCD and the program you are using.
January 18, 2019 at 4:59 pm #15850Linda11ParticipantFind attached is my adc code and proteus simulation file.
January 18, 2019 at 5:01 pm #15852Linda11ParticipantI’m struggling to send the proteus file.
February 18, 2019 at 11:03 pm #15888BaseMellParticipantHi..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.March 29, 2019 at 2:23 pm #15891Linda11ParticipantThank the hardware is working. I had to modify the codes.
June 13, 2019 at 1:59 pm #15900OmekenParticipantI 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); } }
June 17, 2019 at 4:21 pm #15908OmekenParticipantI 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 2 years, 11 months ago by Ligo George.
June 17, 2019 at 4:23 pm #15909OmekenParticipantI mean changing RD1_bit = 0; to TRISD = ;
-
AuthorPosts
- You must be logged in to reply to this topic.