dsp4011 產生Sine WAVE
|
||||
---|---|---|---|---|
新會員
|
我要寫一個PWM1會輸出SINE WAVE 的程式
程式在編譯時並沒有錯誤,但是寫入REAL ICE 執行DEBUG時 OUTPUT 卻說TARGET HALTED,請問這問題可能出在哪裡呢? 是程式的邏輯有問題?還是設定有錯誤?或者是其他的因素? 歡迎大家不吝指教 CHIP型號:DPSPIC4011 實驗版:APP009-dspic40-28p 25550110 程式碼如下: #include <p30f4011.h> #include <timer.h> #include <pwm.h> #include <math.h> #define FCY 7372800*2 #define KPI 0.09817477 //2*PI/64 _FOSC(CSW_FSCM_OFF & XT_PLL8); //XT with 8xPLL oscillator, Failsafe clock offIRRtO _FWDT(WDT_OFF); //Watchdog timer disabledk- _FBORPOR(PBOR_OFF & MCLR_EN); //Brown-out reset disabled, MCLR reset enabledj{g _FGS(CODE_PROT_OFF); //Code protect disabledw9w/ unsigned int const Timer1 = 55530; unsigned int pwmstep = 0; unsigned long pwmtab = 0; unsigned long pwm_out = 0; int dutycyclereg = 1; unsigned long dutycycle = 0; int updatedisable = 0; unsigned int period = 0; unsigned int sptime = 0x0; unsigned int config1 = { PWM_EN & PWM_IDLE_CON & PWM_OP_SCALE1 & PWM_IPCLK_SCALE1 & PWM_MOD_FREE }; unsigned int config2 = { PWM_MOD1_COMP & PWM_PDIS3H & PWM_PDIS2H & PWM_PEN1H & PWM_PDIS3L & PWM_PDIS2L & PWM_PEN1L }; unsigned int config3 = { PWM_SEVOPS1 & PWM_OSYNC_PWM & PWM_UEN }; void INT_PWM(void); void main() { INT_PWM(); /*INITAL TIMER1*/ ConfigIntTimer1( T1_INT_PRIOR_5 & T1_INT_OFF ); WriteTimer1( Timer1 ); /* turn on timer1 */ OpenTimer1( T1_ON & T1_IDLE_STOP & T1_GATE_OFF & T1_PS_1_1 & T1_SYNC_EXT_OFF & T1_SOURCE_INT,(FCY/1000)); period = dutycycle; OpenMCPWM ( period, sptime, config1,config2, config3 ); } void _ISR _T1Interrupt( void) { CloseTimer1(); OpenTimer1( T1_ON & T1_IDLE_STOP & T1_GATE_OFF & T1_PS_1_1 & T1_SYNC_EXT_OFF & T1_SOURCE_INT,(FCY/1000)); pwmtab = sin( KPI * pwmstep); dutycycle = pwmtab; SetDCMCPWM ( dutycyclereg, dutycycle,updatedisable ); if ( pwmstep < 32 ) pwmstep ++; else pwmstep = 0 ; } void INT_PWM() { SetDCMCPWM ( dutycyclereg, dutycycle,updatedisable ); }
發表於: 2008/3/20 10:11
|
|||
|