'******* Mosfet Threshold Voltage Tester ********** '*** For use with PICAXE-14M and AXE033 LCD display '******* Fernando Garcia, June 2008 *************** symbol np_sel = pin0 symbol comp = pin1 symbol rst = pin4 'main selects either N or P channel Mosfet main: if rst = 0 then main 'loop until reset button pushed if np_sel= 1 then goto p_chan 'select P-chan pwmout 2 , 49, 0 'initialize N-chan serout 0,N2400,(254,128,"n-chan") 'display Mosfet pause 150 goto ct_loop_n 'jump to N-chan routine p_chan: pwmout 2 , 49, 200 'initialize P-chan serout 0,N2400,(254,128,"p-chan") 'display Mosfet pause 150 goto ct_loop_p 'jump to P-chan routine 'measuring loop for N channel ct_loop_n: for b1 = 0 to 5 'count 50 steps for b0 = 0 to 9 serout 0,N2400,(254,192,#b1,".",254,194,#b0,254,196,"volt") 'display volts if comp = 1 and b1 = 0 then goto stop_fail 'fail if comp high on 1st count gosub common 'calculate PWM variable b3 pwmout 2 , 49, b3 'PWM out on port C5 pause 20 'allow filter settling if comp = 1 then stop_done 'comparator high? if b1 = 5 then goto stop_fail 'counter overflow if rst = 1 then main 'reset next next goto ct_loop_n 'measuring loop for P channel ct_loop_p: for b1 = 0 to 5 for b0 = 0 to 9 serout 0,N2400,(254,192,#b1,".",254,194,#b0,254,196,"volt") 'display volts if comp = 0 and b1 = 0 then goto stop_fail 'fail if comp low on 1st count gosub common 'calculate PWM variable b3 let b3 = 200 - b3 'count down from 200 pwmout 2 , 49, b3 'PWM out on port C5 pause 20 'allow filter settling if comp = 0 then stop_done 'comparator low? if b1 = 5 then goto stop_fail 'counter overflow if rst = 1 then main 'reset next next goto ct_loop_p 'calculate the PWM constant B3 which will increment 20 Khz PWM in 2% steps '100% PWM = 200 counts common: let b2 = b1 * 10 let b3 = b2 + b0 let b3 = 4 * b3 return 'end routines, either fail or done stop_fail: serout 0,N2400,(254,128," fail ") 'display fail and wait if rst = 1 then main 'reset and start again goto stop_fail stop_done: serout 0,N2400,(254,128," done ") 'display done and wait if rst = 1 then main 'reset and start again goto stop_done