dsPIC33F之Latched Fault Code Workaround via PWM Override Logic Routine

/
// ?2012 Microchip Technology Inc.
//
// MICROCHIP SOFTWARE NOTICE AND DISCLAIMER:  You may use this software, and any 
// derivatives created by any person or entity by or on your behalf, exclusively with 
// Microchip抯 products.  Microchip and its licensors retain all ownership and intellectual 
// property rights in the accompanying software and in all derivatives here to.  
//
// This software and any accompanying information is for suggestion only.  It does not 
// modify Microchip抯 standard warranty for its products.  You agree that you are solely 
// responsible for testing the software and determining its suitability.  Microchip has 
// no obligation to modify, test, certify, or support the software.
//
// THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED 
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF NON-INFRINGEMENT, 
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION 
// WITH MICROCHIP扴 PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. 
// 
// IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, TORT 
// (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT LIABILITY, INDEMNITY, 
// CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL 
// OR CONSEQUENTIAL LOSS, DAMAGE, FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE 
// SOFTWARE, HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR 
// THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT ALLOWABLE BY LAW, MICROCHIP'S TOTAL 
// LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, 
// IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
//
// MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS.
//
/
//
//      Device:  dsPIC33FJ64GS610
//
//	Purpose: Latched Fault Code Workaround via PWM Override Logic Routine 
//      
//      Description:
//	This code example shows the workaround for the latched fault condition.
//	Fault1 on the PWM module is used as the fault input - pin 100. A logic 
//      HIGH value on this pin will trigger the fault operation, and the PWM1L 
//      and PWM1H output will be reset to logic LOW. The outputs will be set LOW 
//      until a logic LOW is once again applied to pin RD8 - pin 100. Applying a
//      logic LOW re-enables the PWM outputs PWM1L and PWM1H.
//
//      PWM1H and PWM1L are available on PIM pins 28 and 29, respectively. 
//
// //


#include <p33fj64gs610.h>


//  ------------------ FUSES / CONFIGURATION BITS ------------------ //

_FWDT(FWDTEN_OFF);               // Watchdog timer disabled
_FICD(JTAGEN_OFF & ICS_PGD1);    // Disable JTAG and Communicate on PGC1/EMUC1 and PGD1/EMUD1
_FOSC(FCKSM_CSECMD);             // Clock switching is enabled, Fail-safe Clock Monitor is disabled
_FOSCSEL(FNOSC_FRC & IESO_ON);   // Internal FRC startup without PLL, switch to FRC & PLL.


// -- Function Prototypes -- //
extern void init_PLL(void);     // PWM setup function
extern void init_AuxPLL(void);     // Enable auxiliary clock
extern void init_PWM(void);     // Initialize PWM module
extern void init_Timer2(void);  // Timer2 initialization
extern void init_Timer1(void);  // Timer4 initialization
extern void Delay_us(unsigned int Timercounts);

unsigned char faultActiveFlag = 0;
unsigned char tmrFlag = 0;

int main (void)   //  Begin main.c code here //

{
    init_PLL();
    init_AuxPLL();
    init_Timer1();
    init_Timer2();
    init_PWM();
    	
   // --- Enable PWM and Timer2 Modules --- //
   PTCONbits.PTEN     = 1;    // Enable PWM module
   T2CONbits.TON      = 1;    // Start Timer2

    while(1)
    {
	   if ((PORTDbits.RD8) && (faultActiveFlag == 1))  // FLT1 is HIGH and fault flag is HIGH
	   {
             // --- PWM Output Override Logic --- /
             IOCON1bits.OVRDAT  = 0;  // PWM1 outputs will be at logic level '0' when overriden
			 
             // Override PWM1H and PWM1L outputs to OVRDAT value above/
			 IOCON1bits.OVRENH  = 1;  // PWM1H = OVRDAT = 0
             Nop();
             IOCON1bits.OVRENL  = 1;  // PWM1L = OVRDAT = 0

             faultActiveFlag = 0;
             FCLCON1bits.FLTMOD = 0b11;
		   }

		     //if RD8 pin is LOW and fault flag is LOW
       else if((!PORTDbits.RD8) && (faultActiveFlag==0))
		 {
			faultActiveFlag = 1;
			Delay_us(10);          // wain one PWM period before start

			IOCON1bits.OVRENH = 0;
            Nop();       
            IOCON1bits.OVRENL = 0;
	      }
   }   
         
	return 0; // --- End of main.c --- //
}


// add one PWM cycle delay at 100kHz PWM frequency
void Delay_us(unsigned int timerCounts)
{  
   tmrFlag       = 0;
   T1CONbits.TON = 1;    // Enable Timer1

   while(tmrFlag <= timerCounts){}  // Wait for tmrFlag to be set from Timer1 ISR
  
   T1CONbits.TON = 0;    // Disable TIMER1
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值