'USB Power current monitor on PICAXE 08M2 'v2.00: operate under timer interrup mode ' '2013/06/4 radiopench 'http://radiopench.blog96.fc2.com/ ' symbol SF = 208 ; Caliblatin ScaleFactor ; 1024*416.7mv/(2048mv) symbol OFS = 1 ; Offset value symbol LEDx1 = C.1 symbol LEDx10 = C.0 symbol acum = w2 symbol N = b7 setfreq m4 ; clock frq. = 4MHz fvrsetup FVR2048 ; set FVR as 2.048V adcconfig %011 ; set FVR as ADC Vref+, 0V Vref- let acum = 0 ; Accum ADC value let N =0 ; 10X counter high LEDx1 ; LED off high LEDx10 ; pwmout pwmdiv64, 2, 186, 80 ;PWM on C.2 1.4ms/12ms setint %00000100, %00000100 ;IRQ set @C.2 positive main: ; goto main ; wait, do nothing interrupt: if pinC.2 = 1 then interrupt; wait C.2 LOW readadc10 C.4,w1 ; read ADC value into w1 let w1 = w1 - OFS ; Offset adjust if w1 > 1024 then ; if negative let w1 = 0 ; endif let acum = acum + w1 ; Accumulate value if acum >= SF then ; if more than ScalFactor toggle LEDx1 ; 1x LED ON or OFF let acum = acum - SF ; save remainder inc N ; inc 10x counter if N = 10 then ; let N = 0 toggle LEDx10 ; 10x LED ON or OFF endif endif setint %00000100, %00000100 ; set IRQ again return ; return to main