PDA

View Full Version : Adc For 16f88



savnik
- 25th March 2008, 11:53
I am using a 16F88 for a project and i want to show simultaneous conversion of two ADC channels, AN0 and AN1 on LCD.
My problem is that the LCD shows the clues alternately and no simultaneous
My code


DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

adval VAR WORD
adval1 VAR WORD

ANSEL = %00000011
CMCON = 7
TRISA = %00000011
ADCON0 = %11001001
ADCON1 = %10000000

INCLUDE "LCDbar_INC.bas"

loop:
ADCIN 0, adval
adval = (adval */ 500)>>2
LCDOut $fe,1,"L:"
@ BARgraph _adval, 1, 2, 16, 100, lines
ADCIN 1, adval1
adval1 = (adval1 */ 500)>>2
LCDOut $fe,$C0,"R:"
@ BARgraph _adval1, 2, 2, 16, 100, lines
PAUSE 300
GoTo loop

Kamikaze47
- 25th March 2008, 13:23
I'm not clear on the problem you are having.

What is it doing or not doing? And what should it do instead?

Jerson
- 25th March 2008, 14:39
to show simultaneous conversion of two ADC channels, AN0 and AN1 on LCD.
My code


DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

adval VAR WORD
adval1 VAR WORD

ANSEL = %00000011
CMCON = 7
TRISA = %00000011
ADCON0 = %11001001
ADCON1 = %10000000

INCLUDE "LCDbar_INC.bas"

loop:
ADCIN 0, adval
adval = (adval */ 500)>>2
ADCIN 1, adval1
adval1 = (adval1 */ 500)>>2
LCDOut $fe,1,"L:"
@ BARgraph _adval, 1, 2, 16, 100, lines
LCDOut $fe,$C0,"R:"
@ BARgraph _adval1, 2, 2, 16, 100, lines
PAUSE 300
GoTo loop


Try above code. You may need to pause between the 2 adcin statements.

mister_e
- 25th March 2008, 14:55
Not sure that would help, i would suggest to check the analog source impedance first. Must meet the datasheet requirement. You could still increase the ADC_SAMPLEUS and or check what you maths will do.

As your maximum value range is 100... why not using a 8 Bit conversion instead?

savnik
- 25th March 2008, 15:42
I'm not clear on the problem you are having.

What is it doing or not doing? And what should it do instead?
I want to measure the audio input at the left and the right channel of a stereo coder (is for fm transmitter).
The left channel show on first line and the right channel show on second line on the 2X16 LCD.
But the LCD first show the left channel and after show the right channel alternately (very fast).

Kamikaze47
- 25th March 2008, 16:24
you may want to change the line:

LCDOut $fe,1,"L:"

to:

LCDOut $fe,1,$fe,2,"L:"

mister_e
- 25th March 2008, 17:03
There's something obvious that just jump to my face. You're using the default LCD assignment, and this use a.0, a.1... which is also your adc channels.

so unless you forgot something in your copy/paste, or i totally misunderstood something

EDIT: one more... Assuming you're using the internal OSC, you want to configure it properly... unless the whole beast will run @32KHz

OSCCON = %01100000 ' 4MHz

Don't forget to check your maths range... sure it will overflow the max 100 soon.

savnik
- 25th March 2008, 18:08
There's something obvious that just jump to my face. You're using the default LCD assignment, and this use a.0, a.1... which is also your adc channels.

so unless you forgot something in your copy/paste, or i totally misunderstood something

EDIT: one more... Assuming you're using the internal OSC, you want to configure it properly... unless the whole beast will run @32KHz

OSCCON = %01100000 ' 4MHz

Don't forget to check your maths range... sure it will overflow the max 100 soon.
I use external xtal 4mhz and the below LCD assignment



DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

savnik
- 27th March 2008, 18:43
Any idea for my problem;

mister_e
- 27th March 2008, 21:45
it worked fine here... sorry.

Darrel Taylor
- 27th March 2008, 23:14
I think Kamikaze47 had the right idea, but mistyped it.

LCDOut $fe,2,"L:"
<br>

savnik
- 28th March 2008, 06:15
I think Kamikaze47 had the right idea, but mistyped it.

LCDOut $fe,2,"L:"
<br>
Ok , i will try.