' RC Car motor DYNAMOMETER
#picaxe 20X2
Symbol Disp= C.7
Symbol Read_temp= W0 'b0 b1
Symbol Read_tork= W1 'b2 b3
Symbol RPM= W2 'b4 b5
Symbol Power_out= W3 'b6 b7
Symbol Read_amp= W4 'b8 b9
Symbol Read_volt= W5 'b10 b11
Symbol Power_in= W6 'b12 b13
Symbol Effic= W7 'b14 b15
Symbol Zero_tork= W8 'b16,b17
Symbol Cal_ADC= W9 'b18 b19
Symbol Sumr = W10 'b20 b21
Symbol Addr = W11 'b22 b23
Symbol Volt_Supp = W12'b24 b25
Symbol N = b42
Symbol M =b43
Symbol L =b44
'****************************************************
Symbol LED = C.2
'****************************************************
Symbol COM = 44 'comma
Symbol RET = 13 'carriage return
Symbol LIN = 10 'line feed
Symbol G = 71
M=0
L=0
'**************************************************
DirsC = %00100111
DirsB = %10100000
ADCSetup = %0000000010100110 ' ADC1,2,5,7
HSerSetup B9600_8,%00
hi2csetup i2cmaster, %10100000, i2cfast_8, i2cword
High C.1
Addr=0
Sumr=0
HSerOut 0, ("?G420") ' configure LCD as 4 X 20
Pause 500
HSerOut 0, ("?S0") 'Blank Screen
Pause 500
HSerOut 0, ("?f") 'clear screen
Pause 500
HSerOut 0, ("?c0") ' no cursor on LCD
Pause 500
HSerOut 0, ("?<") 'exit big number mode
Pause 500
HSerOut 0, ("?B50") ' Set backlight
Pause 500
Checkbat:
Readadc10 C.3,Volt_Supp 'Get voltage from supply battery
If Volt_Supp=<614 then goto Buzz 'Sound alarm if battery voltage is less than 6V
if pinC.7 = 0 then INIT 'Initiate data transfer to PC
HSerOut 0, ("?y0?x00") 'Position cursor at beginning of row 1
Pause 50
HSerOut 0, (" HELLO PETE","?n")
Pause 50
HSerOut 0, (" PRESS THE BUTTON","?n")
Pause 50
HSerOut 0, (" AND HOLD FOR THE","?n")
Pause 50
HSerOut 0, (" RED LIGHT")
Looper:
button C.6,1,255,100,M,0,Looper
' ***************************
Pause 1000
High LED 'LED On
High C.1 'Write protect memory
Calibadc10 Cal_ADC
Readadc10 B.3,Zero_tork
Zero_tork=Zero_tork/2
HSerOut 0, ("?f","?y0?x00") 'clear screen
HSerOut 0, (" CALIBRATION TEST","?n")
HSerOut 0,("CalVal ",#W9,"?n")
HSerOut 0,("ZeroVal ",#Zero_tork)
Pause 2000
HSerOut 0, ("?f","?y0?x00") 'clear screen
HSerOut 0, (" WHEN THE LIGHT","?n")
HSerOut 0, (" IS OFF","?n")
HSerOut 0, (" START THE MOTOR ","?n")
HSerOut 0, ("AND PRESS THE BUTTON")
Pause 2000
low C.2 'LED Off
Looper5:
button C.6,1,255,100,M,0,Looper5
'***************************************************************************
Main:
' ***************************
N=0
HSerOut 0, ("?f","?y0?x00")
For L=1 to 4 'Read the torque value 8 times
readadc10 b.3,Read_tork
if Read_tork>Zero_tork then Looper4
Read_tork=Zero_tork
Looper4:
Read_tork=Read_tork-Zero_tork
Sumr=Sumr+Read_tork
pause 100
Next L
L=0
Read_tork=Sumr/4 'Calculate Torque average and store in Tork_read
Sumr=0
setfreq m32
Pause 1000
count C.4,16000, W2 'Count revolutions during 2 seconds
w2=w2*30 'Calculate RPM
setfreq m8
pause 200
'Readadc10 B.0,Read_amp 'Read Amp draw
'Read_amp=Read_amp*50/1381 'Convert to amps
'Readadc10 B.0,Read_volt 'Read volts in
'Read_volt=Read_volt*5/1023 'Convert to Volts
'Readtemp12 B.2,Read_temp 'Read temperature
' Convert:
'Read_temp=Read_temp+880/16*9/5-67
Power_out=RPM/100*Read_tork 'Calculate power output
PAUSE 100
HSerOut 0, ("TORK=",#Read_tork,"?x10","RPM=",#W2,"?n")
HSerOut 0, ("?x10","Power=",#Power_out)
Low C.1 'Unprotect Memory
hi2cout Addr,(b2,b3,b4,b5,b6,b7)'Write to mamory Torque, RPM, Power
Pause 500
' **************************************************
readi2c Addr,(b2,b3,b4,b5)
pause 500
HSerOut 0, (#Read_tork," ",#W2," ",#Power_out)
' **************************************************
Addr=Addr+6
High C.1 'Protect Memory
Pause 500
Looper3:
' ***************************************************
HSerOut 0, ("?y0?x00") ' position cursor at beginning of row 1
HSerOut 0, ("?y2?x00","SET RPM AND PRESS")
setfreq m32
Pause 1000
count C.4,16000, W2 'Count revolutions during 2 seconds
w2=w2*30 'Calculate RPM
setfreq m8
HSerOut 0, ("?y3?x00","RPM=",#W2)
pause 500
HSerOut 0, ("?y3?x4"," ")
button C.6,1,255,100,M,0,Looper3
' ***************************************************
HSerOut 0, ("?y0?x00")
goto Main
'**********************************************************************
'DATALINK to PC
INIT:
HSerOut 0, ("?f","?y0?x00")
HSerOut 0, (" PRESS THE BUTTON","?n")
HSerOut 0, (" TO SEND DATA","?n")
HSerOut 0, (" TO THE COMPUTER","?n"," AT 9600 BPS")
Looper1:
button C.6,1,255,100,M,0,Looper1
L=0
' ***************************
high C.1 'Write protect eeprom
high C.2 'LED On
sertxd (" I AM READY TYPE G AND CLICK SEND",RET,LF,LF)
let Addr = 0
serrxd (G) 'Wait for GO signal
sertxd ("Sample",COM," TORQUE",COM,"RPM ",COM,"POWER",RET,LF)'Titles
HSerOut 0, ("TRANSFERING DATA","?n")
Read_data: 'Now read the data
hi2cin Addr , (b2,b3,b4,b5,b6,b7)
If Read_tork>2000 then ALL_done
low C.2
TX_data:
sertxd (#L,COM,#Read_tork,COM,#RPM,COM,#Power_out,RET,LF)
Inc_Addr:
L=L+1
let Addr = Addr + 6
high C.2
goto Read_data
ALL_done:
high C.2
L=0
sertxd (0) 'finished so send NULL
HSerOut 0, ("?f","?y0?x00"," DATA TRANSFER","?n") 'clear screen
HSerOut 0, (" IS COMPLETE","?n")
HSerOut 0, (" GO RACING AND KICK","?n")
HSerOut 0, (" SOME CULO ")
END
Buzz:
HSerOut 0, ("?f","?y0?x00"," LOW BATTERY","?n")
HSerOut 0, ("?y2?x00","CHARGE IT NOW TURKEY","?n")
Buzz1:
Low LED
sound C.5, (50,50)
Pause 200
sound C.5, (100,50)
High LED
pause 200
Goto Checkbat