Status: Assigned
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 139 by a.schaap58: problem with adc on 16F1827
http://code.google.com/p/jallib/issues/detail?id=139
Hi all,
I've started using the 16F1827 and succesfully blinked the LED.
After that I tried to use analog input, but ran into a problem.
I use jal 2.4n
This is the "pretty standard" code I use to initialise ADC:
-- ADC setup
const byte ADC_NVREF = 0 -- no external Vref
const ADC_RSOURCE = 10_000 -- Input resistance: 10K
potmeter
const ADC_HIGH_RESOLUTION = FALSE -- Low res ADC is good
enough!
include adc -- fetch the ADC librarye
adc_init() -- Initialize
const byte ADC_CHANNEL = 7 -- potmeter connected to
pin_AN7
set_analog_pin(ADC_CHANNEL) -- init the selected ADC
channel
After compiling I get some errors in adc_clock.jal
Unfortunataly I can't copy/paste the compile results so I can't show all
the errors, but it starts with:
[Line 117] "adc_adcs_bit_long" not defined
while it should be defined here: (I think)
I found this in adc_clock.jal starting at line 86
-- Normalize ADCS bits
if defined(ADCON0_ADCS) == true then
alias jallib_adcs_lsb is ADCON0_ADCS
if defined(ADCON1_ADCS2) == true then
const byte ADC_ADCS_BIT_LONG = 3
const bit ADC_ADCS_BIT_SPLIT = true
alias jallib_adcs_msb is ADCON1_ADCS2
else
const byte ADC_ADCS_BIT_LONG = 2
const bit ADC_ADCS_BIT_SPLIT = false
var volatile bit jallib_adcs_msb -- float in the air
end if
end if
if defined(ADCON1_ADCS) == true then <----missing in 16f1827.jal
alias jallib_adcs is ADCON1_ADCS
const byte ADC_ADCS_BIT_LONG = 3
const bit ADC_ADCS_BIT_SPLIT = false
end if
if defined(ADCON2_ADCS) == true then
alias jallib_adcs is ADCON2_ADCS
const byte ADC_ADCS_BIT_LONG = 3
const bit ADC_ADCS_BIT_SPLIT = false
end if
if defined(ANSEL_ADCS) == true then
alias jallib_adcs is ANSEL_ADCS
const byte ADC_ADCS_BIT_LONG = 3
const bit ADC_ADCS_BIT_SPLIT = false
end if
As "ADCON1_ADCS" appeared to be missing, I added a line to 16f1827.jal
var volatile byte ADCON1 at 0x09E
var volatile bit ADCON1_ADFM at ADCON1 : 7
var volatile bit ADCON1_ADCS2 at ADCON1 : 6
var volatile bit ADCON1_ADCS1 at ADCON1 : 5
var volatile bit ADCON1_ADCS0 at ADCON1 : 4
var volatile bit*3 ADCON1_ADCS at ADCON1 : 4 --added by me
var volatile bit ADCON1_ADNREF at ADCON1 : 2
var volatile bit ADCON1_ADPREF1 at ADCON1 : 1
var volatile bit ADCON1_ADPREF0 at ADCON1 : 0
Now it compiles with no errors, but in the Compile Results this line shows
up:
Unable to find how Vref is setup with this chip, selection Vref won't work.
Please report !
So, "report it", is what I'm doing now. :)
I'm afraid my Jal knowledge is too little to solve this problem.
BTW:
If I load the compiled program into the PIC the only ADC output I get is 0
or 255 and nothing in between if I turn the potmeter.
Due to wrong setting of Vref obviously.
I have attached my code.
Thanks for your help.
André
Attachments:
16f1827_adc_test.jal 1.4 KB
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.