• slider image 442
  • slider image 492
  • slider image 493
  • slider image 494
  • slider image 495
  • slider image 496
:::


Browsing this Thread:   1 Anonymous Users






pic30f2020 PWM波问题
#1
新會員
新會員


查看用戶資訊
我想弄一个SPWM的波,但是现在什么也看不见,一直是高电平,这个是内部晶振32倍频的,所用调试环境MPLAB ICD2 v8.10 编译器是C30,外部有4M的晶振,再有就是PTPER时间怎么算,希望各位不吝赐教,程序如下:



#include "p30f2020.h"
#include "math.h"
#define PI 3.14159

/* Configuration Bit Settings */

_FOSCSEL(FRC_PLL)
_FOSC(CSW_FSCM_OFF & FRC_HI_RANGE & OSC2_CLKO)
_FPOR(PWRT_128)
_FGS(CODE_PROT_OFF)
_FBS(BSS_NO_FLASH)
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

int f,N,k;
double Pul,w,M;

void __attribute__((__interrupt__)) _PWM1Interrupt()
{
IFS1bits.PWM1IF = 0;


M=1.0,w=2*PI*f;

/* ~~~~~~ Load PDC1 register with initial Duty Cycle value ~~~~~~~~~~*/

Pul=(M/w)*(cos((k-1)*PI/N)-cos(k*PI/N));

PDC1=Pul*952*1000000;

k++;
}



int main()
{
N=1000,f=50,Pul=0.0,k=1;

//~~~~~~~~~~~~~~~~~~~~~~~ FRC Dither Configuration ~~~~~~~~~~~~~~~~~~~~~~~~
__builtin_write_OSCCONL(4); // Built-in function to unlock
// OSCCON register
// Writing 0x0004 sets the TSEQEN
// bit to enable FRC tune sequencer

// FRC will tune to one of the following every 8 PWM cycles
OSCTUNbits.TUN = 8; // Minimum frequency
OSCTUNbits.TSEQ1 = 10;
OSCTUNbits.TSEQ2 = 12;
OSCTUNbits.TSEQ3 = 14;
//~~~~~~~~~~~~~~~~~~~~End FRC Dither Configuration ~~~~~~~~~~~~~~~~~~~~~~~~

TRISE = 0; /* Set RE as a digital output */
PORTE=0x00;
LATE=0x00;


IOCON1bits.PENH = 1; // PWM1 outputs controlled by PWM
IOCON1bits.PENL = 1; // module
IOCON1bits.PMOD = 1; //Select Independent Output PWM mode
PTCONbits.EIPU = 1; //立即更新有效周期寄存器
PWMCON1bits.IUE = 1; //立即对有效的pdc寄存器进行更新

/*~~~~~~~~~~~~~~~~~~~~~~ End PWM Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

/* -------------------- INTERRUPTS INITIALIZATION -------------------------------------*/
IPC4bits.PWM1IP = 4; /* PWM1 Interrupt Priority */
IFS1bits.PWM1IF = 0; /* Clear PWM1 Interrupt Flag */
IEC1bits.PWM1IE = 1; /* PWM1 Interrupt Enable */

/* -------------------- PWM1 INITIALIZATION -------------------------------------------- */


TRGCON1 = 0x0000; /* PWM Trigger interrupt generated every
PWM cycle*/
/ / Trigger generated 32nsec from beginning
// of PWM period

TRIG1 = 0X0008; /* TRIGx value of 0 does not produce
a trigger. So choose smallest possible
Trigger time = TRIG1*1.05nsec = 8.4 nsec */

PWMCON1bits.TRGIEN = 1; // Enable PWM1 Trigger Interrupt,
PWMCON1bits.DTC = 2; // Primary Time Base provides timing,
// PDC1 provides Duty Cycle,
// Dead Time function is disabled,
// Enable immediate duty cycle update
PTPER = 9520;
PDC1=4761;
PHASE1 = 0; /* No Phase shift for PWM1 */
PTCONbits.PTEN = 1; // Turn ON PWM module
//PWM_LOOP();
while(1); // Infinite loop

}

發表於: 2008/5/10 17:04
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... ]

教育訓練中心

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