• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 30F4011 PWM控制伺服機
#2
版主
版主


查看用戶資訊
書沒有看清楚,再詳看一下 dsPIC30F Family Reference Manual 裡的 MCPWM 章節。http://www.microchip.com/stellent/gro ... ts/devicedoc/en026096.pdf

有幾個戰存器是要了解的:
PTCON : PWM Time Base Control register
PTMR : PWM Time Base counter
PTPER : PWM Time Base Period register
SEVTCMP : PWM Special Event Compare register
PWMCON1 : PWM Control register #1
PWMCON2 : PWM Control register #2
DTCON1: Dead Time Control register #1
DTCON2: Dead Time Control register #2
FLTACON : Fault A Control register
FLTBCON : Fault B Control register
PDCx : PWM Duty Cycle register #1 ~ #4

控制 Period 的就是 PTPER 暫存器。
控制 Duty Cycle 的是PDC1, PDC2, PDC3 三個暫存器,看底下波形應可知道。

Attach file:



jpg  (0.00 KB)


jpg  (0.00 KB)


發表於: 2009/7/16 9:52
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


30F4011 PWM控制伺服機
#1
新會員
新會員


查看用戶資訊
以下程式碼為曾百由寫的 dspic數位訊號控制器原理與應用
第15章中的範例

//---------------------------------------------------------------------
#define __dsPIC30F4011__

#include <p30F4011.h>
#include <pwm.h> // 將pwm函式的原型宣告檔案含入

#define FCY 7372800 * 2 // 因為使用頻率為將外部 7.3728 MHz * 8 的模式 , 每一指令週期需 4 個 clock
// 所以 FCY = (7.3728 * 8 / 4 ) MHz = 7372800* 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


int main(void)
{

Init_MCPWM( );

while(1);
}

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 */
config = (PWM_INT_DIS & PWM_FLTA_DIS_INT & PWM_INT_PR1
& PWM_FLTA_INT_PR0);
ConfigIntMCPWM( config );
/* Configure PWM to generate square wave of 50% duty cycle */
dutycyclereg = 1;
dutycycle = 0x3FFF;
updatedisable = 0;
SetDCMCPWM(dutycyclereg,dutycycle,updatedisable);
period = 0x7fff;
sptime = 0x0;
config1 = (PWM_EN & PWM_IDLE_STOP & PWM_OP_SCALE16
& PWM_IPCLK_SCALE64 &
PWM_MOD_UPDN);
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);


/---------------------------------------------------------------/

因為要控制伺服機,他的控訊號是1ms為反轉、2ms為正轉,每秒可接收60個訊號,想請問要怎麼設定 dutycycle 及 period?

發表於: 2009/7/16 9:17

Edited by cutesinnc on 2009年07月16日 09:36:38
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... ]

教育訓練中心

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