Weird PWM Behaviour on 16F1825


Closed Thread
Results 1 to 15 of 15
  1. #1

    Default 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?
    Attached Files Attached Files

  2. #2


    Did you find this post helpful? Yes | No

    Default 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)

  3. #3


    Did you find this post helpful? Yes | No

    Default 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).

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default 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.??
    Dave
    Always wear safety glasses while programming.

  5. #5


    Did you find this post helpful? Yes | No

    Default 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?

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Weird PWM Behaviour on 16F1825

    You should check the settings on your programmer.

    Robert

  7. #7


    Did you find this post helpful? Yes | No

    Default 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?

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Weird PWM Behaviour on 16F1825

    Erase code, erase eeprom settings for starters.

  9. #9


    Did you find this post helpful? Yes | No

    Default 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.

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: Weird PWM Behaviour on 16F1825

    Here's a screenshot of my settings:

    Name:  meLabs_Prg_Settings.png
Views: 942
Size:  461.7 KB

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default 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:

    Name:  Programmer options 1.JPG
Views: 916
Size:  92.0 KB

    Name:  Programmer options 2.JPG
Views: 849
Size:  92.7 KB

    Robert

  12. #12
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Weird PWM Behaviour on 16F1825

    Quote Originally Posted by RossWaddell View Post
    ... 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.

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Weird PWM Behaviour on 16F1825

    Ross, what about your Program settings?

    Name:  meLabs_Prg_Settings.JPG
Views: 921
Size:  76.6 KB

  14. #14


    Did you find this post helpful? Yes | No

    Default Re: Weird PWM Behaviour on 16F1825

    I have the same settings except I also have the 'User ID' checked/enabled.

  15. #15


    Did you find this post helpful? Yes | No

    Default 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.

Similar Threads

  1. Config & Oscon settings 16F1825
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th July 2020, 18:18
  2. Interrupt On Change Question on 16F1825
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd August 2012, 06:05
  3. Convert Rotary Encoder Code from 16F628A to 16F1825
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 7th June 2012, 05:34
  4. PBP3 Support HPWM on CCP3/CCP4 (16F1825)?
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd June 2012, 02:37
  5. odd 2550 behaviour
    By f_lez in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th November 2006, 10:03

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts