Re: c30pwm的問題
|
||||
---|---|---|---|---|
新會員
|
我將這些靜態常數值丟入duty中,是為了要建立弦波點所設的值,我想做一個spwm, 但我在程式中的那些值是做為測試用,並不是弦波點。想改用c30來寫,沒想到並不順利~還請各位先進指教
發表於: 2006/4/24 21:27
|
|||
|
Re: c30pwm的問題
|
||||
---|---|---|---|---|
資深會員
|
想請問一下,為什麼要將靜態常數值丟入PDC1中 呢,是要做
什麼功用的??
發表於: 2006/4/24 20:46
|
|||
|
c30pwm的問題
|
||||
---|---|---|---|---|
新會員
|
版主,您好,我將c30的範例拿來增加靜態常數值丟入c30涵式庫中的dutycycle中來改變duty值,但一直出現build all錯誤
但我直接用暫存器設定來寫程式時卻可以成功的丟入PDC1中 請問使用c30涵式庫時還是要有注意到宣告什麼地方或者並不能直接將值丟入涵式庫中?? 此範例週期我改66us,為上/下計數制。 // *********************************************************************** // File : EX15_1_MCPWM.C // Purpose : 練習如何使用 Microchip C30 提供的 PWM 函式庫 // // 使用的函式庫: // pwm // // *********************************************************************** #define <dsPIC30F4011> #include <p30F4011.h> #include <pwm.h> // 將pwm函式的原型宣告檔案含入 #define FCY 12000000 * 2 void Init_MCPWM(void); _FOSC(CSW_FSCM_OFF & XT_PLL8); //XT with 8xPLL oscillator, Failsafe clock off _FWDT(WDT_OFF); //Watchdog timer disabled _FBORPOR(PBOR_OFF & MCLR_EN); //Brown-out reset disabled, MCLR reset enabled _FGS(CODE_PROT_OFF); //Code protect disabled static const int table[] ={0 , 17 , 23 , 26 , 28 , 39 , 41 , 46 , 66 , 88 , //測試用點位 100, 110,120,130,140,150,160,170,180,190, 200,210,220,230,240,250,260,270,280,290, 300,310,320,330,340,350,360,370,380,390, 400,450,500,550,600,650,700,750,800,850, 900,950,1000,1050,1100,1150,1200,1250,1300,1350, 1400,1450,1500,1550,1600}; int i; int main(void) { Init_MCPWM(); while(1) { for(i=0;i<65;i++) { dutycycle=table[i]; } } //******************************************************* void Init_MCPWM(void) { /* Holds the PWM interrupt configuration value*/ unsigned int config; /* Holds the value to be loaded into dutycycle register */ unsigned int period; /* Holds the value to be loaded into special event compare register */ unsigned int sptime; /* Holds PWM configuration value */ unsigned int config1; /* Holds the value be loaded into PWMCON1 register */ unsigned int config2; /* Holds the value to configure the special event trigger postscale and dutycycle */ unsigned int config3; /* The value of ‘dutycyclereg’ determines the duty cycle register(PDCx) to be written */ unsigned int dutycyclereg; unsigned int dutycycle; unsigned char updatedisable; /* Configure pwm interrupt enable/disable and set interrupt priorties */ /* Configure PWM to generate square wave of 50% duty cycle */ ConfigIntMCPWM( config ); dutycyclereg = 1; updatedisable = 0; SetDCMCPWM(dutycyclereg,dutycycle,updatedisable); period = 800; sptime = 0x0; config = (PWM_INT_DIS & PWM_FLTA_DIS_INT & PWM_INT_PR1 & PWM_FLTA_INT_PR0); config1 = (PWM_EN & PWM_IDLE_STOP & PWM_OP_SCALE16 & PWM_IPCLK_SCALE1 & PWM_MOD_DBL); config2 = (PWM_MOD1_COMP & PWM_PDIS3H & PWM_PDIS2H & PWM_PEN1H & PWM_PDIS3L & PWM_PDIS2L & PWM_PEN1L); config3 = (PWM_SEVOPS1 & PWM_OSYNC_PWM & PWM_UEN); OpenMCPWM(period,sptime,config1,config2,config3); } }
發表於: 2006/4/24 19:45
|
|||
|