Problem with 10-bit A/D conversion - PIC18F2455 - LCD
Hello,
I have written code for 10-bit A/D conversion with PIC18F2455, but not working properly, value on LCD display is not correct.
I used sample code from melbas written for 10-bit A/D conversion on LCD for PIC18F4550.
I only changed values for define LCD registers and bits.
http://melabs.com/samples/LABXUSB-18F4550/adci10xu.htm
I using 20MHz external oscillator.
What is problem?
Thank you
Here is my code:
Define LOADER_USED 1
DEFINE OSC 48
' Define LCD registers and bits
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTC
Define LCD_RSBIT 7
Define LCD_EREG PORTC
Define LCD_EBIT 6
DEFINE LCD_BITS 4 ' 4-bit data bus
DEFINE LCD_LINES 2 ' LCD - 2 lines
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval var word ' Create adval to store result
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00001010 ' Set PORTA analog...
ADCON2 = %10000000 ' ...and right justify result
Pause 500 ' Wait .5 second
loop: ADCIN 0, adval ' Read channel 0 to adval
Lcdout $fe, 1 ' Clear LCD
Lcdout "Value: ", DEC adval ' Display the decimal value
Pause 100 ' Wait .1 second
Goto loop ' Do it forever
End
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
Quote:
ADCON2 = %10000000 ' ...and right justify result
and set the conversion clock to fosc/2
way out of specs
ADCON2 = %10000011 ' ...and right justify result and use frc
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
I changed
ADCON2 = %10000000
to
ADCON2 = %10000011
it is still the same :confused:
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
What is your ADC source and how is it connected?
What are the current readings and what are the expected readings?
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
Source is pressure sensor (output 0 - 1V), wchich is normaly working with 10-bit A/D - PIC16F877 conection.
I built conection with PIC18F2455, but not working properly. :confused:
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
Problem is solved, I changed LCD display, it is OK. :)
Thanks for your help.
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
kuba230,
If I may jump in here now that your problem is solved...
Quote:
but not working properly, value on LCD display is not correct.
So just curious... Was the 'bad' LCD displaying garbage characters or was it displaying a somewhat valid number??
Please be more specific as to what the 'bad' LCD was displaying.
Being more specific on describing the problem is more likely to help solve future problems :)
dwight
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
To clarify... the reason I asked the above question(s) is because it seems to me that if the LCD was displaying any reasonable characters then the LCD was working.
Was it an LCD contrast issue or were the characters complete garbage??
Is it possible that you also fixed something else in your code that was suggested by the other reply's to your questions and that was the real problem??
That is why I asked about what exactly you were seeing on the LCD.
dwight
1 Attachment(s)
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
I atached photo of my wrong LCD. I do not know, what is the problem with LCD.:confused:
Display is marked as MC10621E8-SYL, *W 4034
But after changing, everything is OK.
Attachment 8230
Re: Problem with 10-bit A/D conversion - PIC18F2455 - LCD
Hey Kuba230,
Thanks for posting the picture. So to me the picture says a lot... It definitely shows a problem with the LCD but it also shows that your code is working, more or less.
I would submit that if others that posted comments about checking your register settings and AD setup would have known your display looked like that they would have suggested a problem with the LCD before talking about your code setup.
It's obvious that you were smart enough to recognize that there was an issue with the LCD and you replaced the defective display.
The reason I am focusing in on the idea of accurately describing your problem is because I have spent the last several days working with a new electronic technician and trying to teach troubleshooting techniques. It has become clear to me that it is very important for one (anyone) to really think about what the symptoms in a given circuit are telling you, and if you are inviting others to make suggestions then the more accurate you can describe the problem then the more accurate will be the feedback.
Really just an academic point of learning to better communicate both with others and with ourselves.
cheers
dwight