Hi,

This is probably one for Seb (sorry!).

I'm using 18F4620 with jal 2.4n

I think I've found a bug with the adc_channels setup:
18F4620 uses fixed assignments for ADC channels (using ADCON1_PCFG)
and you can optionally change two channels (AN2&AN3) to Vref+ and
Vref- using ADCON1_VCFG.

adc_channels:
-- -----------------------------------------
-- FIRST CASE:
--  - PCFG bits exist,
--  - analog are dependent from each other
--  - Vref config is done via PCFG bits
--    combination
-- -----------------------------------------
this is not correct for the 18F4620, as Vref config is done using VCFG

further down the code loads ADC_PCFG_MAP:-

      if target_chip == PIC_18F4525 | target_chip == PIC_18F4620 then
         -- This array stores PCFG config bits, 3 by 3, for each
number of
         -- ADC channels, from 1 to the max:
         -- For each 3-tuple: (no vref, 1 vref, 2 vref)
         const byte ADC_PCFG_MAP [42] = {0b_1111, 0b_0, 0b_0, 0b_1110,
0b_0, 0b_0, 0b_1101, 0b_0,......}
         var bit*4 no_vref = 0
         var bit*4 one_vref = 0
         var bit*4 two_vref = 0

         if (ADC_NCHANNEL) == 0 then
            asm nop
         elsif (ADC_NCHANNEL) == 1 then
            pin_AN0_direction = input
         elsif (ADC_NCHANNEL) == 2 then
            pin_AN1_direction = input
            pin_AN0_direction = input
         ...
         ...
         ...
         end if

      end if

and at the end of that section:-

      -- Vref configuration via PCFG bits are directly linked to the
"if" hell just above,
      -- some variable/contant exist and are defined specifically
depending on the PICs.
      -- pin setup and vref setup can't be dissociated in the context,
this is why this
      -- Vref setup is included in pin setup procedure

      -- Retrieve config bits according to selected number of ADC
channels
      -- ADC_PCFG_MAP contains all confs, from 0 analog to the max
      if defined(ADC_DYNAMIC) == true then
         var byte idx = ADC_NCHANNEL * 3
      else
         const byte idx = ADC_NCHANNEL * 3
      end if
      if ADC_NVREF == 0 then
         no_vref = ADC_PCFG_MAP[idx]
         ADCON1_PCFG = no_vref
      elsif ADC_NVREF == 1 then
         one_vref = ADC_PCFG_MAP[idx + 1]
         ADCON1_PCFG = one_vref
      elsif ADC_NVREF == 2 then
         two_vref = ADC_PCFG_MAP[idx + 2]
         ADCON1_PCFG = two_vref
      else
         -- This is only valid when using constant, ie. not dynamic
ADC channels
         if defined(ADC_DYNAMIC) == false then
            _error "You can't have more than 2 VRef..."
         end if
      end if
   end procedure

based on the above if ADC_NCHANNEL is not equals to 0 (ie Vref
channels required) then 0b_0 will be loaded into ADCON1_PCFG (which on
the 18F4620 sets ALL anaologue channels on!) - ie ADC_PCFG_MAP values
are not correct.

a bit further down (still under "First Case"):-
   -- declare dummy procedure for normalization. Note Vref setup, due
to some jalv2 contraints
   -- (like defining a constant but assigning its definitive value
later), Vref setup is done
   -- while discovering/setting up ADC pins. See comment within
_adc_setup_pins() for dependent pins
   procedure _adc_vref() is
   end procedure

this means that you can't select Vref using VCFG.

Cheers,  Noel.

-- 
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.

Reply via email to