ADC library

33 views
Skip to first unread message

Bill Beek

unread,
Jun 17, 2021, 9:56:36 AM6/17/21
to jallib
Hello all,

When I tried to do a test with analog input on the 16F18857 I found that the library adc.jal gave 7 errors. In particular, the "adcon0_chs" was not recognized. The lib of the 16F18857 does recognize it the "adcon0_adcs" . It seems that some newer MCU's have this problem as well.  After a change of the adc lib a new error occurred,
_error "Found unsupported value for constant ADC_ADCS_BITCOUNT".
Does anyone else have experience with this event or know a solution?
Thanks, Bill

Rob CJ

unread,
Jun 18, 2021, 7:09:35 AM6/18/21
to jal...@googlegroups.com
Hi Bill,

I added an alias to cover with the difference but could not test it.

It then compiles without errors so I do not know where your other error message comes from. Can you clarify that?

I attached the updated library with the alias. Let me know if it works (or the problems you encouter).

Thanks.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Bill Beek <bill...@gmail.com>
Verzonden: donderdag 17 juni 2021 15:56
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] ADC library
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/5305520a-4b61-4eba-9e93-0c07e34786d6n%40googlegroups.com.
adc.zip

vsurducan

unread,
Jun 18, 2021, 7:40:30 AM6/18/21
to jal...@googlegroups.com
Hi Rob, Bill,
I do not think this library will work as is with this PICmicro. It's a different ADC with a lot of features.
best wishes,

Bill Beek

unread,
Jun 18, 2021, 3:26:16 PM6/18/21
to jallib
Hi Rob, Vasile
The modified adc lib of ROB gives the same result and error as mine.
The adc lib no longer gives errors but now the adc_clock lib gives 1 error, see below :

jal jalv25r5 (compiled Apr 3 2021)
generating p-code
1002 tokens, 426017 chars; 8421 lines; 11 traffic jams
generating PIC code pass 1
generating PIC code pass 2
63 branches checked, 0 errors
312 data accesses checked, 0 errors
44 skips checked, 0 errors
writing result
C:\JALLIB~2\lib/adc_clock.jal:156: "Found unsupported value for constant ADC_ADCS_BITCOUNT"
1 errors, 0 warnings

For the adc test program i use 16f876a_adc.jal from the sample programs, 
with of course the right fuses for the used 16f18857

Perhaps Vasile is right that this series of PICs needs its own library.
I also take a closer look into the problem .
Thanks for your effort.
Kinds regards Bill.

Rob CJ

unread,
Jun 19, 2021, 3:22:34 AM6/19/21
to jal...@googlegroups.com
Hi Bill,

I do not know this library but if it provides some basic functions it may be doable to make it work for other PICs too. I will see if I can make it work but I will need some time for that.

Met vriendelijke groet,
Rob Jansen

From: jal...@googlegroups.com <jal...@googlegroups.com> on behalf of Bill Beek <bill...@gmail.com>
Sent: Friday, June 18, 2021 9:26:16 PM
To: jallib <jal...@googlegroups.com>
Subject: Re: [jallib] ADC library
 

Rob CJ

unread,
Jun 19, 2021, 4:36:32 AM6/19/21
to jal...@googlegroups.com
Hi Bill,

A first analysis. The adc_clock.jal library calculates the optimal converstion time (Tad). It does this only for ADC_ADCS_BITCOUNT with values 2 and 3 but for the 16f18857 this value is 1 and so the library generates the error message.

Maybe Rob Hamerling can shine a light on this since he created that library.

In the meantime I will study it to see what this Tad is about and why a value of 1 is not (yet) supported.

Still I think it may be doable to adapt the adc libraries for the newer PICs. Once I have done that I will test it to see if it actually works.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Rob CJ <rob...@hotmail.com>
Verzonden: zaterdag 19 juni 2021 09:22
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Onderwerp: Re: [jallib] ADC library
 

Rob Hamerling

unread,
Jun 19, 2021, 8:30:44 AM6/19/21
to jal...@googlegroups.com


