Hi Rob,
If I replace the ADRESH and ADRESL content with fixed values, it looks like
computation is ok, however this is not the real situation when reading ADC.
How can a computing error be reported after compilation time?
It seems _ERROR or _WARN  does not work... Like this:

if (voltage1 <= 490) |  (voltage1 >= 510) then
 _ERROR "average computing error"  ; this error to be reported after
compilation, but only if it's true.
end if

On the other hand I'm using interrupts in usb_serial for debugging and
STATUS and FSR0L are also used...

;  243    voltage1 = voltage1 + voltage1_a[i]
                               bcf      v__status, v__c,v__access
                               rlcf     v___i_2,w,v__banked
                               movwf    v____temp_66,v__banked
                               lfsr     0,v_voltage1_a
                               movf     v____temp_66,w,v__banked
                               addwf    v__fsr0l,f,v__access
                               movf     v__ind,w,v__access
                               movwf    v__pic_temp,v__access
                               incf     v__fsr0l,f,v__access
                               movf     v__ind,w,v__access
                               movwf    v__pic_temp+1,v__access
                               movf     v__pic_temp,w,v__access
                               addwf    v_voltage1,f,v__banked
                               movf     v__pic_temp+1,w,v__access
                               addwfc   v_voltage1+1,f,v__banked

On Thu, Nov 11, 2021 at 8:07 PM Rob CJ <[email protected]> wrote:

> Hi Vasile,
>
> Strange that this does not work.
>
> Did you try to isolate the problem to a minimum program without using
> special - other - procedures so that it can easily be reproduced by anybody
> that does not have the library you are using?
>
> That would make it easier to find the root cause.
>
> Thanks.
>
> Kind regards,
>
> Rob
>
> ------------------------------
> *Van:* [email protected] <[email protected]> namens vsurducan
> <[email protected]>
> *Verzonden:* donderdag 11 november 2021 13:47
> *Aan:* [email protected] <[email protected]>
> *Onderwerp:* [jallib] adc average
>
> Hi all ( aka Kiste and Rob&Rob ?) :)
>
> One possible solution to take 8 adc average values is below (and does not
> work):
>
> const sample_nr  = 8  ; buffer size dimension
> var word voltage1_a[sample_nr] ; sample array
> var word one_ch_ad_read
> var word voltage1 = 0 ; the average value we need
> const word c256 = 256
>
> var byte i
>   for 8 using i loop
>    one_ch_ad_read (0, 0b10, 0b00, 1) ; read adc procedure
>    ch0_adc_value = c256*ADRESH + ADRESL ; compute result
>    voltage1_a [i] = ch0_adc_value ; store sample
>    voltage1 = voltage1 + voltage1_a[i] ; do a sum of all samples each i
> step
>   end loop
>
>    voltage1 = voltage1 >> 3  ; divide by 8 and get the adc average
>
> The issue is at the line:
> voltage1 = voltage1 + voltage1_a[i] ;
> initially voltage1 = 0
> for i=0  voltage1 = 0 + voltage1_a[0]
> for i=1 voltage1 = voltage1 (i=0) + voltage1_a[1] ...etc
> this is not working as presumed...
>
> If I remove this line from for...loop...end loop and write as:
> voltage1 = voltage1_a [0] + voltage1_a [1] + voltage1_a [2] + voltage1_a
> [3]
>             + voltage1_a [4] + voltage1_a [5] + voltage1_a [6] +
> voltage1_a [7]
>
> then everything is ok.
>
> The question is: why it does not work?
> thx
>
> --
> 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/CAM%2Bj4qttXVSgPyqqUetP_HaKEH01xZoSXXmG%2BD73jKOHh2Ub9g%40mail.gmail.com
> <https://groups.google.com/d/msgid/jallib/CAM%2Bj4qttXVSgPyqqUetP_HaKEH01xZoSXXmG%2BD73jKOHh2Ub9g%40mail.gmail.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/AM0PR07MB624187B39106F690C4BD3E10E6949%40AM0PR07MB6241.eurprd07.prod.outlook.com
> <https://groups.google.com/d/msgid/jallib/AM0PR07MB624187B39106F690C4BD3E10E6949%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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/CAM%2Bj4qssx%2Bkh9aoqPQ8NFY78U0veZDOjv6bXmbij23S1bebVqw%40mail.gmail.com.

Reply via email to