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



________________________________
Van: [email protected] <[email protected]> namens Bill Beek 
<[email protected]>
Verzonden: zondag 20 juni 2021 21:25
Aan: jallib <[email protected]>
Onderwerp: Re: [jallib] ADC library

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.


On Saturday, June 19, 2021 at 4:55:23 PM UTC+2 Bill Beek wrote:
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

On Saturday, June 19, 2021 at 3:29:19 PM UTC+2 vasile wrote:
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


On Sat, Jun 19, 2021 at 11:36 AM Rob CJ <[email protected]> wrote:
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: [email protected] <[email protected]> namens Rob CJ 
<[email protected]>
Verzonden: zaterdag 19 juni 2021 09:22
Aan: [email protected] <[email protected]>
Onderwerp: Re: [jallib] ADC library

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: [email protected] <[email protected]> on behalf of Bill Beek 
<[email protected]>
Sent: Friday, June 18, 2021 9:26:16 PM
To: jallib <[email protected]>
Subject: Re: [jallib] ADC library

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.


On Friday, June 18, 2021 at 1:09:35 PM UTC+2 [email protected] wrote:
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: [email protected] <[email protected]> namens Bill Beek 
<[email protected]>
Verzonden: donderdag 17 juni 2021 15:56
Aan: jallib <[email protected]>
Onderwerp: [jallib] ADC library

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

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/5305520a-4b61-4eba-9e93-0c07e34786d6n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/5305520a-4b61-4eba-9e93-0c07e34786d6n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/c0832bf5-eb7f-4fe5-8090-4b7d961d17d2n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/c0832bf5-eb7f-4fe5-8090-4b7d961d17d2n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/VI1PR07MB62565FA7AB025B0D8C05EF0AE60C9%40VI1PR07MB6256.eurprd07.prod.outlook.com<https://groups.google.com/d/msgid/jallib/VI1PR07MB62565FA7AB025B0D8C05EF0AE60C9%40VI1PR07MB6256.eurprd07.prod.outlook.com?utm_medium=email&utm_source=footer>.

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/AM0PR07MB6241992EED78E63795269B35E60C9%40AM0PR07MB6241.eurprd07.prod.outlook.com<https://groups.google.com/d/msgid/jallib/AM0PR07MB6241992EED78E63795269B35E60C9%40AM0PR07MB6241.eurprd07.prod.outlook.com?utm_medium=email&utm_source=footer>.

--
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 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/4b4f4289-0eff-4a0f-812e-d5c2daff6789n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/4b4f4289-0eff-4a0f-812e-d5c2daff6789n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/AM0PR07MB62411F73344CBBF6E7FA0ADEE60A9%40AM0PR07MB6241.eurprd07.prod.outlook.com.

Reply via email to