On 19/06/2021 10.36, Rob CJ wrote:
A first analysis. The adc_clock.jal library calculates the optimal converstion time (Tad). It does this only for ADC_ADCS_BITCOUNT with values 2 and 3 but for the 16f18857 this value is 1 and so the library generates the error message.

Maybe Rob Hamerling can shine a light on this since he created that library.


Long time ago! It has always been a primary goal in Jallib to build libraries which would work for all PICs. We succeeded in most cases, but for ADC it was by far the most challenging because of the large variations of ADC implementations between PICs. But that was about 10 years ago.  With the availability of newer PICs the variations have only become larger. But the ADC libraries haven't followed these developments, complexity being one of the main reasons, 'retirement'  of some of the developers like me another. Today I follow the Jallib developments passively at considerable distance!

A pragmatic approach for users of JalV2 users might be to forget the current ADC libraries for PICs which are apparently not supported and develop code specific for that PIC following the instructions in its datasheet. I did that myself for the 10F222....

Regards, Rob.

--
Rob Hamerling, Vianen, NL

vsurducan

unread,
Jun 19, 2021, 9:29:19 AM6/19/21
to jal...@googlegroups.com
Hi Rob,
TAD is the ADC clock period, this has a range of accepted values like on the other PIC16 and PIC18.
You can see which are those in DS40001825F at page 331.
My personal opinion seeing the struggle to maintain one common JAL ADC library over 20 years is that it is impossible.

For each PIC the user has to read the ADC datasheet.

For example the following procedure for one channel read used in PIC18F25k50 can be adapted (relatively easy) for PIC16F188577 if BASIC MODE is used (backward compatible, see page 345 and ADCON2 register at page 350)
I hope this will help. I do not have this PIC, but so far I found that simple ADC routines are better than any library.
good luck!

-- this routine works for PIC18F25k50 at 48MHz with internal reference voltage enabled, comments for PIC16F18857 adaption are below.
-- enable reference voltage
-- ------------------------------------------
VREFCON0_FVRS = 0b10  ; 0b00 FVR is off
                     ; 0b01 1x1.024V
                     ; 0b10 2x1.024V = 2.048V if VCC > 3.3V
                     ; 0b11 4x1.024V = 4.096V if VCC = 5V
VREFCON0_FVREN = on    ; fixed Vref enabled
                      ; on = enabled
                      ; off = disabled


-- read one channel of ADC
-- -------------------------
var word wADRESH
var word adc_value

procedure one_ch_ad_read ( byte in channel, bit*2 in refp, bit*2 in refn, bit in justify ) is
pragma inline
; result in ADRESH and ADRESL for each channel
; if ref external Vref+, channel1 (RA1) is not available for input,
; justify = 1 to right

   ADCON2_ADCS = 0b_110 ; fosc/64, TAD=1.3us  at 48MHz ; for PIC16F188577 replace with  ADCLK register settings
                        ; 000 = Fosc/2
                        ; 001 = Fosc/8
                        ; 010 = Fosc/32
                        ; 011 = FRC (600KHz)
                        ; 100 = Fosc/4
                        ; 101 = Fosc/16
                        ; 110 = Fosc/64
                        ; 111 = FRC (600KHz)
   ADCON2_ACQT = 0b_000 ; TAD = 0 ; for PIC16F188577 replace with ADCQ register settings
                        ; 000 = 0TAD
                        ; 001 = 2TAD
                        ; 010 = 4TAD
                        ; 011 = 6TAD
                        ; 100 = 8TAD
                        ; 101 = 12TAD
                        ; 110 = 16TAD
                        ; 111 = 20TAD
   ADCON1_PVCFG = refp  ; 00-PVCFG connected with VDD  ;  for PIC16F188577 replace this settings in ADREF register
                        ; 01-PVCFG connected externally with Vref+
                        ; 10-PVCFG connected internally with FVRBUF2
                        ; 11-reserved
   ADCON1_NVCFG = refn  ; 00-PVCFN connected with VSS
                        ; 01-PVCFN connected externally with Vref-
                        ; 10-reserved
                        ; 11-reserved
                       
                       
   ADCON2_ADFM = justify  ; 1-right(6 MSBs of ADDRESH are 0),
                          ; 0-left (6 LSBs of ADDRESL are 0)

