• slider image 442
  • slider image 497
  • slider image 498
  • slider image 499
  • slider image 500
  • slider image 502
:::


Browsing this Thread:   1 Anonymous Users






Re: c30pwm的問題
#4
新會員
新會員


查看用戶資訊
我將這些靜態常數值丟入duty中,是為了要建立弦波點所設的值,我想做一個spwm, 但我在程式中的那些值是做為測試用,並不是弦波點。想改用c30來寫,沒想到並不順利~還請各位先進指教

發表於: 2006/4/24 21:27
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: c30pwm的問題
#3
資深會員
資深會員


查看用戶資訊
想請問一下,為什麼要將靜態常數值丟入PDC1中 呢,是要做

什麼功用的??

發表於: 2006/4/24 20:46
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: c30pwm的問題
#2
新會員
新會員


查看用戶資訊
這是我直接設暫存器時的程式,但這有成功的
大家可以討論討論,不過我想改c30來寫

//此電路頻率為12MHZ,經PLL=8倍震盪變為96MHZ,4/96MHZ=41.6ns(每一clk週期計時)
//PTPER計數為800*2=1600,1600*41.6ns=66.7us,1/T=15KHZ
//中斷PDC1=400,400/1600=0.25 , 0.25*66.7us=16.67us(每到16.67us中斷一次變為0)

#include <p30f4011.h>
#include <ports.h>
#include <pwm.h>
//---------------------------------------------------------------------------
// Configuration bits

_FOSC(CSW_FSCM_OFF & XT_PLL8);
_FWDT(WDT_OFF);
_FBORPOR(PBOR_OFF & MCLR_EN );
_FGS(CODE_PROT_OFF);

//---------------------------------------------------------------------------
// Definitions

#define Fcy 12000000*2 //24M*8=96MHZ , 4/96MHZ=41.66..ns <--平均每一點的週期
#define PWM1_L LATEbits.LATE0
#define PWM1_H LATEbits.LATE1

//***************************************************

void initial (void)
{

LATE = 0x0000; //TRISX:1為輸入方向,0為輸出方向
TRISE = 0x0000;
return;
}

//*********************main program********************

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;

void main()
{
initial();

PTCON=0X8002;

PTPER=800; //T=41.66ns*1600(上下計數800*2)=66.7us ,
//F=1/T , 1/66.7us=15kHZ
PWMCON1=0x0077;

DTCON1=0x008C; //DTAPS=10 (除頻4倍)00=8,41.66us*4*12(C)=2us

OVDCON=0x0FAA; //強制修改同步

FLTACON=0x008C; //錯誤偵測

while(1)

{
for(i=0;i<65;i++)
{
PDC1=table[i];
}
}
}

發表於: 2006/4/24 19:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


c30pwm的問題
#1
新會員
新會員


查看用戶資訊
版主,您好,我將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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------