Excellent.....many thanks, I shall use that code gratuitously.
Excellent.....many thanks, I shall use that code gratuitously.
Have you tested this fast averaging with Hysterisis by Darrel:
http://www.picbasic.co.uk/forum/cont...ith-hysteresis
Ioannis
Yes I have (& very good it is too) , but I'd rather have this jittery AtoD values 'cleaned up' at the source (rather than putting averaging in place to address unstability caused by avoidable factors)
Just include an RC filter on the A/D input, and put the PIC to sleep just before enabling the A/D conversion. This returns very stable readings in most applications with a stable power supply or Vref.
Nice subject !
I use a similar code for reading the over-current of one DC motor :
If the averge of 10 readings it's bigger than checkin value (or time exceed 5 seconds) then gpio.0 and gpio.5 goes low.Code:check: vt =0 vs =0 grup=0 cnt =0 pause 50 for cnt = 1 to 10 adcin 3, adval vt=adval * 5000 vt=div32 1023 grup=vt+grup pause 5 next cnt vs=grup / 10 if (vs > checkin) or (T1Count > 50) then gpio.0=0 gpio.5=0 endif
It's one good ideea to use ADCON instead ADCIN ? How to do this and keeping average of 10 readings ?
It's this correct ?
In header of code I add :
And I modify the "check" subroutine like that :Code:ADCON0 = %10001101 ' ADC input on GPIO.4/AN3/pin3 (page 41) ' MSB 1 = Right Justify "1" ' 0 = Vdd as voltage reference "0" ' 0 = n/a "00" ' 0 = n/a ' 1 = select channel 03 (bit 2 of 2) "11" ' 1 = select channel 03 (bit 1 of 2) ' 0 = conversion status (see routine) "0" ' LSB 1 = A/D converter module is on "1"
The hardware it's in picture.Code:check: vt =0 vs =0 grup=0 cnt =0 pause 50 for cnt = 1 to 10 ADCON0.1 = 1 NOT_DONE: if ADCON0.1 = 1 THEN NOT_DONE Pause 10 adval.highbyte = ADRESH adval.lowbyte = ADRESL PAUSE 10 vt=adval * 5000 vt=div32 1023 grup=vt+grup PAUSE 10 next cnt vs=grup / 10 if (vs > checkin) or (T1Count > 50) then gpio.0=0 gpio.5=0 endif
Thanks !
Bookmarks