-- for PIC16F188577 add here BASIC MODE conversion
ADMD = 0b000


   if    channel == 0 then pin_AN0_direction = input 
                           ANSELA = 0b_0000_0001                   ; for PIC16F188577  check if ANSEL registers are the same
                           ANSELB = 0            ; others digital
                           ANSELC = 0
                           ADCON0_CHS = 0b_00000 ;RA0-AN0  ; for PIC16F188577 replace the ADCON0 settings with ADPCH register
   elsif channel == 1 then pin_AN1_direction = input
                           ANSELA = 0b_0000_0010
                           ANSELB = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_00001 ;RA1-AN1
   elsif channel == 2 then pin_AN2_direction = input
                           ANSELA = 0b_0000_0100
                           ANSELB = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_00010 ;RA2-AN2
   elsif channel == 3 then pin_AN3_direction = input
                           ANSELA = 0b_0000_1000
                           ANSELB = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_00011 ;RA3-AN3
   elsif channel == 4 then pin_AN4_direction = input
                           ANSELA = 0b_0010_0000
                           ANSELB = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_00100 ;RA5-AN4
   elsif channel == 8 then pin_AN8_direction = input
                           ANSELB = 0b_0000_0100
                           ANSELA = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_01000 ;RB2-AN8
   elsif channel == 9 then pin_AN9_direction = input
                           ANSELB = 0b_0000_1000
                           ANSELA = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_01001 ;RB3-AN9
   elsif channel == 10 then pin_AN10_direction = input
                           ANSELB = 0b_0000_0010
                           ANSELA = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_01010 ;RB1-AN10
   elsif channel == 11 then pin_AN11_direction = input
                           ANSELB = 0b_0001_0000
                           ANSELA = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_01011 ;RB4-AN11
   elsif channel == 12 then pin_AN12_direction = input
                           ANSELB = 0b_0000_0001
                           ANSELA = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_01100 ;RB0-AN12
   elsif channel == 14 then pin_AN14_direction = input
                           ANSELC = 0b_0000_0100
                           ANSELA = 0
                           ANSELB = 0
                           ADCON0_CHS = 0b_01110 ;RC2-AN14
   elsif channel == 18 then pin_AN18_direction = input
                           ANSELC = 0b_0100_0000
                           ANSELA = 0
                           ANSELB = 0
                           ADCON0_CHS = 0b_10010 ;RC6-AN18
   elsif channel == 19 then pin_AN19_direction = input
                           ANSELC = 0b_1000_0000
                           ANSELA = 0
                           ANSELB = 0
                           ADCON0_CHS = 0b_10011 ;RC7-AN19
   elsif channel == 28 then
                           ANSELA = 0
                           ANSELB = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_11100 ;temperature indicator
   elsif channel == 29 then
                           ANSELA = 0
                           ANSELB = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_11101 ;CTMU charge time measurement unit
   elsif channel == 30 then
                           ANSELA = 0
                           ANSELB = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_11110 ;DAC
   elsif channel == 31 then
                           ANSELA = 0
                           ANSELB = 0
                           ANSELC = 0
                           ADCON0_CHS = 0b_11111 ;FVRBUF1 out
   end if


   ADCON0_ADON = true           ; supply the ad module
   _usec_delay ( 12 )          ; wait the sampling time min 11.5*TAD
   ADCON0_GO = true             ; start the conversion
   while ADCON0_GO loop end loop    ; wait for ad completion
 end procedure

-- read one channel of ADC
-- -------------------------
var word wADRESH
var word adc_value


forever loop
   
   one_ch_ad_read (4, 0b10, 0b00, 1) ; channel AN4 (RA5), using 2V internal Vref,  right justify

   wADRESH = ADRESH
   adc_value = 256*wADRESH + ADRESL
end loop


Bill Beek

