Author: sebastien.lelong
Date: Thu Jun 25 12:11:39 2009
New Revision: 1041
Added:
trunk/test/unittest/16f77_adc.jalt
Modified:
trunk/include/peripheral/adc/adc.jal
trunk/include/peripheral/adc/adc_channels.jal
trunk/tools/adc/adc_channels.jal.tmpl
Log:
heavy unittests for 16f77 + fix empty if condition + fix number of analog
ADC including Vref + fix/normalize no ADRESL register
Modified: trunk/include/peripheral/adc/adc.jal
==============================================================================
--- trunk/include/peripheral/adc/adc.jal (original)
+++ trunk/include/peripheral/adc/adc.jal Thu Jun 25 12:11:39 2009
@@ -49,6 +49,12 @@
_warn "This PIC does not seem to handle 10-bits ADC"
end if
+-- some PICs don't handle high resolution (8bits only) *and*
+-- don't have ADRESL register. Normalize !
+if defined(ADRESL) == false then
+ var volatile byte ADRESL is ADRES
+end if
+
-- local variables
var volatile byte _adcon0_shadow = 0
@@ -166,7 +172,10 @@
elsif defined(ADCON2_ADFM) == true then
var volatile bit JALLIB_ADFM is ADCON2_ADFM
else
- _err "Couldn't found ADFM bits, report this error !"
+ var volatile bit JALLIB_ADFM = 0 ; fake
+ if ADC_HIGH_RESOLUTION == true then
+ _error "Couldn't found ADFM bits, can't setup justification.
Are you
sure this PIC handles high resolution ADC ?"
+ end if
end if
if ADC_HIGH_RESOLUTION == true then
Modified: trunk/include/peripheral/adc/adc_channels.jal
==============================================================================
--- trunk/include/peripheral/adc/adc_channels.jal (original)
+++ trunk/include/peripheral/adc/adc_channels.jal Thu Jun 25 12:11:39 2009
@@ -141,35 +141,36 @@
var bit*4 one_vref = 0
var bit*4 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
+ elsif (ADC_NCHANNEL) == 2 then
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN2_direction = input
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN2_direction = input
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 6 then
+ elsif (ADC_NCHANNEL) == 6 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 7 then
+ elsif (ADC_NCHANNEL) == 7 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
@@ -177,7 +178,7 @@
adc_pin_AN0_direction = input
adc_pin_AN3_direction = input
adc_pin_AN6_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 8 then
+ elsif (ADC_NCHANNEL) == 8 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
@@ -186,7 +187,7 @@
adc_pin_AN0_direction = input
adc_pin_AN3_direction = input
adc_pin_AN6_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 9 then
+ elsif (ADC_NCHANNEL) == 9 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
@@ -196,7 +197,7 @@
adc_pin_AN0_direction = input
adc_pin_AN3_direction = input
adc_pin_AN6_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 10 then
+ elsif (ADC_NCHANNEL) == 10 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
@@ -207,7 +208,7 @@
adc_pin_AN0_direction = input
adc_pin_AN3_direction = input
adc_pin_AN6_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 11 then
+ elsif (ADC_NCHANNEL) == 11 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
@@ -219,7 +220,7 @@
adc_pin_AN3_direction = input
adc_pin_AN10_direction = input
adc_pin_AN6_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 12 then
+ elsif (ADC_NCHANNEL) == 12 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
@@ -232,7 +233,7 @@
adc_pin_AN10_direction = input
adc_pin_AN11_direction = input
adc_pin_AN6_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 13 then
+ elsif (ADC_NCHANNEL) == 13 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
@@ -246,7 +247,7 @@
adc_pin_AN10_direction = input
adc_pin_AN11_direction = input
adc_pin_AN6_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 14 then
+ elsif (ADC_NCHANNEL) == 14 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN13_direction = input
@@ -261,8 +262,9 @@
adc_pin_AN10_direction = input
adc_pin_AN11_direction = input
adc_pin_AN6_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 15 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 16 then
+ elsif (ADC_NCHANNEL) == 15 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 16 then
adc_pin_AN2_direction = input
adc_pin_AN5_direction = input
adc_pin_AN13_direction = input
@@ -312,34 +314,37 @@
var bit*4 one_vref = 0
var bit*4 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN4_direction = input
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 6 then
+ elsif (ADC_NCHANNEL) == 6 then
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 7 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 8 then
+ elsif (ADC_NCHANNEL) == 7 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 8 then
adc_pin_AN7_direction = input
adc_pin_AN5_direction = input
adc_pin_AN6_direction = input
@@ -373,23 +378,29 @@
var bit*3 one_vref = 0
var bit*3 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 4 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN4_direction = input
adc_pin_AN2_direction = input
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 6 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 7 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 8 then
+ elsif (ADC_NCHANNEL) == 6 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 7 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 8 then
adc_pin_AN7_direction = input
adc_pin_AN5_direction = input
adc_pin_AN6_direction = input
@@ -432,35 +443,36 @@
var bit*4 one_vref = 0
var bit*4 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
+ elsif (ADC_NCHANNEL) == 2 then
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN2_direction = input
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN2_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 6 then
+ elsif (ADC_NCHANNEL) == 6 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
adc_pin_AN5_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 7 then
+ elsif (ADC_NCHANNEL) == 7 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
@@ -468,7 +480,7 @@
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
adc_pin_AN5_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 8 then
+ elsif (ADC_NCHANNEL) == 8 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
@@ -477,7 +489,7 @@
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
adc_pin_AN5_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 9 then
+ elsif (ADC_NCHANNEL) == 9 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
@@ -487,7 +499,7 @@
adc_pin_AN0_direction = input
adc_pin_AN5_direction = input
adc_pin_AN8_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 10 then
+ elsif (ADC_NCHANNEL) == 10 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
@@ -498,7 +510,7 @@
adc_pin_AN9_direction = input
adc_pin_AN5_direction = input
adc_pin_AN8_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 11 then
+ elsif (ADC_NCHANNEL) == 11 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN10_direction = input
@@ -510,7 +522,7 @@
adc_pin_AN9_direction = input
adc_pin_AN5_direction = input
adc_pin_AN8_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 12 then
+ elsif (ADC_NCHANNEL) == 12 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN10_direction = input
@@ -523,7 +535,7 @@
adc_pin_AN9_direction = input
adc_pin_AN5_direction = input
adc_pin_AN8_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 13 then
+ elsif (ADC_NCHANNEL) == 13 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN10_direction = input
@@ -537,7 +549,7 @@
adc_pin_AN9_direction = input
adc_pin_AN5_direction = input
adc_pin_AN8_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 14 then
+ elsif (ADC_NCHANNEL) == 14 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN10_direction = input
@@ -577,15 +589,19 @@
var bit*3 one_vref = 0
var bit*3 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 4 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN4_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
@@ -624,34 +640,37 @@
var bit*4 one_vref = 0
var bit*4 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 6 then
+ elsif (ADC_NCHANNEL) == 6 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
adc_pin_AN5_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 7 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 8 then
+ elsif (ADC_NCHANNEL) == 7 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 8 then
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN7_direction = input
@@ -683,14 +702,17 @@
var bit*3 one_vref = 0
var bit*3 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
@@ -728,34 +750,37 @@
var bit*4 one_vref = 0
var bit*4 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN4_direction = input
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 6 then
+ elsif (ADC_NCHANNEL) == 6 then
adc_pin_AN5_direction = input
adc_pin_AN4_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 7 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 8 then
+ elsif (ADC_NCHANNEL) == 7 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 8 then
adc_pin_AN7_direction = input
adc_pin_AN5_direction = input
adc_pin_AN6_direction = input
@@ -796,33 +821,37 @@
var bit*4 one_vref = 0
var bit*4 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 6 then
+ elsif (ADC_NCHANNEL) == 6 then
adc_pin_AN2_direction = input
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN3_direction = input
adc_pin_AN0_direction = input
adc_pin_AN5_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 7 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 8 then
+ elsif (ADC_NCHANNEL) == 7 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 8 then
adc_pin_AN4_direction = input
adc_pin_AN1_direction = input
adc_pin_AN7_direction = input
@@ -864,20 +893,22 @@
var bit*4 one_vref = 0
var bit*4 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN4_direction = input
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
@@ -916,20 +947,22 @@
var bit*4 one_vref = 0
var bit*4 two_vref = 0
- if (ADC_NCHANNEL + ADC_NVREF) == 0 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 1 then
+ if (ADC_NCHANNEL) == 0 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 1 then
adc_pin_AN0_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 2 then
- elsif (ADC_NCHANNEL + ADC_NVREF) == 3 then
+ elsif (ADC_NCHANNEL) == 2 then
+ asm nop
+ elsif (ADC_NCHANNEL) == 3 then
adc_pin_AN0_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 4 then
+ elsif (ADC_NCHANNEL) == 4 then
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN2_direction = input
adc_pin_AN3_direction = input
- elsif (ADC_NCHANNEL + ADC_NVREF) == 5 then
+ elsif (ADC_NCHANNEL) == 5 then
adc_pin_AN0_direction = input
adc_pin_AN1_direction = input
adc_pin_AN4_direction = input
Added: trunk/test/unittest/16f77_adc.jalt
==============================================================================
--- (empty file)
+++ trunk/test/unittest/16f77_adc.jalt Thu Jun 25 12:11:39 2009
@@ -0,0 +1,174 @@
+-- Title: unittest to check ADC libs for 16F77
+-- Author: Sebastien Lelong, Copyright (c) 2008-2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4k
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this describes multiple unittests (a testcase), to test the
+-- many different combination while setting up ADC.
+--
+-- Notes: see jallib wiki page about unit testing to learn how to use this
file
+--
+
+;@jallib section pic_20MHz
+include 16f77 ;@no_debug
+pragma target OSC HS
+pragma target clock 20_000_000
+pragma target WDT disabled
+enable_digital_io()
+-- force analog pin/port to be output, so we can check they are
+-- automagically set as input when configured
+porta_direction = all_output
+porte_direction = all_output
+
+
+;@jallib section self_test
+include unittest
+var byte a = 120
+test_byte(a) ;@assertEquals 120 test_test
+
+
+;@jallib testcase test_8an_0vref
+;@jallib use pic_20MHz
+;@jallib use self_test
+const byte ADC_NCHANNEL = 8
+const byte ADC_NVREF = 0
+const bit ADC_HIGH_RESOLUTION = false
+include adc
+adc_init()
+
+asm nop
+test_byte(adc_conversion_delay) ;@assertEquals 21 test_compute_delay
+asm nop
+var byte adcon1_pcfg_tmp = ADCON1 & 0b_0000_0111
+test_byte(adcon1_pcfg_tmp) ;@assertEquals 0 test_pcfg
+-- check pin on PORTA configured as inputs (47 is 0b0011_1101 =>
RA{0,1,2,3,5}
+asm nop
+test_byte(TRISA) ;@assertEquals 47 test_pin_porta_input
+-- check pin on PORTE configured as inputs (7 is 0b0000_0111 => RE{0,1,2}
+asm nop
+test_byte(TRISE) ;@assertEquals 7 test_pin_porte_input
+
+
+;@jallib testcase test_7an_1vref
+;@jallib use pic_20MHz
+;@jallib use self_test
+const byte ADC_NCHANNEL = 8
+const byte ADC_NVREF = 1
+const bit ADC_HIGH_RESOLUTION = false
+include adc
+adc_init()
+
+asm nop
+var byte adcon1_pcfg_tmp = ADCON1 & 0b_0000_0111
+test_byte(adcon1_pcfg_tmp) ;@assertEquals 1 test_pcfg
+-- check pin on PORTA configured as inputs (47 is 0b0011_1101 =>
RA{0,1,2,3,5}
+asm nop
+test_byte(TRISA) ;@assertEquals 47 test_pin_porta_input
+-- check pin on PORTE configured as inputs (7 is 0b0000_0111 => RE{0,1,2}
+asm nop
+test_byte(TRISE) ;@assertEquals 7 test_pin_porte_input
+
+
+;@jallib testcase test_5an_0vref
+;@jallib use pic_20MHz
+;@jallib use self_test
+const byte ADC_NCHANNEL = 5
+const byte ADC_NVREF = 0
+const bit ADC_HIGH_RESOLUTION = false
+include adc
+adc_init()
+
+asm nop
+var byte adcon1_pcfg_tmp = ADCON1 & 0b_0000_0111
+test_byte(adcon1_pcfg_tmp) ;@assertEquals 2 test_pcfg
+-- check pin on PORTA configured as inputs (47 is 0b0011_1101 =>
RA{0,1,2,3,5}
+asm nop
+test_byte(TRISA) ;@assertEquals 47 test_pin_porta_input
+-- check pin on PORTE configured as inputs (0 is 0b0000_0000 => RE{0,1,2}
+asm nop
+test_byte(TRISE) ;@assertEquals 0 test_pin_porte_input
+
+
+;@jallib testcase test_4an_1vref
+;@jallib use pic_20MHz
+;@jallib use self_test
+const byte ADC_NCHANNEL = 5
+const byte ADC_NVREF = 1
+const bit ADC_HIGH_RESOLUTION = false
+include adc
+adc_init()
+
+asm nop
+var byte adcon1_pcfg_tmp = ADCON1 & 0b_0000_0111
+test_byte(adcon1_pcfg_tmp) ;@assertEquals 3 test_pcfg
+-- check pin on PORTA configured as inputs (47 is 0b0011_1101 =>
RA{0,1,2,3,5}
+asm nop
+test_byte(TRISA) ;@assertEquals 47 test_pin_porta_input
+-- check pin on PORTE configured as inputs (0 is 0b0000_0000 => RE{0,1,2}
+asm nop
+test_byte(TRISE) ;@assertEquals 0 test_pin_porte_input
+
+
+;@jallib testcase test_3an_0vref
+;@jallib use pic_20MHz
+;@jallib use self_test
+const byte ADC_NCHANNEL = 3
+const byte ADC_NVREF = 0
+const bit ADC_HIGH_RESOLUTION = false
+include adc
+adc_init()
+
+asm nop
+var byte adcon1_pcfg_tmp = ADCON1 & 0b_0000_0111
+test_byte(adcon1_pcfg_tmp) ;@assertEquals 4 test_pcfg
+-- check pin on PORTA configured as inputs (11 is 0b0000_1011 =>
RA{0,1,2,3,5}
+asm nop
+test_byte(TRISA) ;@assertEquals 11 test_pin_porta_input
+-- check pin on PORTE configured as inputs (0 is 0b0000_0000 => RE{0,1,2}
+asm nop
+test_byte(TRISE) ;@assertEquals 0 test_pin_porte_input
+
+
+;@jallib testcase test_2an_1vref
+;@jallib use pic_20MHz
+;@jallib use self_test
+const byte ADC_NCHANNEL = 3
+const byte ADC_NVREF = 1
+const bit ADC_HIGH_RESOLUTION = false
+include adc
+adc_init()
+
+asm nop
+var byte adcon1_pcfg_tmp = ADCON1 & 0b_0000_0111
+test_byte(adcon1_pcfg_tmp) ;@assertEquals 5 test_pcfg
+-- check pin on PORTA configured as inputs (11 is 0b0000_1011 =>
RA{0,1,2,3,5}
+asm nop
+test_byte(TRISA) ;@assertEquals 11 test_pin_porta_input
+-- check pin on PORTE configured as inputs (0 is 0b0000_0000 => RE{0,1,2}
+asm nop
+test_byte(TRISE) ;@assertEquals 0 test_pin_porte_input
+
+
+;@jallib testcase test_0an_0vref
+;@jallib use pic_20MHz
+;@jallib use self_test
+const byte ADC_NCHANNEL = 0
+const byte ADC_NVREF = 0
+const bit ADC_HIGH_RESOLUTION = false
+include adc
+adc_init()
+
+asm nop
+var byte adcon1_pcfg_tmp = ADCON1 & 0b_0000_0110 -- last bit is "x" :
unknown
+test_byte(adcon1_pcfg_tmp) ;@assertEquals 6 test_pcfg
+-- check pin on PORTA configured as inputs (0 is 0b0000_0000 =>
RA{0,1,2,3,5}
+asm nop
+test_byte(TRISA) ;@assertEquals 0 test_pin_porta_input
+-- check pin on PORTE configured as inputs (0 is 0b0000_0000 => RE{0,1,2}
+asm nop
+test_byte(TRISE) ;@assertEquals 0 test_pin_porte_input
+
+
Modified: trunk/tools/adc/adc_channels.jal.tmpl
==============================================================================
--- trunk/tools/adc/adc_channels.jal.tmpl (original)
+++ trunk/tools/adc/adc_channels.jal.tmpl Thu Jun 25 12:11:39 2009
@@ -86,17 +86,21 @@
#set dummy_pic = $ds_pic[dsref][-1]
#for i,(numch,dconf) in enumerate(smap)
#if i == 0
- if (ADC_NCHANNEL + ADC_NVREF) == $numch then
+ if (ADC_NCHANNEL) == $numch then
#else
- elsif (ADC_NCHANNEL + ADC_NVREF) == $numch then
+ elsif (ADC_NCHANNEL) == $numch then
#end if
- #for strpin in dconf['analog_pins']:
- #set an_pin = strpin[0].split("/")[0]
- #if not an_pin.startswith("AN")
- #silent an_pin = $adc_pins[dummy_pic][an_pin]
- #end if
+ #if dconf['analog_pins']
+ #for strpin in dconf['analog_pins']:
+ #set an_pin = strpin[0].split("/")[0]
+ #if not an_pin.startswith("AN")
+ #silent an_pin =
$adc_pins[dummy_pic][an_pin]
+ #end if
adc_pin_${an_pin}_direction = input
- #end for
+ #end for
+ #else
+ asm nop
+ #end if
#end for
end if
#end def
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---