完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
关于dspic33ev64gs502的PWM问题
/* * File: main.c * Author: jack * * Created on 2018?8?1?, ??8:38 */ // FSEC #include "xc.h" #include "p33EP64GS502.h" _FOSCSEL(FNOSC_FRC) _FOSC(FCKSM_CSECMD & OSCIOFNC_ON) _FWDT(WDTEN_OFF) _FICD(ICS_PGD2 & JTAGEN_OFF) _FDEVOPT(PWMLOCK_OFF) int main(void) { // Configure Oscillator to operate the device at 68 MHz // Fosc = Fin*M/(N1*N2), Fcy = Fosc/2 // Fosc = 7.37*(76)/(2*2)= ~140Mhz for Fosc, Fcy = 70 MHz // Configure PLL prescaler, PLL postscaler, PLL divisor PLLFBD = 74; // M = PLLFBD + 2 CLKDIVbits.PLLPOST = 0; // N1 = 2 CLKDIVbits.PLLPRE = 0; // N2 = 2 __builtin_write_OSCCONH(0x01); // New Oscillator selection FRC w/ PLL __builtin_write_OSCCONL(0x01); // Enable Switch while(OSCCONbits.COSC != 0b001); // Wait for Osc. to switch to FRC w/ PLL while(OSCCONbits.LOCK != 1); // Wait for PLL to Lock // Setup the ADC and PWM clock for 120MHz /* Setup for the Auxiliary clock to use the FRC as the REFCLK */ // ((FRC * 16) / APSTSCLR ) = (7.37MHz * 16) / 1 = 117.9MHz ACLKCONbits.FRCSEL = 1; // FRC provides input for Auxiliary PLL (x16) ACLKCONbits.SELACLK = 1; // Aux Osc. provides clock source for PWM & ADC ACLKCONbits.APSTSCLR = 7; // Divide Auxiliary clock by 1 ACLKCONbits.ENAPLL = 1; // Enable Auxiliary PLL while(ACLKCONbits.APLLCK != 1); // Wait for Auxiliary PLL to Lock // __delay_us(50); // Errata#1 (reference:DS80000656A) ANSELB = 0x0000;//???? ANSELA = 0x0000;//???? IOCON1 =0xC800; IOCON2 = IOCON3 = 0xC800; /* Set Independent Time Bases and Phase, Edge-Aligned Mode and Independent Duty Cycles */ PWMCON1 = PWMCON2 = PWMCON3 = 0x0000; /* Configure Faults */ FCLCON2 = FCLCON1 = FCLCON3 = 0x0003; /* 1:1 Prescaler */ PTCON2 = 0x0000; /* Enable PWM Module */ PTCON = 0x8000; PTPER = 6281; //200K // Buck/Boost converter switching Frequency (350 kHz) PHASE1 = 0; PHASE2 = 0; PHASE3 = 0;//300; /* Set Duty Cycles */ PDC1 = 240; PDC2 = 240; PDC3 = 240; /* Set Dead Time Values */ DTR1 = 0; DTR2 = 0; DTR3 = 0; ALTDTR1 = 0; ALTDTR2 = 0; ALTDTR3 = 0; PTCONbits.PTEN = 1; // Enable the PWM while(1) { } // End of While loop } 代码是使用例程改的,pwm波形很混乱,占空比和频率都不对。不知道哪里出了问题。求大神指导。。。。 |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
求解外围电路实现的是4脚给持续低电平复位并正常工作,高电平不工作的原因
2069 浏览 1 评论
3378 浏览 3 评论
PIC1946程序有一个变量在运行过程中恢复初始值其他变量保持不变
2319 浏览 2 评论
2744 浏览 0 评论
PIC16F1825的RC5引脚,在主程序中操作无效,在中断中可以改变是为什么?
3991 浏览 5 评论
938浏览 0评论
用XC8编译PIC18F25K80时提示下面Error,求怎么解决这个问题
6328浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-10 11:22 , Processed in 0.555240 second(s), Total 44, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号