unread,
Jun 19, 2021, 10:55:23 AM6/19/21
to jallib
Thanks to all of you, I will look in too your suggestions.
With the "ADC_ADCS_BITCOUNT" set to 2 no error occurs.
But i have to test it after the weekend.

have a nice weekend, Bill

Bill Beek

unread,
Jun 20, 2021, 3:25:43 PM6/20/21
to jallib
Hello everyone involved,
Tonight I just completed the adc test, on pin A0 and A1 everything works fine in 10 bit resolution.
I can now further test the jalpic_one board. The fact that the maximum conversion speed is not
realized is not very  important in my case.
Perhaps there is someone with good programming skills who wants to improve the adc library
Thanks again to anyone who has given suggestions.
Bill.

Rob CJ

unread,
Jun 21, 2021, 2:59:42 AM6/21/21
to jal...@googlegroups.com
Hi Bill,

That is good news and thanks for the update. I will have a ook at the library and see if I can fix the issue you mentioned.

If I figured it out, I will upload a new version and it will then be part of one of the new bee packages.

Kind regards,

Rob


Verzonden: zondag 20 juni 2021 21:25
Aan: jallib <jal...@googlegroups.com>

Rob CJ

unread,
Jun 21, 2021, 5:19:51 AM6/21/21
to jal...@googlegroups.com
Hi Bill,

I had a look at the adc library and saw that it is no longer complete so I am a bit suprised that it worked for you.

Because of issues with the ADC library in the past (and JANSEL), as already mentioned by others, I had done a small update of the adc library in the past but removed some stuff which was no longer maintainable. One of this was the setting of the input pins and the reference. What you see in the initialization routine of this library is this:

procedure adc_init() is
   if defined(ADC_DYNAMIC) == false then
      pragma inline
   end if
--RJ    _adc_setup_pins()
--RJ    _adc_vref()
   _adc_init_clock()
   _adc_init_acquisition_delay()
end procedure

And as you can see, two calls are commented out so in fact the library does not work completely since input pins and reference voltage are not set (at least not by this library).

In a previous release of JAL there was a library called adc_channels.jal which covered these functions but this library was incomplete and - almost - impossible to maintain since it was made specific for each PIC that was known at that time.

So we have two options (maybe more but these are the ones I can think off):
1) We remove the adc library
2) We add some information to the library that the user has to set the input pins and the reference voltage before using the library (which is very PIC specific).

Suggestions are welcome.

Kind regards,

Rob




Verzonden: zondag 20 juni 2021 21:25

Bill Beek

unread,
Jun 21, 2021, 10:22:40 AM6/21/21
to jallib
Hi Rob,
After your post I looked even further, I use the latest adc lib and tested the first 10 adc channels. they work all the time, and are relatively accurate. I also looked at the adc_clock lib and tried to adjust the code. The 18857 only has 1 clock selection bit "FRC or crystal controlled" , but it didn't work yet. For now, I'm happy with the result.
Here's a piece of the program I used.

const bit ADC_HIGH_RESOLUTION = true
const byte ADC_NCHANNEL = 2
const byte ADC_NVREF = ADC_NO_EXT_VREF
include adc
adc_init()
var word measure
var word voltage
var byte lowmeasure
const byte prefix[] = "Channel "
const byte highstr[] = " (high) "
const byte lowstr[] = " (low) "
const byte suffix[] = ": "
const byte value[] = "  U = "
const byte units[] = " Volts."
forever loop
   var byte channel = 0
   -- loop over all channels and read
   led = !led
   for 11 using channel loop
      -- get ADC result, high resolution
      measure = adc_read_high_res(channel)
      -- send it back through serial
      print_string(serial_hw_data,prefix)
      print_string(serial_hw_data,highstr)
      print_byte_dec(serial_hw_data,channel)
      print_string(serial_hw_data,suffix)
      -- print_word_bin(serial_hw_data,measure) ; this one works !
      print_word_dec(serial_hw_data,measure) ; I should get ~512
      voltage = measure * 0.4883  -- 5 V / 1024 * 100 (for 2 decimals)
     print_string(serial_hw_data,value)
     --print_word_dec(serial_hw_data,voltage)
     --print_string(serial_hw_data,value)
     format_word_dec(serial_hw_data,voltage,5,2) -- decimal 2 = /100
     print_string(serial_hw_data,units)
     print_crlf(serial_hw_data)
       delay_1ms(250)
      -- Even if we set high resolution, we can still access results
      -- in low resolution (the 2 LSb will be removed)
      lowmeasure = adc_read_low_res(channel)
      print_string(serial_hw_data,prefix)
      print_string(serial_hw_data,lowstr)
      print_byte_dec(serial_hw_data,channel)
      print_string(serial_hw_data,suffix)
      print_byte_dec(serial_hw_data,lowmeasure) ; I should get ~127
      print_crlf(serial_hw_data)
      -- and sleep a litte...
      --led = OFF
     delay_1ms(2500)
   end loop
