0% found this document useful (0 votes)
286 views2 pages

Picaxe 4-20ma Tester

The document describes a program that controls a PWM output to raise and lower between 4mA, 12mA, and 20mA levels. It uses an ADC to read the current and adjusts the PWM duty cycle up or down if the current drifts from the target level. If the current goes out of range, it enters a fault routine that can be reset by a push button.

Uploaded by

vinothvlb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
286 views2 pages

Picaxe 4-20ma Tester

The document describes a program that controls a PWM output to raise and lower between 4mA, 12mA, and 20mA levels. It uses an ADC to read the current and adjusts the PWM duty cycle up or down if the current drifts from the target level. If the current goes out of range, it enters a fault routine that can be reset by a push button.

Uploaded by

vinothvlb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

start:

w6=200:w4=80:b4=1 ' w6=pwm, w4=adc for 4mA, b4=12mA loop


cnt.
gosub raise ' raise to 4mA
gosub interrupt ' and wait for push button

loop0:
wait 2
w4=444 ' adc for 12mA
gosub raise ' raise to 12mA

b3=2 ' b3=led flash number


if b4>5 then loop1 ' only stop at 12mA 5 times
gosub flash

loop1:
w4=408 ' adc for 20mA
gosub raise ' raise to 20mA
b3=3
gosub flash

lower:
wait 2
w4=80 ' adc for 4mA
for w6=w6 to 0 step -1 ' decrease pwm
for b1=1 to 10
pwmout 2,255,w6 ' pwm on output2
readadc10 1,w5
if w5<70 or w5>420 then fault
if w5<=w4 then loop2
next b1
next w6

loop2:
pulsout 4, 300 ' 1 flash for 4mA
goto loop0

raise:
for w6=w6 to 1024
for b1=1 to 15
pwmout 2,255,w6
readadc10 1,w5
if w5>=w4 then valueup
next b1
if w5<40 or w5>420 then fault
next w6

valueup:
return

flash:
for b2=1 to b3
pulsout 4,300 ' flash output4
pause 800
next b2
return
interrupt:
pulsout 4,300 ' PB has been pressed
b3=1
pause 1000 ' wait for PB release

freeze:
pwmout 2,255,w6 ' PWM on output2
pause 10
readadc10 1,w3
if pin3=1 then loop3 ' has PB been pressed?
if w3<70 or w3>420 then loop4 ' out of range?
if w3>w5 then tweakdown ' has output drifted high?
goto freeze ' all ok

loop3:
pulsout 4,300 ' inicate PB press
pause 1000

loop4:
setint %00001000,%00001000 ' enable interrupt for freeze control
return

tweakup:
w6=w6+1 ' adjust output up
goto freeze

tweakdown:
w6=w6-1 ' adjust output down
goto freeze

fault:
setint %00000000,%00000000 ' disable interrupt
pwmout 2,0,0 ' turn off output

loop5: ' LED fault routine


for b5=0 to 30
if pin3=1 then loop6 ' has PB neen pressed?(reset)
if b5>29 then loop5
if b5>10 then led

loop7:
pause 50
next b5

led:
pulsout 4,300 ' led fault indication
goto loop7

loop6:
pulsout 4,300 ' indicate PB press
goto start

You might also like