2 Attachment(s)
Weird PWM Behaviour on 16F1825
It's possible I'm losing my mind, but why would this code make my motor spin faster than the revised code below? Everything else is the same (code, config, circuit connections).
Sample code 1 (motor spins up to correct RPM, from Test_SN754410_Reverse_0):
Code:
HIGH MOTOR_2_DIR ' reverse
' Spin up motors to saved value of _MotorRPM
IF MotorRPM > 66 THEN
FOR I = (255-65) to (255-MotorRPM) step -1
pause 30
HPWM 2, I, 20000 ' port engine (CCP2)
NEXT I
EndIf
HPWM 2, 255-MotorRPM, 20000' port engine (CCP2)
Sample code 2 (motor spins up to a lower RPM regardless of initial value of PortEngDir, from Test_SN754410_Reverse_1):
Code:
PortEngDir VAR BYTE
PortEngDir = 1
if PortEngDir = 1 then
HIGH MOTOR_2_DIR ' reverse
IF MotorRPM > 66 THEN
FOR I = (255-65) to (255-MotorRPM) step -1
pause 30
HPWM 2, I, 20000 ' port engine (CCP2)
NEXT I
EndIf
HPWM 2, 255-MotorRPM, 20000' port engine (CCP2)
else
LOW MOTOR_2_DIR ' Forward
IF MotorRPM > 66 THEN
FOR I = 65 to (MotorRPM - 1)
pause 30
HPWM 2, I, 20000 ' port engine (CCP2)
NEXT I
EndIf
HPWM 2, MotorRPM, 20000 ' port engine (CCP2)
endif
Is there something about nested IF blocks I don't know about?
Re: Weird PWM Behaviour on 16F1825
What's weird is that the code in the Main loop is the same, but if I program the same PIC16F1825 chip with the 2nd file (Test_SN754410_Reverse_1) then the motor spins at the lower RPM as it does in the IF..ELSE..ENDIF block before Main.
Anyone have any ideas? Ultimately, I'm modifying the program to allow using a switch to control motor direction but I don't want to lose how the motors spun with the previous code (as in Test_SN754410_Reverse_0)
Re: Weird PWM Behaviour on 16F1825
Anyone? A correction to the above is that the faster RPM is **not** what I want - I think this a cause of my EEPROM variable getting a weird initial setting of greater than what I have in the code (possibly linked to my post here).
Re: Weird PWM Behaviour on 16F1825
In both cases it defaults to
IF MotorRPM > 66 THEN
So it will always go to the second IF in the nest.??
Re: Weird PWM Behaviour on 16F1825
But the direction of the motor should be different (if you're talking about the 2nd sample code). Could it be that with additional code lines somehow the chip isn't being completely erased before re-programming so the EEPROM variable is some number > 255?
Re: Weird PWM Behaviour on 16F1825
You should check the settings on your programmer.
Robert
Re: Weird PWM Behaviour on 16F1825
I set them back to default after reading a post from Darrel on the EE_Var thread, but that hasn't helped. Which settings in particular are you thinking of?
Re: Weird PWM Behaviour on 16F1825
Erase code, erase eeprom settings for starters.
Re: Weird PWM Behaviour on 16F1825
I had checked those earlier, Demon, and also selected the 'Set to default'. I'll look over those again tonight.
1 Attachment(s)
Re: Weird PWM Behaviour on 16F1825
Here's a screenshot of my settings:
Attachment 6715
2 Attachment(s)
Re: Weird PWM Behaviour on 16F1825
I think you are interested in 3 things in particular: erasing before programming, programming and erase options.
Here are my settings:
Attachment 6717
Attachment 6718
Robert
Re: Weird PWM Behaviour on 16F1825
Quote:
Originally Posted by
RossWaddell
... Could it be that with additional code lines somehow the chip isn't being completely erased before re-programming so the EEPROM variable is some number > 255?
What if you display the eeprom value to an LCD or send it out to PC via RS232?
It would help to eliminate that as the source of your problem.
1 Attachment(s)
Re: Weird PWM Behaviour on 16F1825
Ross, what about your Program settings?
Attachment 6720
Re: Weird PWM Behaviour on 16F1825
I have the same settings except I also have the 'User ID' checked/enabled.
Re: Weird PWM Behaviour on 16F1825
Problem resolved. I was updating DT_INST-14.bas directly for different chips based on instructions for earlier versions of the file; now that I've downloaded the latest version and added the variables to my main program as needed, it seems to work fine.