完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
我在看微芯片提供的下面的代码,我对高亮的线路感到困惑。根据我的系统时钟=120 MHZ指令时钟=120/4=30MHZ指令时间=1/30=0.033 3US=33.3NSPTPER=10Us/0.033 3US=300,但是有书面PTPL=9615//不能理解一个计数是C。在1.04nS中,请只关注高亮线。
以上来自于百度翻译 以下为原文 I am viewing the following code provided from microchip and I am confused on highlighted lines . according to me The system clock = 120MHz Instruction clock = 120/4=30MHz Instruction time = 1/30=0.0333us=33.3ns PTPER=10us/0.0333us=300 but there is written PTPER=9615 // can't understand how one count is completed in 1.04ns. please focus only highlighted lines #include "p33FJ06GS202.h" /* Configuration Bit Settings */ _FOSCSEL(FNOSC_FRC) _FOSC(FCKSM_CSECMD & OSCIOFNC_ON) _FWDT(FWDTEN_OFF) _FPOR(FPWRT_PWR128) _FICD(ICS_PGD2 & JTAGEN_OFF) void init_PWM(); void init_ADC(); int main() { /* Configure Oscillator to operate the device at 40Mhz Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 Fosc= 7.37*(43)/(2*2)=80Mhz for Fosc, Fcy = 40Mhz */ /* Configure PLL prescaler, PLL postscaler, PLL divisor */ PLLFBD=41; /* M = PLLFBD + 2 */ CLKDIVbits.PLLPOST=0; /* N1 = 2 */ CLKDIVbits.PLLPRE=0; /* N2 = 2 */ __builtin_write_OSCCONH(0x01); /* New Oscillator FRC w/ PLL */ __builtin_write_OSCCONL(0x01); /* Enable Switch */ while(OSCCONbits.COSC != 0b001); /* Wait for new Oscillator to become FRC w/ PLL */ while(OSCCONbits.LOCK != 1); /* Wait for Pll to Lock */ /* Now setup the ADC and PWM clock for 120MHz ((FRC * 16) / APSTSCLR ) = (7.37 * 16) / 1 = ~ 120MHz*/ ACLKCONbits.FRCSEL = 1; /* FRC provides input for Auxiliary PLL (x16) */ ACLKCONbits.SELACLK = 1; /* Auxiliary Oscillator 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 */ init_PWM(); init_ADC(); IPC3bits.ADIP = 4; /* ADC Interrupt Priority */ IFS0bits.ADIF = 0; /* Clear ADC Interrupt Flag */ IEC0bits.ADIE = 1; /* ADC Interrupt Enable */ ADCONbits.ADON = 1; /* ADC is turned ON */ PTCONbits.PTEN = 1; /* Turn ON PWM module */ while(1) { Nop(); } } void init_PWM() { PTPER = 9615; /* PTPER = ((10us) / 1.04ns) = 9615, where 10us is the PWM period and 1.04ns is PWM resolution. */ PDC1 = 2404; /* PWM1 duty cycle (2.5us / 1.04ns) */ IOCON1bits.PENH = 1; /* PWM1 outputs controlled by PWM */ IOCON1bits.PENL = 1; IOCON1bits.PMOD = 0; /* Choose Complementary PWM mode */ PWMCON1bits.DTC = 1; /* Negative Dead time enabled */ /* Negative deadtime = 130nsec */ DTR1 = 63; /* Deadtime = (65ns / 1.04ns) where 65ns is desired deadtime */ ALTDTR1 = 63; /* ALTDeadtime = (65ns / 1.04ns) where 65ns is desired deadtime */ TRGCON1bits.TRGDIV = 1; /* Trigger output every 2nd trigger event */ TRIG1 = 4808; /* Trigger generated in the middle of the PWM period */ } void init_ADC() { ADPCFGbits.PCFG5 = 0; /* Choose AN5 as analog input */ ADCPC1bits.IRQEN2 = 1; /* Enable interrupt request */ ADCPC1bits.TRGSRC2 = 4; /* Trigger ADC pair 2 conversion on PWM1 generator */ ADSTATbits.P2RDY = 0; /* Clear pair 2 data ready bit */ ADCONbits.FORM = 0; /* Choose integer data format */ ADCONbits.ORDER = 0; /* Even numbered input is converted first */ ADCONbits.SEQSAMP = 1; /* Sequential sampling enabled */ ADCONbits.ADCS = 7; /* ADC clock = FADC/14 */ } void __attribute__ ((__interrupt__, no_auto_psv)) _ADCInterrupt(void) { unsigned int tmp; IFS0bits.ADIF = 0; /* Clear ADC interrupt flag */ ADSTATbits.P2RDY = 0; /* Clear pair 2 data ready bit */ tmp = ADCBUF5*8; /* Scaling of AN5 voltage */ /* This ensures a significant change in duty cycle based on ADC conversion value */ if (tmp < 500) tmp = 500; /* Applying boundary conditions */ /* The boundary conditions ensure that the duty cycle does not become less than deadtime setting 500/8 >= Deadtime */ PDC1 = tmp; /* Update PWM1 duty cycle */ } |
|
相关推荐
5个回答
|
|
|
你到底在哪里找到这个密码的?正如你所说的,一个1.04 ns的周期意味着一个961.5兆赫的时钟,这是荒谬的。
以上来自于百度翻译 以下为原文 Where exactly did you find this code? As you say, a period of 1.04 ns implies a clock of 961.5 MHz, which is ridiculous. |
|
|
|
|
|
代替引用样本代码中提供的计算,参考数据表公式来计算PTPER寄存器。如果你使用下面的公式,希望你能理解9615是如何出现的。PTP= =((ACLK×8×期望PWM周期)/PWM输入时钟预分频器(PCLKDIV & lt;2:0&gt))8)在哪里,ACLK=(RIFCK*M1/N)引用数据表以进行更详细的解释(页面:47)http://WW1.Microchip .com /…EVICEDOC/7000
以上来自于百度翻译 以下为原文 Instead of refering the the provided calculation in sample code, refer the data sheet formula to calculate PTPER register. If you use the below formula, hope you will understand how 9615 is coming. PTPER =( ( (ACLK * 8 * Desired PWM Period ) / PWM Input Clock Prescaler Divider (PCLKDIV<2:0>) ) - 8) where, ACLK = (REFCLK * M1 / N) Refer datasheet for more detailed explanation (Page: 47) http://ww1.microchip.com/...eviceDoc/70000323f.pdf |
|
|
|
|
|
感谢Munsi.KUMAR发布了非常有用的链接来解决这个问题。我没有意识到PWM有它自己的振荡器,它有它自己的乘法器(APLL X16)。因此,如果它的RIFCK是60MHz(这可以从PASCLK通过复用PLL)得到,那么用于PWM的ACLK可以是60×16=960MHz,并且可以达到1.04Ns的分辨率。
以上来自于百度翻译 以下为原文 Thanks manish.kumar for posting very useful link to resolve this problem. I did not realize that PWM has its own oscillator which has its own multiplier(APLL x16). So if its REFCLK is 60MHz (which could be derived from POSCCLK by multplying its PLL)then ACLK for PWM could be 60*16=960MHz and a resolution of 1.04ns could be achieved. |
|
|
|
|
|
PIC30将系统时钟除以4为指令时钟,PIC33和PIC24除以2。我相信?
以上来自于百度翻译 以下为原文 The Pic30 divides the system clock by 4 for instruction clock The Pic33 and Pic24 divide by 2. I believe? |
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 06:38 , Processed in 0.698583 second(s), Total 80, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1599