end loop

Kind regards Bill.

Rob CJ

unread,
Jun 21, 2021, 11:28:14 AM6/21/21
to jal...@googlegroups.com
Hi Bill,

I looked into some more details of the library and I think understand why it works for you. Since you use the defaults of the PIC after reset and you changed ADC_ADCS_BITCOUNT to 2 the program compiles and runs but the clock selection that is calculated by the library does not work correctly for the PIC you are using.

I am not sure what the ADC clock settings are used now but it may be that your ADC now uses a clock source of fosc/2 since a clock register is set to 0 (this PIC is different from the other PICs since is uses a separate register for the clock of the ADC and that is why it has the setting of 1 instead of 2 and 3). If you are using fosc/2 then according to the datasheet you may be  using it out of spec. see table below with a clock frequency of 20 MHz.



The clock register for your PIC is defined as follows:


I was working on an update of the library but got stuck with the clock adc_clock part that calculates the Tad. 

Maybe somebody else knows what goes wrong in the code below (it always results in the warning that the clock speed is too high as if the dword 'value' is not calculated correctly). It also results in quite some rom space which I do not like.

I wonder why we would not simplify the libary and always use FRC since that is always correct according to the table  above. It would make the adc library simpler since adc_clock.jal library st no longer needed. If somebody has any idea why not to do that,  let me know.

   elsif (ADC_ADCS_BITCOUNT == 1then          -- target has separate clock selection register
      counter = 0
      done = FALSE
      ADCON0_ADCS = FALSE                       -- use ADCLK register
      repeat
         value = (2 * dword(counter + 1) * 10_000_000) / target_clock
         if value >= ADC_MIN_TAD then
            tad_word  = word(value)
            jallib_adcs = counter
            done = TRUE
         end if
         counter = counter + 1
      until done | (counter == 64)
      if !done then
         _warn "\n\tClock speed too high for Tad, internal ADC oscillator (Frc) selected"
         tad_word  = 40                        -- (approx)
         ADCON0_ADCS = TRUE                    -- use Frc
      end if 

Kind regards,

Rob


Verzonden: maandag 21 juni 2021 16:22
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] Re: ADC library
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.

vsurducan

unread,
Jun 21, 2021, 12:45:38 PM6/21/21
to jal...@googlegroups.com
Hi Rob,
Removing any library (even an incomplete one) is not a happy choice.
Perhaps the best ADC library will have one normal ADC procedure and an interrupt driven ADC procedure for each PIC clases. Since that means a lot of work, everything that already exists is better than something which does not.

There are PICs with two simultan channel sampling, others which can select each channel independently, others which only groups of channels can be selected, each using different registers for that... there are 10bit and 12bit ADCs, and so on. Using aliases to force a new PIC to meet an existing code of an old PIC family is finally restrictive. But it has the advantage that the user has a starting point for his ADC routine...which is better than nothing.
best wishes

vsurducan

unread,
Jun 21, 2021, 12:50:47 PM6/21/21
to jal...@googlegroups.com
Rob, the library does not need to compute the TAD, that was introduced first by a french jallian (i think it was Sebastien Lelong) who tried to write an universal ADC library ( and for a short time it works).
You have only to choose one of the recommended ranges. The ADC will work very well with several different clocks...
As a PIC user, performing an ADC without reading the microcontroller datasheet...and letting the library do everything for you just to be easy seems weird.
best wishes,

