Revision: 1397
Author: sebastien.lelong
Date: Sat Oct 17 05:51:59 2009
Log: issue-99: improve ADC configuration feedback using some _debug
statements + raise an error in case expecting ANS bits but none found.
Which is the case in which an unsupported PIC would fall into
http://code.google.com/p/jallib/source/detail?r=1397
Modified:
/trunk/include/peripheral/adc/adc_channels.jal
/trunk/tools/adc/adc_channels.jal.tmpl
=======================================
--- /trunk/include/peripheral/adc/adc_channels.jal Fri Oct 16 13:44:30 2009
+++ /trunk/include/peripheral/adc/adc_channels.jal Sat Oct 17 05:51:59 2009
@@ -111,6 +111,8 @@
if target_chip == PIC_18F2550 | target_chip == PIC_18F4550 | target_chip
== PIC_18F4455 | target_chip == PIC_18F2455 | target_chip == PIC_18F6680 |
target_chip == PIC_18F6585 | target_chip == PIC_18F8585 | target_chip ==
PIC_18F8680 | target_chip == PIC_16F870 | target_chip == PIC_16F871 |
target_chip == PIC_16F73 | target_chip == PIC_16F74 | target_chip ==
PIC_16F77 | target_chip == PIC_16F76 | target_chip == PIC_18F4450 |
target_chip == PIC_18F2450 | target_chip == PIC_18F66J93 | target_chip ==
PIC_18F67J93 | target_chip == PIC_18F86J93 | target_chip == PIC_18F87J93 |
target_chip == PIC_16F767 | target_chip == PIC_16F737 | target_chip ==
PIC_16F747 | target_chip == PIC_16F777 | target_chip == PIC_16F72 |
target_chip == PIC_16F876A | target_chip == PIC_16F874A | target_chip ==
PIC_16F877A | target_chip == PIC_16F873A | target_chip == PIC_16F716 |
target_chip == PIC_18F4439 | target_chip == PIC_18F4539 | target_chip ==
PIC_18F2539 | target_chip == PIC_18F2439 | target_chip == PIC_16F873 |
target_chip == PIC_16F874 | target_chip == PIC_16F876 | target_chip ==
PIC_16F877 | target_chip == PIC_16F872 | target_chip == PIC_16F818 |
target_chip == PIC_16F819 then
+ _debug "ADC channels config: dependent pins, via PCFG bits"
+
-- Datasheet: 39632D
if target_chip == PIC_18F2550 | target_chip == PIC_18F2455 then
@@ -126,7 +128,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -211,7 +213,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -337,7 +339,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -458,7 +460,7 @@
pin_AN11_direction = input
pin_AN6_direction = input
elsif (ADC_NCHANNEL) == 15 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 16 then
pin_AN2_direction = input
pin_AN4_direction = input
@@ -495,7 +497,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -607,11 +609,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -646,11 +648,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -674,7 +676,7 @@
pin_AN0_direction = input
pin_AN1_direction = input
elsif (ADC_NCHANNEL) == 7 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 8 then
pin_AN7_direction = input
pin_AN5_direction = input
@@ -705,17 +707,17 @@
var bit*3 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN1_direction = input
pin_AN3_direction = input
elsif (ADC_NCHANNEL) == 4 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 5 then
pin_AN4_direction = input
pin_AN2_direction = input
@@ -741,17 +743,17 @@
var bit*3 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN1_direction = input
pin_AN3_direction = input
elsif (ADC_NCHANNEL) == 4 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 5 then
pin_AN4_direction = input
pin_AN2_direction = input
@@ -759,9 +761,9 @@
pin_AN1_direction = input
pin_AN3_direction = input
elsif (ADC_NCHANNEL) == 6 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 7 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 8 then
pin_AN7_direction = input
pin_AN5_direction = input
@@ -792,7 +794,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -904,7 +906,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -1043,7 +1045,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -1142,17 +1144,17 @@
var bit*3 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN1_direction = input
pin_AN3_direction = input
elsif (ADC_NCHANNEL) == 4 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 5 then
pin_AN4_direction = input
pin_AN2_direction = input
@@ -1180,11 +1182,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -1219,11 +1221,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -1247,7 +1249,7 @@
pin_AN0_direction = input
pin_AN1_direction = input
elsif (ADC_NCHANNEL) == 7 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 8 then
pin_AN7_direction = input
pin_AN5_direction = input
@@ -1278,11 +1280,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -1317,11 +1319,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -1345,7 +1347,7 @@
pin_AN0_direction = input
pin_AN5_direction = input
elsif (ADC_NCHANNEL) == 7 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 8 then
pin_AN4_direction = input
pin_AN1_direction = input
@@ -1376,11 +1378,11 @@
var bit*3 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN1_direction = input
@@ -1411,11 +1413,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -1450,11 +1452,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -1478,7 +1480,7 @@
pin_AN0_direction = input
pin_AN5_direction = input
elsif (ADC_NCHANNEL) == 7 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 8 then
pin_AN4_direction = input
pin_AN1_direction = input
@@ -1509,7 +1511,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -1594,7 +1596,7 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
@@ -1720,11 +1722,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -1761,11 +1763,11 @@
var bit*4 two_vref = 0
if (ADC_NCHANNEL) == 0 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 1 then
pin_AN0_direction = input
elsif (ADC_NCHANNEL) == 2 then
- asm nop
+ asm nop
elsif (ADC_NCHANNEL) == 3 then
pin_AN0_direction = input
pin_AN2_direction = input
@@ -1816,6 +1818,8 @@
elsif target_cpu == PIC_16 & (defined(ANCON0_PCFG0) |
defined(ANCON0_PCFG1) | defined(ANCON0_PCFG2) | defined(ANCON0_PCFG3) |
defined(ANCON0_PCFG4) | defined(ANCON0_PCFG5) | defined(ANCON0_PCFG6) |
defined(ANCON0_PCFG7) | defined(ANCON1_PCFG10) | defined(ANCON1_PCFG11) |
defined(ANCON1_PCFG12) | defined(ANCON1_PCFG8) | defined(ANCON1_PCFG9)) then
+ _debug "ADC channels config: independent pins, via PCFG bits"
+
-- Selecting the number of ADC channels is done using PCFG bits
-- User can optionally specify ADC channels number
if defined(ADC_NCHANNEL) == true then
@@ -2064,6 +2068,7 @@
-- --------------------------------------------
else
+ _debug "ADC channels config: independent pins, via ANS bits"
-- Selecting the number of ADC channels is done using ANS bits
-- There are many different cases where ANS bits can be found
-- - bit*2 ADCON0_ANS
@@ -2098,98 +2103,98 @@
if target_chip == PIC_16F722 | target_chip == PIC_16F723 | target_chip
== PIC_16F724 | target_chip == PIC_16F726 | target_chip == PIC_16F727 |
target_chip == PIC_16LF722 | target_chip == PIC_16LF723 |
target_chip == PIC_16LF724 | target_chip == PIC_16LF726 | target_chip ==
PIC_16LF727 then
- alias ADC_JANSEL_ANS0 is JANSEL_ANS0
- alias ADC_JANSEL_ANS1 is JANSEL_ANS1
- alias ADC_JANSEL_ANS2 is JANSEL_ANS2
- alias ADC_JANSEL_ANS3 is JANSEL_ANS3
- alias ADC_JANSEL_ANS4 is JANSEL_ANS5
- alias ADC_JANSEL_ANS12 is JANSEL_ANS6
- alias ADC_JANSEL_ANS10 is JANSEL_ANS7
- alias ADC_JANSEL_ANS8 is JANSEL_ANS8
- alias ADC_JANSEL_ANS9 is JANSEL_ANS9
- alias ADC_JANSEL_ANS11 is JANSEL_ANS10
- alias ADC_JANSEL_ANS13 is JANSEL_ANS11
+ alias ADC_JANSEL_ANS0 is JANSEL_ANS0
+ alias ADC_JANSEL_ANS1 is JANSEL_ANS1
+ alias ADC_JANSEL_ANS2 is JANSEL_ANS2
+ alias ADC_JANSEL_ANS3 is JANSEL_ANS3
+ alias ADC_JANSEL_ANS4 is JANSEL_ANS5
+ alias ADC_JANSEL_ANS12 is JANSEL_ANS6
+ alias ADC_JANSEL_ANS10 is JANSEL_ANS7
+ alias ADC_JANSEL_ANS8 is JANSEL_ANS8
+ alias ADC_JANSEL_ANS9 is JANSEL_ANS9
+ alias ADC_JANSEL_ANS11 is JANSEL_ANS10
+ alias ADC_JANSEL_ANS13 is JANSEL_ANS11
- if target_chip == PIC_16F724 | target_chip == PIC_16F727 |
target_chip
== PIC_16LF724 | target_chip == PIC_16LF727 then
- alias ADC_JANSEL_ANS5 is JANSEL_ANS20
- alias ADC_JANSEL_ANS6 is JANSEL_ANS21
- alias ADC_JANSEL_ANS7 is JANSEL_ANS22
- end if
+ if target_chip == PIC_16F724 | target_chip == PIC_16F727 |
target_chip == PIC_16LF724 | target_chip == PIC_16LF727 then
+ alias ADC_JANSEL_ANS5 is JANSEL_ANS20
+ alias ADC_JANSEL_ANS6 is JANSEL_ANS21
+ alias ADC_JANSEL_ANS7 is JANSEL_ANS22
+ end if
else
- -- no exception here: ANSx corresponds to analog pin n°x
- if defined(JANSEL_ANS0) == true then
- alias ADC_JANSEL_ANS0 is JANSEL_ANS0
- end if
- if defined(JANSEL_ANS1) == true then
- alias ADC_JANSEL_ANS1 is JANSEL_ANS1
- end if
- if defined(JANSEL_ANS2) == true then
- alias ADC_JANSEL_ANS2 is JANSEL_ANS2
- end if
- if defined(JANSEL_ANS3) == true then
- alias ADC_JANSEL_ANS3 is JANSEL_ANS3
- end if
- if defined(JANSEL_ANS4) == true then
- alias ADC_JANSEL_ANS4 is JANSEL_ANS4
- end if
- if defined(JANSEL_ANS5) == true then
- alias ADC_JANSEL_ANS5 is JANSEL_ANS5
- end if
- if defined(JANSEL_ANS6) == true then
- alias ADC_JANSEL_ANS6 is JANSEL_ANS6
- end if
- if defined(JANSEL_ANS7) == true then
- alias ADC_JANSEL_ANS7 is JANSEL_ANS7
- end if
- if defined(JANSEL_ANS8) == true then
- alias ADC_JANSEL_ANS8 is JANSEL_ANS8
- end if
- if defined(JANSEL_ANS9) == true then
- alias ADC_JANSEL_ANS9 is JANSEL_ANS9
- end if
- if defined(JANSEL_ANS10) == true then
- alias ADC_JANSEL_ANS10 is JANSEL_ANS10
- end if
- if defined(JANSEL_ANS11) == true then
- alias ADC_JANSEL_ANS11 is JANSEL_ANS11
- end if
- if defined(JANSEL_ANS12) == true then
- alias ADC_JANSEL_ANS12 is JANSEL_ANS12
- end if
- if defined(JANSEL_ANS13) == true then
- alias ADC_JANSEL_ANS13 is JANSEL_ANS13
- end if
- if defined(JANSEL_ANS14) == true then
- alias ADC_JANSEL_ANS14 is JANSEL_ANS14
- end if
- if defined(JANSEL_ANS15) == true then
- alias ADC_JANSEL_ANS15 is JANSEL_ANS15
- end if
- if defined(JANSEL_ANS16) == true then
- alias ADC_JANSEL_ANS16 is JANSEL_ANS16
- end if
- if defined(JANSEL_ANS17) == true then
- alias ADC_JANSEL_ANS17 is JANSEL_ANS17
- end if
- if defined(JANSEL_ANS18) == true then
- alias ADC_JANSEL_ANS18 is JANSEL_ANS18
- end if
- if defined(JANSEL_ANS19) == true then
- alias ADC_JANSEL_ANS19 is JANSEL_ANS19
- end if
- if defined(JANSEL_ANS20) == true then
- alias ADC_JANSEL_ANS20 is JANSEL_ANS20
- end if
- if defined(JANSEL_ANS21) == true then
- alias ADC_JANSEL_ANS21 is JANSEL_ANS21
- end if
- if defined(JANSEL_ANS22) == true then
- alias ADC_JANSEL_ANS22 is JANSEL_ANS22
- end if
+ -- no exception here: ANSx corresponds to analog pin n°x
+ if defined(JANSEL_ANS0) == true then
+ alias ADC_JANSEL_ANS0 is JANSEL_ANS0
+ end if
+ if defined(JANSEL_ANS1) == true then
+ alias ADC_JANSEL_ANS1 is JANSEL_ANS1
+ end if
+ if defined(JANSEL_ANS2) == true then
+ alias ADC_JANSEL_ANS2 is JANSEL_ANS2
+ end if
+ if defined(JANSEL_ANS3) == true then
+ alias ADC_JANSEL_ANS3 is JANSEL_ANS3
+ end if
+ if defined(JANSEL_ANS4) == true then
+ alias ADC_JANSEL_ANS4 is JANSEL_ANS4
+ end if
+ if defined(JANSEL_ANS5) == true then
+ alias ADC_JANSEL_ANS5 is JANSEL_ANS5
+ end if
+ if defined(JANSEL_ANS6) == true then
+ alias ADC_JANSEL_ANS6 is JANSEL_ANS6
+ end if
+ if defined(JANSEL_ANS7) == true then
+ alias ADC_JANSEL_ANS7 is JANSEL_ANS7
+ end if
+ if defined(JANSEL_ANS8) == true then
+ alias ADC_JANSEL_ANS8 is JANSEL_ANS8
+ end if
+ if defined(JANSEL_ANS9) == true then
+ alias ADC_JANSEL_ANS9 is JANSEL_ANS9
+ end if
+ if defined(JANSEL_ANS10) == true then
+ alias ADC_JANSEL_ANS10 is JANSEL_ANS10
+ end if
+ if defined(JANSEL_ANS11) == true then
+ alias ADC_JANSEL_ANS11 is JANSEL_ANS11
+ end if
+ if defined(JANSEL_ANS12) == true then
+ alias ADC_JANSEL_ANS12 is JANSEL_ANS12
+ end if
+ if defined(JANSEL_ANS13) == true then
+ alias ADC_JANSEL_ANS13 is JANSEL_ANS13
+ end if
+ if defined(JANSEL_ANS14) == true then
+ alias ADC_JANSEL_ANS14 is JANSEL_ANS14
+ end if
+ if defined(JANSEL_ANS15) == true then
+ alias ADC_JANSEL_ANS15 is JANSEL_ANS15
+ end if
+ if defined(JANSEL_ANS16) == true then
+ alias ADC_JANSEL_ANS16 is JANSEL_ANS16
+ end if
+ if defined(JANSEL_ANS17) == true then
+ alias ADC_JANSEL_ANS17 is JANSEL_ANS17
+ end if
+ if defined(JANSEL_ANS18) == true then
+ alias ADC_JANSEL_ANS18 is JANSEL_ANS18
+ end if
+ if defined(JANSEL_ANS19) == true then
+ alias ADC_JANSEL_ANS19 is JANSEL_ANS19
+ end if
+ if defined(JANSEL_ANS20) == true then
+ alias ADC_JANSEL_ANS20 is JANSEL_ANS20
+ end if
+ if defined(JANSEL_ANS21) == true then
+ alias ADC_JANSEL_ANS21 is JANSEL_ANS21
+ end if
+ if defined(JANSEL_ANS22) == true then
+ alias ADC_JANSEL_ANS22 is JANSEL_ANS22
+ end if
end if
-- Configure a pin to act as an analog pin.
@@ -2338,6 +2343,9 @@
pin_AN22_direction = input
end if
end if
+ if defined(ADC_JANSEL_ANS0) == false & defined(ADC_JANSEL_ANS1) ==
false & defined(ADC_JANSEL_ANS2) == false & defined(ADC_JANSEL_ANS3) ==
false & defined(ADC_JANSEL_ANS4) == false & defined(ADC_JANSEL_ANS5) ==
false & defined(ADC_JANSEL_ANS6) == false & defined(ADC_JANSEL_ANS7) ==
false & defined(ADC_JANSEL_ANS8) == false & defined(ADC_JANSEL_ANS9) ==
false & defined(ADC_JANSEL_ANS10) == false & defined(ADC_JANSEL_ANS11) ==
false & defined(ADC_JANSEL_ANS12) == false & defined(ADC_JANSEL_ANS13) ==
false & defined(ADC_JANSEL_ANS14) == false & defined(ADC_JANSEL_ANS15) ==
false & defined(ADC_JANSEL_ANS16) == false & defined(ADC_JANSEL_ANS17) ==
false & defined(ADC_JANSEL_ANS18) == false & defined(ADC_JANSEL_ANS19) ==
false & defined(ADC_JANSEL_ANS20) == false & defined(ADC_JANSEL_ANS21) ==
false & defined(ADC_JANSEL_ANS22) == false then
+ _error "\n\tUnable to configure ADC channels.\n\tConfiguration is
supposed to be done using ANS bits\n\tbut it seems there's no ANS bits for
this PIC.\n\tMaybe your PIC isn't supported, please report !"
+ end if
end procedure
-- Configure a pin to act as an digital pin.
=======================================
--- /trunk/tools/adc/adc_channels.jal.tmpl Sun Aug 9 01:29:38 2009
+++ /trunk/tools/adc/adc_channels.jal.tmpl Sat Oct 17 05:51:59 2009
@@ -36,69 +36,69 @@
#def analyze_config(bits,dpins,mapping)
- #set analog = [d for d in dpins.items() if d[1] == 'A']
- #set vrefs = [d for d in dpins.items() if d[1].startswith('VREF')]
- #set num_a = len(analog)
- #set num_vref = len(vrefs)
- ## There can be "anything" bits...
- #silent bits = bits.replace("x","0")
- ## Mapping for 0, 1 or 2 VREF
- #silent mapping.setdefault(num_a + num_vref,{0 : '0', 1 : '0',
2 : '0', 'analog_pins' : []})[num_vref] = bits
- #silent mapping[num_a + num_vref]['analog_pins'] = analog + vrefs
- #return "const bit*%d ADC_PCFG_%sANA_%sREF = 0b_%s" %
(len(bits),num_a,num_vref,bits)
+ #set analog = [d for d in dpins.items() if d[1] == 'A']
+ #set vrefs = [d for d in dpins.items() if d[1].startswith('VREF')]
+ #set num_a = len(analog)
+ #set num_vref = len(vrefs)
+ ## There can be "anything" bits...
+ #silent bits = bits.replace("x","0")
+ ## Mapping for 0, 1 or 2 VREF
+ #silent mapping.setdefault(num_a + num_vref,{0 : '0', 1 : '0',
2 : '0', 'analog_pins' : []})[num_vref] = bits
+ #silent mapping[num_a + num_vref]['analog_pins'] = analog + vrefs
+ #return "const bit*%d ADC_PCFG_%sANA_%sREF = 0b_%s" %
(len(bits),num_a,num_vref,bits)
#end def
#def parse_analog_pin(strpin)
- #if "/" in strpin
- #return strpin.split("/")[0]
- #else
- #return strpin
- #end if
+ #if "/" in strpin
+ #return strpin.split("/")[0]
+ #else
+ #return strpin
+ #end if
#end def
#def pcfg_conf(dsref,pics)
- #set confs = copy.deepcopy($adc_pcfg[$dsref])
- ## clean/remove some pins when not available in given PICs
- ## (given PICs all have the same pins, but the confs/combination
- ## may be a merge for different PICs. Ex: 16F77 has RE pins, not 16F76)
- #set dummy_pic = $pics[-1]
- #set availpins = $adc_pins[dummy_pic]
- #for conf,dpins in confs.items():
- #for pin in dpins.keys()
- #set an_pin = $parse_analog_pin(pin)
- ## search by digital and analog names
- #if not an_pin in availpins.keys() and not an_pin in
availpins.values()
- #silent dpins.pop(pin)
- #end if
- #end for
- #end for
-
- #set mapping = dict()
+ #set confs = copy.deepcopy($adc_pcfg[$dsref])
+ ## clean/remove some pins when not available in given PICs
+ ## (given PICs all have the same pins, but the confs/combination
+ ## may be a merge for different PICs. Ex: 16F77 has RE pins, not
16F76)
+ #set dummy_pic = $pics[-1]
+ #set availpins = $adc_pins[dummy_pic]
+ #for conf,dpins in confs.items():
+ #for pin in dpins.keys()
+ #set an_pin = $parse_analog_pin(pin)
+ ## search by digital and analog names
+ #if not an_pin in availpins.keys() and not an_pin in
availpins.values()
+ #silent dpins.pop(pin)
+ #end if
+ #end for
+ #end for
+
+ #set mapping = dict()
##-- These are some constants similar to what can be found in
MCC18 adc.h header file
- #for bits,dpins in confs.items()
- #set r = $analyze_config(bits,dpins,mapping)
- ## remove generation of constants, as there can be duplicate,
and
- ## since they're used and since I'm not lazy for now to fix
these dups
- ## I prefer "silent" this !
- ## Please forgive me...
+ #for bits,dpins in confs.items()
+ #set r = $analyze_config(bits,dpins,mapping)
+ ## remove generation of constants, as there can be duplicate, and
+ ## since they're used and since I'm not lazy for now to fix these
dups
+ ## I prefer "silent" this !
+ ## Please forgive me...
##$r
- #end for
- ## mapping contains only valid/existing config, but these aren't
continue:
- ## we can have 1 ANA, then 3 ANA, but no 2 ANA config.
- ## We need to have "padding" configs, because these aren going to be put
- ## in a array, and accessed by ADC_NCHANNEL/ADC_NVREF
- #set tmpmap = dict().fromkeys(range(0,max(mapping.keys()) + 1))
- #for k,v in tmpmap.items()
- #if not k in mapping
- #silent mapping[k] = {0 : '0', 1 : '0', 2 : '0',
'analog_pins' : []}
- #end if
- #end for
- #set smap = sorted(mapping.items())
- #set lmap = []
- #silent
[(lmap.append(m[1][0]),lmap.append(m[1][1]),lmap.append(m[1][2]))
for m in smap]
- #set lenlmap = str(len(lmap))
- #set lenbits = str(len(bits))
- #set map = "const byte ADC_PCFG_MAP [" + lenlmap + "] = {0b_" + ",
0b_".join(lmap) + "}"
+ #end for
+ ## mapping contains only valid/existing config, but these aren't
continue:
+ ## we can have 1 ANA, then 3 ANA, but no 2 ANA config.
+ ## We need to have "padding" configs, because these aren going to be
put
+ ## in a array, and accessed by ADC_NCHANNEL/ADC_NVREF
+ #set tmpmap = dict().fromkeys(range(0,max(mapping.keys()) + 1))
+ #for k,v in tmpmap.items()
+ #if not k in mapping
+ #silent mapping[k] = {0 : '0', 1 : '0',
2 : '0', 'analog_pins' : []}
+ #end if
+ #end for
+ #set smap = sorted(mapping.items())
+ #set lmap = []
+ #silent
[(lmap.append(m[1][0]),lmap.append(m[1][1]),lmap.append(m[1][2])) for m in
smap]
+ #set lenlmap = str(len(lmap))
+ #set lenbits = str(len(bits))
+ #set map = "const byte ADC_PCFG_MAP [" + lenlmap + "] = {0b_" + ",
0b_".join(lmap) + "}"
-- This array stores PCFG config bits, 3 by 3, for each number of
-- ADC channels, from 1 to the max:
@@ -108,58 +108,58 @@
var bit*$lenbits one_vref = 0
var bit*$lenbits two_vref = 0
- ## Generate procedure to access combinations
+ ## Generate procedure to access combinations
#for i,(numch,dconf) in enumerate(smap)
- #if i == 0
+ #if i == 0
if (ADC_NCHANNEL) == $numch then
- #else
+ #else
elsif (ADC_NCHANNEL) == $numch then
- #end if
- #if dconf['analog_pins']
- #for strpin in dconf['analog_pins']:
- ## pin can looks like "AN0" or a couple like
"AN0/RA0"
- #set an_pin = $parse_analog_pin(strpin[0])
- ## check pin exists in this pic (there can be
multiple PIC in the
- ## same datasheets, but with different analog
pins, and the same
- ## PCFG combinations, exceptions (eg. "RE1 pin
only exist for 16F77")
- #if an_pin.startswith("AN")
- #if not an_pin in
$adc_pins[dummy_pic].values()
- #continue
- #end if
- #else
- #if not an_pin in
$adc_pins[dummy_pic].keys()
- #continue
- #end if
- #end if
- #if not an_pin.startswith("AN")
- #silent an_pin =
$adc_pins[dummy_pic][an_pin]
- #end if
+ #end if
+ #if dconf['analog_pins']
+ #for strpin in dconf['analog_pins']:
+ ## pin can looks like "AN0" or a couple like "AN0/RA0"
+ #set an_pin = $parse_analog_pin(strpin[0])
+ ## check pin exists in this pic (there can be multiple PIC
in the
+ ## same datasheets, but with different analog pins, and
the same
+ ## PCFG combinations, exceptions (eg. "RE1 pin only exist
for 16F77")
+ #if an_pin.startswith("AN")
+ #if not an_pin in $adc_pins[dummy_pic].values()
+ #continue
+ #end if
+ #else
+ #if not an_pin in $adc_pins[dummy_pic].keys()
+ #continue
+ #end if
+ #end if
+ #if not an_pin.startswith("AN")
+ #silent an_pin = $adc_pins[dummy_pic][an_pin]
+ #end if
pin_${an_pin}_direction = input
- #end for
- #else
- asm nop
- #end if
- #end for
+ #end for
+ #else
+ asm nop
+ #end if
+ #end for
end if
#end def
#def pcfg_combination
- #set bydsref = {}
- #silent [bydsref.setdefault($pic_ds[p],[]).append(p) for p in
$pcfg_combination_pics]
- #for dsref, pics in bydsref.items()
- ## Even if PICs are in the same datasheets, there can be
differences
- ## regarding the number of
- #set pics = $ds_pic[dsref]
- #set pingrps = {}
- #for p in pics
- #silent
pingrps.setdefault(tuple($adc_pins[p]),[]).append(p)
- #end for
-
- #for pins,picsgrp in pingrps.items()
- #set condition = " | ".join(map(lambda x: "target_chip
== PIC_%s" %
x.upper(),picsgrp))
- #set ds_refs = list(set([$pic_ds[p] for p in picsgrp]))
- #assert len(ds_refs) == 1
+ #set bydsref = {}
+ #silent [bydsref.setdefault($pic_ds[p],[]).append(p) for p in
$pcfg_combination_pics]
+ #for dsref, pics in bydsref.items()
+ ## Even if PICs are in the same datasheets, there can be
differences
+ ## regarding the number of
+ #set pics = $ds_pic[dsref]
+ #set pingrps = {}
+ #for p in pics
+ #silent pingrps.setdefault(tuple($adc_pins[p]),[]).append(p)
+ #end for
+
+ #for pins,picsgrp in pingrps.items()
+ #set condition = " | ".join(map(lambda x: "target_chip ==
PIC_%s" % x.upper(),picsgrp))
+ #set ds_refs = list(set([$pic_ds[p] for p in picsgrp]))
+ #assert len(ds_refs) == 1
-- Datasheet: $ds_refs[0]
if $condition then
@@ -167,9 +167,9 @@
$pcfg_conf($dsref,$picsgrp)
end if
- #end for
-
- #end for
+ #end for
+
+ #end for
-- Retrieve config bits according to selected number of ADC channels
-- ADC_PCFG_MAP contains all confs, from 0 analog to the max
@@ -191,19 +191,19 @@
#end def
#def pcfg_18f
- ## PCFG0 in ANCON0
- ## PCFG1 in ANCON0
- ## PCFG2 in ANCON0
- ## PCFG3 in ANCON0
- ## PCFG4 in ANCON0
- ## PCFG5 in ANCON0
- ## PCFG6 in ANCON0
- ## PCFG7 in ANCON0
- ## PCFG8 in ANCON1
- ## PCFG9 in ANCON1
- ## PCFG10 in ANCON1
- ## PCFG11 in ANCON1
- ## PCFG12 in ANCON1
+ ## PCFG0 in ANCON0
+ ## PCFG1 in ANCON0
+ ## PCFG2 in ANCON0
+ ## PCFG3 in ANCON0
+ ## PCFG4 in ANCON0
+ ## PCFG5 in ANCON0
+ ## PCFG6 in ANCON0
+ ## PCFG7 in ANCON0
+ ## PCFG8 in ANCON1
+ ## PCFG9 in ANCON1
+ ## PCFG10 in ANCON1
+ ## PCFG11 in ANCON1
+ ## PCFG12 in ANCON1
-- Selecting the number of ADC channels is done using PCFG bits
-- User can optionally specify ADC channels number
@@ -474,36 +474,36 @@
if target_chip == PIC_16F722 | target_chip == PIC_16F723 | target_chip
== PIC_16F724 | target_chip == PIC_16F726 | target_chip == PIC_16F727 |
target_chip == PIC_16LF722 | target_chip == PIC_16LF723 |
target_chip == PIC_16LF724 | target_chip == PIC_16LF726 | target_chip ==
PIC_16LF727 then
- ## always exists in all 16F72X family
- alias ADC_JANSEL_ANS0 is JANSEL_ANS0
- alias ADC_JANSEL_ANS1 is JANSEL_ANS1
- alias ADC_JANSEL_ANS2 is JANSEL_ANS2
- alias ADC_JANSEL_ANS3 is JANSEL_ANS3
- alias ADC_JANSEL_ANS4 is JANSEL_ANS5
- alias ADC_JANSEL_ANS12 is JANSEL_ANS6
- alias ADC_JANSEL_ANS10 is JANSEL_ANS7
- alias ADC_JANSEL_ANS8 is JANSEL_ANS8
- alias ADC_JANSEL_ANS9 is JANSEL_ANS9
- alias ADC_JANSEL_ANS11 is JANSEL_ANS10
- alias ADC_JANSEL_ANS13 is JANSEL_ANS11
+ ## always exists in all 16F72X family
+ alias ADC_JANSEL_ANS0 is JANSEL_ANS0
+ alias ADC_JANSEL_ANS1 is JANSEL_ANS1
+ alias ADC_JANSEL_ANS2 is JANSEL_ANS2
+ alias ADC_JANSEL_ANS3 is JANSEL_ANS3
+ alias ADC_JANSEL_ANS4 is JANSEL_ANS5
+ alias ADC_JANSEL_ANS12 is JANSEL_ANS6
+ alias ADC_JANSEL_ANS10 is JANSEL_ANS7
+ alias ADC_JANSEL_ANS8 is JANSEL_ANS8
+ alias ADC_JANSEL_ANS9 is JANSEL_ANS9
+ alias ADC_JANSEL_ANS11 is JANSEL_ANS10
+ alias ADC_JANSEL_ANS13 is JANSEL_ANS11
- ## only for these
- if target_chip == PIC_16F724 | target_chip == PIC_16F727 |
target_chip
== PIC_16LF724 | target_chip == PIC_16LF727 then
- alias ADC_JANSEL_ANS5 is JANSEL_ANS20
- alias ADC_JANSEL_ANS6 is JANSEL_ANS21
- alias ADC_JANSEL_ANS7 is JANSEL_ANS22
- end if
+ ## only for these
+ if target_chip == PIC_16F724 | target_chip == PIC_16F727 |
target_chip == PIC_16LF724 | target_chip == PIC_16LF727 then
+ alias ADC_JANSEL_ANS5 is JANSEL_ANS20
+ alias ADC_JANSEL_ANS6 is JANSEL_ANS21
+ alias ADC_JANSEL_ANS7 is JANSEL_ANS22
+ end if
else
- -- no exception here: ANSx corresponds to analog pin n°x
+ -- no exception here: ANSx corresponds to analog pin n°x
#for i in range(23)
- if defined(JANSEL_ANS$i) == true then
- alias ADC_JANSEL_ANS$i is JANSEL_ANS$i
- end if
- #end for
+ if defined(JANSEL_ANS$i) == true then
+ alias ADC_JANSEL_ANS$i is JANSEL_ANS$i
+ end if
+ #end for
end if
-- Configure a pin to act as an analog pin.
@@ -514,6 +514,7 @@
-- one named AN12, if any
-- - set_analog_pin(4) will do the same for AN4
procedure set_analog_pin(byte in an_pin_num) is
+ #set conds = []
#for i in range(23)
if defined(ADC_JANSEL_ANS$i) == true then
if an_pin_num == $i then
@@ -521,7 +522,12 @@
pin_AN${i}_direction = input
end if
end if
+ #silent conds.append("defined(ADC_JANSEL_ANS%s) == false" % $i)
#end for
+ #set finalcond = " & ".join(conds)
+ if $finalcond then
+ _error "\n\tUnable to configure ADC channels.\n\tConfiguration is
supposed to be done using ANS bits\n\tbut it seems there's no ANS bits for
this PIC.\n\tMaybe your PIC isn't supported, please report !"
+ end if
end procedure
-- Configure a pin to act as an digital pin.
@@ -663,6 +669,8 @@
## Check PICs which use PCFG bits as combinations
if $pcfg_combination_condition then
+
+ _debug "ADC channels config: dependent pins, via PCFG bits"
$pcfg_combination
@@ -675,6 +683,8 @@
## 18F PICs, which use PCFG bits
elsif target_cpu == PIC_16 & (defined(ANCON0_PCFG0) |
defined(ANCON0_PCFG1) | defined(ANCON0_PCFG2) | defined(ANCON0_PCFG3) |
defined(ANCON0_PCFG4) | defined(ANCON0_PCFG5) | defined(ANCON0_PCFG6) |
defined(ANCON0_PCFG7) | defined(ANCON1_PCFG10) | defined(ANCON1_PCFG11) |
defined(ANCON1_PCFG12) | defined(ANCON1_PCFG8) | defined(ANCON1_PCFG9)) then
+
+ _debug "ADC channels config: independent pins, via PCFG bits"
$pcfg_18f
$select_vref
@@ -688,6 +698,7 @@
## So these are PICs which use ANS bits, wether non-18F or 18F
else
+ _debug "ADC channels config: independent pins, via ANS bits"
$ans
$select_vref
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---