• AVR Freaks

Hot!Trouble with control of PWM using PIC32 and Simulink

Author
danielPatrick
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/04/09 11:41:12
  • Location: 0
  • Status: offline
2019/04/15 06:42:33 (permalink)
0

Trouble with control of PWM using PIC32 and Simulink

I am using a PIC32 EF built into the Diligent Wi-FIRE board. I have the MPLAB Simulink Blockset and am trying to set up a 10 kHz PWM to pin 5, and I want to adjust the duty cycle by using the potentiometer built into the board.
I have the timer for the PWM block set to 0.0001s and the sample time for that branch is 0.00001s
After uploading to the hardware, the frequency of the output is 300 microseconds, should be 100 microseconds.
Another thing I cant quite figure out is the resolution of the duty cycle adjustment. The output only seems to sweep through 0, 33, 66 and 100 % as I adjust the potentiometer. In the output compare block I have played around with the ‘max time for all channels value’ and scaled the gain for the input to this block accordingly (equal to the ‘OC1max’) but this is not resolving my problem. I am new to this platform so any insight or suggestions would be greatly appreciated.

Attached Image(s)

#1

2 Replies Related Threads

    Lubin
    Moderator
    • Total Posts : 359
    • Reward points : 5
    • Joined: 2007/03/31 07:38:15
    • Location: Bayonne, France
    • Status: offline
    Re: Trouble with control of PWM using PIC32 and Simulink 2019/04/15 07:01:06 (permalink)
    0
    Hi Patrick,
     
    Try uploading model whenever possible.
     
    To Scale the Output Compare ducy cycle, multiply the ADC output with a gain with the value: OC1max / 4096 (I suppose the ADC output is set for 12 bits) here.
    If you have any doubts with fixed point, maybe convert your calculation to float first.
     
    The block sampling time and Output Compare period is not linked.
     
    If you use the PWM block instead of the Output Compare, and
    If the ADC is triggered with the PWM signal, and
    If the end of ADC conversion trig the main time step,
    ==> Then you have to insure that the Simulink model base time step period is equal to the PWM period otherwise your model run with a wrong time base.
     
    This is one subtility. But provided you do not use the PWM block, you do not have to pay attention to this.
    #2
    danielPatrick
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/04/09 11:41:12
    • Location: 0
    • Status: offline
    Re: Trouble with control of PWM using PIC32 and Simulink 2019/04/15 07:22:47 (permalink)
    0
    Thank you for your reply, I made your modifications and it works perfectly! I did not properly understand the features of the output compare block. All makes sense now. Wish I had posted to this forum earlier. 
     
    Thank you again Lubin
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5