'''''''''''''''''''''''''''''''''''Assembley to collect period on cap1 cap2 and cap3''''''
asm
cap1m0 = 0101
cap1ren = 1
cap2m0 = 0101
cap2ren = 1
cap3m0 = 0101
cap3ren = 1
endasm
'''''''''''''''''''''''''''''''''Read values taken and write to var (no longer needed since file name can be used in calculations)''''''''''''''''''
start:
F69H VAR BYTE 'Value of period at CAP1 ready for calculation
F67H VAR BYTE 'Value of period at CAP2 ready for calculation
F65H VAR BYTE 'Value of period at CAP3 ready for calculation
''''''''''''''''''''''''''''''''''''Algorithm for finding power''''''''''''''''''''''''
averageperiod var byte 'saving average period to ram
averageperiod = (F69H+F67H+F65H)/3 'average period found using 3 periods
'for now im using arbitary random scaling factors, until i have the actual graphs to get the real rpm against power
rpmvalue var byte 'saving rpm value to ram
rpmvalue=60/(8*averageperiod) 'finding rpm value using current period measurement
power var byte 'saving power to ram
IF rpmvalue<=300 Then
power=rpmvalue/15
else
power=rpmvalue/10
endif
' now i need to link power to the arbitary pwm output
'this is a standard quadratic function (quadratic in example case anyway)
dutycycle var byte 'byte being the one that is answer of algorithm when thats created
dutycycle = (power^2)+(5*power)+3 'finding dutycycle using rpmvalue
'''''''''''''''''''''''''''''''''''pwm output (possibly need interupts so as not to cause delay in hpwm output'''''''''''''''''''''''''''''''''''''''''''' '''
CCP1CON=0 'output of pwm pin
TRISC= $00000000
HPWM 1,DutyCycle,20000
goto start
end
Bookmarks