• AVR Freaks

Hot!Resetting PWM fault condition

New Member
  • Total Posts : 11
  • Reward points : 0
  • Joined: 2011/04/26 09:04:37
  • Location: Madison, WI
  • Status: offline
2011/10/11 12:41:35 (permalink)

Resetting PWM fault condition

Hi all - I am using the PWM module of a dsPIC33FJ64GS606 and am having trouble getting the fault condition to completely reset.  I feel like I'm missing something obvious.  Basically, I'm using an analog comparator to measure a voltage that, should it get too high, will trigger a PWM fault and tie all PWM outputs low.  When this happens I can flip a switch (input pin) high, then low, and the PWM action should resume.  However, the PWM action does not actually resume.  I have confirmed that the interrupt flags and such are getting reset properly but, sadly, still no PWM action.
The interesting part is that I can get the PWM to start up again by halting execution with the debugger and then starting execution again.  Without actually changing any registers or anything, the PWM does start up again.
I have also been able to get the PWM to start up again by doing
    PTCONbits.PTEN = 0; PTCONbits.PTEN = 1;
however I would prefer to not resort to this.  It turns out there is a bug with this chip and a specific start-up sequence must be used to prevent PWM pin glitches.  I'd prefer to avoid messing around with this if possible.
Has anyone experienced anything like this before?

4 Replies Related Threads

    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2011/04/26 09:04:37
    • Location: Madison, WI
    • Status: offline
    Re:Resetting PWM fault condition 2011/10/14 08:52:43 (permalink)
    +1 (1)
    Okay, after monkeying around with it a bit more I was able to make the fault reset function properly.  If it's of use to anyone, the problem was a combination of a typo in the FRM, my misreading the FRM, and having to add a small delay to allow the fault to completely reset (I'm using latched mode).  Here is the final fault reset code:
          IFS6bits.AC4IF = 0;                       /* Analog comparator interrupt flag */
    PWMCON1bits.FLTIEN = 0;            /* Clear PWM Channel 1 fault interrupt flag */
    PWMCON1bits.FLTIEN = 1;
    PWMCON2bits.FLTIEN = 0;            /* Clear PWM Channel 2 fault interrupt flag */
    PWMCON2bits.FLTIEN = 1;
    FCLCON1bits.FLTMOD = 0b11;      /* Disable PWM faults */
    FCLCON2bits.FLTMOD = 0b11;     for(count=0; count<100; count++);    /* Add in a small delay to allow fault condition to reset */ FCLCON1bits.FLTMOD = 0b00;      /* Enable PWM faults */
    FCLCON2bits.FLTMOD = 0b00;

    Sorry if the code isn't formed very legibly; I couldn't get some of the lines to look right in the preview.
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Status: offline
    Re:Resetting PWM fault condition 2018/03/29 06:25:26 (permalink)
    Thank you, this post save me!!!!!
    Just adding the small delay make my code running correctly.
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re:Resetting PWM fault condition 2018/04/07 21:36:48 (permalink)
    For short delays, use the compiler built in delay macros.
    e.g. __delay_us() in XC16
    Simple do nothing for loops can get completely removed by the optimiser if you don't take special care, like making the count variable "volatile".

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/09/25 04:00:39
    • Location: 0
    • Status: offline
    Re: Resetting PWM fault condition 2019/04/17 03:53:45 (permalink)
    Hi Guys 
    I am also struggling with resetting the fault.
    If I single step through the reset procedure, it works fine. The FLTSTAT gets reset and the PWM starts up again.
    If I run the code without breaks, the PWM stays off.  If I then pause and look at the SFR's the FLTSTAT has not reset.
    I have tried the delay between the FLTMOD=0b11 and FLTMOD=0b00, still no joy!
    I am setting a flag in the PWM interupt routine and disabling the FLTIEN.
    void __attribute__ ( ( interrupt, no_auto_psv ) ) _PWM1Interrupt ( )
     /*User Code*/
        LATDbits.LATD1=1; // for scope checking
        if (PWMCON1bits.FLTSTAT == 1)
     IFS5bits.PWM1IF = false;

    In the main code I check for Fault flag that I set in Interrupt, then check FLT1/ RA2. (Is there a way to check FLT1 other then reading the pin RA2?)
    I then proceed to reset the FLTSTAT by setting and resetting FLTMOD<1:0> with a delay inbetween.
    Finaly, enabling interupt again and resetting my FAULT flag.
    NOW pwm is suppose to be pulsing.
    But it happens only when I single step through the code??
    Please Help. 



      __builtin_write_PWMSFR(&FCLCON1, 0x80B, &PWMKEY);
      __builtin_write_PWMSFR(&FCLCON2, 0x80B, &PWMKEY);

      __builtin_write_PWMSFR(&FCLCON1, 0x808, &PWMKEY);
      __builtin_write_PWMSFR(&FCLCON2, 0x808, &PWMKEY);

    Jump to:
    © 2019 APG vNext Commercial Version 4.5