ahhh thank you, thats cleared many things up for me. my picbasic pro just arrived so ill be testing all my attempted codings now!
cheers mack
ahhh thank you, thats cleared many things up for me. my picbasic pro just arrived so ill be testing all my attempted codings now!
cheers mack
ok well these are the bare bones of my code so far... i havnt actually created the algorithm yet so i havnt actually got a proper dutycycle to put in yet. and things like config settings etc i still have yet to choose. just hope its going in the right direction
'obviously unfinished and dutycycle would not be a fixed 50%'''''''''''''''''''''''''''''''''''Assembley to collect period on cap1 cap2 and cap3''''''
asm
cap1m0 = 0101
cap1ren = 1
cap2m0 = 0101
cap2ren = 1
cap3m0 = 0101
cap3ren = 1
endasm
'''''''''''''''''''''''''''values put in var for us in calculation''''''''''''''''''
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 average''''''''''''''''''''''''
'yet to write it
'''''''''''''''''''''''''''''''''''pwm output'''''''''''''''''''''''''''''''''''''''''''' '''
HPWM 1, 127, 20000
whoops just realised the pwm output wasnt quite anything...
hopefully that should workDutyCycle var byte 'byte being the one that is answer of algorithm when thats created
CCP1CON=0 'output of pwm pin
TRISC= $00000000
HPWM 1,DutyCycle,20000
end
hey sorry again,
getting the right ideas but im a little stuck on one bit...
i need to set the PWM period by writing to the PR2 register and then set the PWM duty cycle by writing to the CCPR1L register and CCP1CON<5:4> bits. would this require assembley language and how would i do it?
afterwards i need to make the CCP1 pin an output by clearing the
TRISC<2> bit. would that just be trisc.2 = 0 ?
also i need to set the TMR2 prescale value and enable Timer2
by writing to T2CON. but im not too sure on how to work out the prescale value? and how to write to it?
and i need to configure the CCP1 module for PWM operation, how would i decide upon specific configurations? leave it as standard config until i find there is a problem then try and sort out the config?
will this give me hpwm? since i cant find anywhere in the datasheet that its hardwarepwm, but i am presuming it is since its whole purpose seems to revolve around pwm outputs and ccp.
additionally if i am updating the pwm constantly as it is giving an output... will this cause any delay in the output? for example when it updates... there will be a significant pause in the pwm?
unforunately since i cant actually test it yet without the real algorithms, i just wanna know if this sounds about right?
'''''''''''''''''''''''''''''''''''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
I am not going to comment much on you code as I am still reading the data sheet and my chips have not arrived yet. But I do not think the ASM stuff is quite right.
Have you seen this thread? Post #4.
http://www.picbasic.co.uk/forum/showthread.php?t=7095
Dave
Always wear safety glasses while programming.
yeah i didnt really know where i was going with the assembley stuff... just kinda wrote down a few commands that seemed kinda suitable...
Bookmarks