It worked!
But how would I change it to read AN0 and AN1
How do I change the program to read multiple channels?
It worked!
But how would I change it to read AN0 and AN1
How do I change the program to read multiple channels?
which PICs work with the ADCIN command? WHich one that you used worked with that command?
Instead of the part above, you may tryCode:ADCON0.1=1 ' Set GO/DONE bit to start A/D conversion WHILE ADCON0.1=1 ' Wait for it to complete WEND adcVar.HighByte = ADRESH ' Read high-byte of result adcVar.LowByte = ADRESL ' Read low-byte of result
ADCIN 0, AdcVar
and to continue with multiple channels, you may try
ADCIN 1, AdcVar1
ADCIN 2, AdcVar2
etc.
ADCIN command will take care of setting ADC registers etc.
Edit:
Here is another version of reading as many ADC channels as available on your PIC.
Code:NumOfCh CON 7 ' Number of Analog Channels we will read. ' Change this number as desired. AdcValue VAR BYTE[NumOfCh+1] ' Array to store ADC Values in a row. Channel VAR BYTE ' Loop variable to go through channels. Start: FOR Channel = 0 TO NumOfCh ' Will read 7 analog cannnels and store ADCIN Channel, AdcValue[Channel] '..ADC values in AdcValue Array. Next Channel ' do something here. GOTO Start
Last edited by sayzer; - 16th October 2007 at 15:08. Reason: Added Array.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
What version of PBP are you using?
I don't have a 685 to test this with, but I ran it through MPSIM using ADCIN, and it appears to work
fine with v2.47. The only difference is instead of setting ADCON1.7 for right justification, you need to
set ADCON0.7. Give this a shot and let me know if it works.
You can enable more A/D pins if you need to by setting the ANSEL or ANSELH bits for each port pinCode:@ DEVICE PIC16F685,MCLR_OFF,WDT_OFF,INTRC_OSC_NOCLKOUT,PROTECT_OFF DEFINE ADC_BITS 10 ' Set clock source (3=rc) DEFINE ADC_CLOCK 3 ' Set sampling time in microseconds DEFINE ADC_SAMPLEUS 10 adcVar VAR WORD ' Create variable to store result Index VAR BYTE ' Loop index for channels ' Set PORTA to all input TRISA = %00000111 ' AN0 to AN2 inputs ANSEL = %00000111 ' AN0 to AN2 analog inputs, rest digital ANSELH = 0 ' AN8 to AN11 digital ' Set up ADCON0 (not ADCON1) like in the manual ADCON0 = %10000000 ' right justify for 10-bit Pause 500 ' Wait .5 second HIGH PORTB.6 ' Turn on status LED main: FOR Index = 0 TO 2 ' Display 3 channel results ADCIN Index,adcVar ' Read AN0 to AN2 GOSUB Display ' Display channel results NEXT Index Pause 10 ' Wait.01 second GoTo main ' Do it forever Display: serout portb.7, 6, ["Channel #",#Index,#adcVar] RETURN END
with A/D like shown in the data sheet.
Last edited by Bruce; - 16th October 2007 at 16:04.
Bookmarks