Weird PWM Behaviour on 16F1825


Results 1 to 15 of 15

Threaded View

  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

Similar Threads

  1. Config & Oscon settings 16F1825
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th July 2020, 17:18
  2. Interrupt On Change Question on 16F1825
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd August 2012, 05: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, 04:34
  4. PBP3 Support HPWM on CCP3/CCP4 (16F1825)?
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd June 2012, 01:37
  5. odd 2550 behaviour
    By f_lez in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th November 2006, 09: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