Menu

Pulse rate issue with PWM software mode on 16F877A

2024-02-13
2024-02-14
  • Terry Platt

    Terry Platt - 2024-02-13

    Hi All,
    I've got a board with four stepper motors that I'm driving with the software PWM code as given in the GCB command list. The equation for the pulse rate calculares out as 13.6uS per cycle (20 MHz clock and no delay), but I see about 1.3mS cycle time pulses on the output. Is the cycle time equation incorrect, or am I missing some important setting?

     
  • Anobium

    Anobium - 2024-02-14

    Not sure.

    Can you post a small section of the program to show the issue?

     
  • Terry Platt

    Terry Platt - 2024-02-14

    Hi Anobium, Here's where I set up and then test the PWM output. I need 4 channels, but I use only one for the test. The chip is running at 20MHz with a resonator (checked) and I've tried various numbers of cycles, but always get the 1.3mS cycle time.

     
  • Anobium

    Anobium - 2024-02-14

    I get a width of 7.6ms. So, I cannot explain.

    My full program.

        #chip 18F16Q20, 20
        #option Explicit
    
        #define PWM_Out1 portc.7
        #Define PWM_Delay 0 us 
        dir PWM_Out1 out
    
        Do
            PWMOut 1, 127, 255 
        Loop
    

    I have built a modeller. See https://1drv.ms/x/s!Ase-PX_n_4cvhNwqbKN5gGktDH_iNQ?e=fVWlwe The yellow cells are the named cells used in the calculation.

    T_Cycle =(( Instructions + (InstructionsPerPWM*ChannelsUsed))*TOSC)+( 255 * PWM_Delay/1000 *ChannelsUsed)
    

    The calcs do not work based on the formula shown in the Help. in the modeller - I have shown the PWMOUT() command and the number of instructions using this chip. I have changed the formula as the delay is a function of the number of channels used ( but the value is 0 when no delay is set).

    The pulse width ( 7.6ms) is the same using the legacy FOR-NEXT as this could have been the issue ( it is not as this new for-next is optimised).

    So, play wit the modeller. See if you can make work and make sense! Once we have a model then I think it will answer the question about the formula being correct or not.

    Try to figure this out in the modeller.

     

    Last edit: Anobium 2024-02-14

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.