Rob CJ

unread,
Jun 21, 2021, 1:18:31 PM6/21/21
to jal...@googlegroups.com
Hi Vasile,

Thanks for the feedback. I agree with you that a basic ADC library is better than nothing. I think the Tad calculation is making it more beautiful but requires also more space than needed (since it calculates for different target clocks).

The basic ADC library would then only start a conversion and return the result. 

The user of the library should then take care of the following 3 items which can be mentioned in the adc.jal library and the sample program:
1) Set the correct analog input for the used channel
2) Set the correct reference voltage. I think the default is often that is used VDD as reference which works fine.
3) Set the correct AD clock (Tad) using the table in the datesheet. I think if you do not set this it will still work OK.

If we would go this way, the whole Tad calculation (adc_clock.jal) could be removed (sorry Rob Hamerling) and adc.jal could be simplified.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens vsurducan <vsur...@gmail.com>
Verzonden: maandag 21 juni 2021 18:50
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Onderwerp: Re: [jallib] Re: ADC library
 

vsurducan

unread,
Jun 22, 2021, 1:17:59 AM6/22/21
to jal...@googlegroups.com
Hi Rob, this wasn't a  request. I never used the ADC library from the jalpack even though I have read it and tried to understand it's philosophy.
But you have perfectly defined my way of working with ADC. So it's up to jal users requests and finally on your own wish.
best wishes,


Bill Beek

unread,
Jun 22, 2021, 3:15:06 PM6/22/21
to jallib
Hi Rob, I have included your piece of software in the adc_clock library library.
After I defined the variables  everything worked  properly.
Of course I have the ADC_ADCS_BITCOUNT set back to 1 in the 16F18857 lib.
The FRC clock signal is now used, which is also my preference.
As far as I'm concerned, this chapter is closed
Thanks again to all who contributed ideas and made suggestions.
 Bill.

Rob CJ

unread,
Jun 23, 2021, 3:12:03 AM6/23/21
to jal...@googlegroups.com
Hi Bill,

Thanks for the update but I have chosen a different approach to solve the problem.

Yesterday I simplified the ADC library to a basic version so that it supports more PICs and to prevent that the libary becomes too complex to support all variations of the ADC. Reason is that the library did not provide the functionality that it said it did, this because the library 'adc_channel.jal' was no longer used some time ago and so some functionality was not working because of that (like channel selection and setting the reference voltage).

This simplified version makes it more generic but as I mentioned earlier, the user has to take the following steps in de main program:
1) Set the correct analog input for the used channel(s)
2) Set the correct reference voltage. I think the default is often that is used VDD as reference which works fine in most cases.
3) Set the correct AD clock using the table in the datesheet. 

With this change I no longer include the adc_clock.jal library and  so this also works for a PIC16F18857.

I attached this version to this post and if there are no objections to this change, I need to update the adc sample programs (hmm, 26 sample files to check) and test some to see if they work for different PICs.

So @Jallib users. If you have any objections, let me know.

Kind regards,

Rob


Verzonden: dinsdag 22 juni 2021 21:15
Aan: jallib <jal...@googlegroups.com>
adc.jal

Bill Beek

unread,
Jun 25, 2021, 10:29:57 AM6/25/21
to jallib
Hi Rob,
I've tested your adc lib on several PICs so far found no problems. It concerns the following types:
16F876A, 18F2520, 18F24K50, 16F1783.
The latter only works well if AN0 is connected to GND, the other 10 analog channels then work well
with 12 bits of resolution.This also happens with the old adc lib, so I suspect something is wrong somewhere in myconfiguration, I'm still looking into that.
I will test some other types later on.

Bill.

Rob CJ

unread,
Jun 25, 2021, 11:25:33 AM6/25/21
to jal...@googlegroups.com
Hi Bill,

Thanks for the update. About the 16F1783. If you look in the datasheet it say this:

The CHS<4:0> bits of the ADCON0 register determine which positive channel is selected. 
When CHSN<3:0> = 1111 then the ADC is effectively a single ended ADC converter.

These CHSN bits seems to be something extra since not al ADC has them (CHSN<3:0> are Negative Differential Input Channel Select bits). At reset, the CHSN bits are at 0, which selects AN0. So you could try to set these bits to 1111 and see if your problem is solved (1111 = ADC Negative reference - selected by ADNREF).

Kind regards,

Rob


Verzonden: vrijdag 25 juni 2021 16:29

vsurducan

unread,
Jun 25, 2021, 12:38:50 PM6/25/21
to jal...@googlegroups.com
Hi Bill, Rob,
BTW, I don't know if you've noticed, but in all Microchip datasheet is missing the minimum value for
(Vref+) -|Vref-|. Usually they presume the user is connecting Vref- to Vss and Vref+ to Vdd or to the internal reference
(1.024V, 2.048V or 4.096V) or to a different one for external Vref+ mode).

The Vref- can be tied to a positive voltage. On old PIC16F876 supplied at 5V, I remember the (Vref+) -|Vref-| = ~2.2V.
I'm quite sure that on XLP microcontrollers supplied at minimum 1.8V this value must be much smaller.
More than that, Vref- can be tied to a negative voltage of about -0.5V ( at 0.6V the protective diodes on IO pins are conducting) without degrading the ADC linearity. Again, that value is from memory, measured on PIC16F876 supplied at 5V.

Bill, can you do please a test about these reference voltage values on 16F1783?
thx,


Bill Beek

unread,
Jun 28, 2021, 7:59:05 AM6/28/21
to jallib
Hello Rob and Vasile,
The following PICs have also been tested with Rob's adc lib. 16F886, 18F2553, 18F2580, 26K80.
No problems found so far. The 18F25K22 only worked well with the old adc lib.
With the new lib 5 volts supply voltage and reference voltage could only be measured up to 2.5 volts.
At a higher voltage, the value remained there. I'll have to investigate that too.
I have not yet looked at the 16F1783 configuration.
At 12 bits resolution the differential measurement is more suitable than single ended in my opinion,
I will look at that later. At the moment I am busy with other things for the next 4 weeks.

Bill

Rob CJ

unread,
Jun 28, 2021, 11:10:53 AM6/28/21
to jal...@googlegroups.com
Hi Bill,

Thanks for the update. Currently I made some changes to the adc library since I started modifying the sample files. I think the change has no further impact on the functionality (for some PICs I got a compile error).

While modifying the 30 ADC sample files, I will test the ones for which I have a PIC - and samples that can easily be tested - and I found out that some could never have worked so I fixed those.

It will take me some time before all sample files are modified. I can have a look at the 18F25K22 too and also create a sample file for that one (and for the 16F18857).

Once all is done I will upload the new adc.jal and all 30 adc sample files.

Kind regards,

Rob



Verzonden: maandag 28 juni 2021 13:59
Message has been deleted
Message has been deleted

Rob CJ

unread,
Jul 10, 2021, 4:36:51 PM7/10/21
to jal...@googlegroups.com
Hello all,

I simplified the ADC library because of the changes in the ADC for the newer PICs which was not supported. It is - almost - impossible to cover for all the differences. This means that the library has been simplified and the result it that some of the configuration - like selecting the analog inputs, the reference voltage selection and the ADC clock -  has to be done in the main program before the library is initialized. 

I updated all 26 ADC sample files and created two new ADC sample files (for the 16F18857 and the 18F25k22) and tested 19 of them since I did not have all hardware or PICs available. You can recognize the tested sample files by the comments where the actual output of the program is mentioned. All others are compiled but could not be re-tested. I noticed that some generated sample files did not work - and could not have worked at all - so these where fixed. All sample files are now manually maintained.

If you encounter any problems, let me know. 

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Rob CJ <rob...@hotmail.com>
Verzonden: maandag 28 juni 2021 17:10
Reply all
Reply to author
Forward
0 new messages