完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
对不起,下面的代码现在是一个工作示例,实际代码非常大,但是我不明白为什么TrM2没有运行到计算的周期。我正在寻找…//定时器2 - 100点击@ 48 MHz=2.08333 USEC=预分频器1:1,后缩放器1:1,8位,预加载0xE8但0xE8在检查我的示波器时是错误的,0xDa几乎是点亮的。我是否正确地计算了TrM2?它可以是我的示波器,但它是正确的,当它检查了内置的测试。非常感谢杰夫/。它,预加载0xe8//用于产生输出频率//----pRI1BIT.TMR2IE=1;IPR1BITS.TMR2IP=1;T2CONtiTS。T2CKPS1=0;和/ 2位预分频值:00:PS=1,T2CONBITS。T2CKPS0= 0;;/01:PS= 4,1X:PS= 16 T2CONTITS。T2OutPS3= 0;//On位后尺度值:y=1, 0001=2,T2OutPS2=0;/ 0010=3, 0011=4, 0100=5, 0101=6, 0110=7,T2CONTITS。T2OutPS1=0;错误的周期。//DA几乎是精确的。(一)(PIP1BIT.TMR2IE=1){PIR1BIT.TMR2IF;T2CONTITS。TMR2ON=1;// 0=转定时器断开,1=转定时器为/}。= 0;//清除溢出位IH15A AcCOM+=IH16FRQHZ;IF(IH15AcAc≫= ToGlEX){IH15Y-ACOMUM=ToGlEX;//十进制BReSENAMM减法,保持剩余的LeDyG4R4FRYQ^ =切换;/ /切换输出引脚使频率} /*配置为48 MHz / /IrCF和LT;2:0MHz和:内部RC振荡器频率选择位/ /(111 MHz=Hfimtoc)/(011=Hfimtoc/ 16(1 MHz)/ / 110=Hfimtoc/2(8 MHz)//010=Hfimtoc/32(500 kHz)//101=Hfimtoc/South-(αMHz)//=Hfimtoc/Al-(μkHz)//=Hfimtoc/O-(αMHz)//设置48 MHz,不要忘记设置延迟XTalthFRIQ设置延迟例程OSCTUNE=0x80;// 1000 0000 3XOSCCon=0x70;/ / 0111 0111 0000 MHz OSCCON2= 0x10;//0001 0000 PPL启用ACXEnable中断(空隙);而(1){CrRWdTh())。…}
以上来自于百度翻译 以下为原文 Sorry, the code below is now a working example, the real code is very large, but I do not understand why the TRM2 is not running to the calculated period. I'm Looking for ... // Timer 2 - 100 clicks @ 48MHz = 2.08333 usec = Prescaler 1:1, Postscaler 1:1, 8 Bit, preload 0xE8 But 0xE8 is wrong when checked against my oscilloscope, 0xDA is almost spot on. Have I calculated TRM2 incorrectly? It could be my cheep oscilloscope, but its correct when checked against the inbuilt test. Many thanks Geoff. /*============================*/ void AC_Enable_Interrupts(void) /*============================*/ { //---------- // Timer 2 - 100 clicks @ 48MHz = 2.08333 usec = Prescaler 1:1, Postscaler 1:1, 8 Bit, preload 0xE8 // Used to generate the output frequency //---------- PIR1bits.TMR2IF = 1; PIE1bits.TMR2IE = 1; IPR1bits.TMR2IP = 1; T2CONbits.T2CKPS1 = 0; // 2 bit Prescale value: 00: PS = 1, T2CONbits.T2CKPS0 = 0; // 01: PS = 4, 1x: PS = 16 T2CONbits.T2OUTPS3 = 0; // 4 bit Postscale value: 0000 = 1, 0001 = 2, T2CONbits.T2OUTPS2 = 0; // 0010 = 3, 0011 = 4, 0100 = 5, 0101 = 6, 0110 = 7, T2CONbits.T2OUTPS1 = 0; // 0111 = 8, 1000 = 9, 1001 = 10, 1010 = 11, 1011 = 12, T2CONbits.T2OUTPS0 = 0; // 1100 = 13, 1101 = 14,1110 = 15, 1111 = 16 TMR2 = 0x0; PR2 = 0xDA; // Should be E8, but this produces the wrong period. // DA is almost exact. T2CONbits.TMR2ON = 1; // 0 = turn timer off, 1 = turn timer on } /*==================================================*/ void interrupt IH_Capture_Timers(void) /*==================================================*/ { if (PIR1bits.TMR2IF == 1) { // Enabled if (PIE1bits.TMR2IE == 1) { PIR1bits.TMR2IF = 0; // Clear overflow bit IH15_Accum += IH16_FreqHz; if (IH15_Accum >= TOGGLEx) { IH15_Accum -= TOGGLEx; // decimal bresenham subtraction, keep remainder LED_G_RA4_Freq ^= Toggle; // toggle output pin to make frequency } } /*============*/ void main(void) /*============*/ { // Oscillator internal configuration for 48MHz // IRCF<2:0>: Internal RC Oscillator Frequency Select bits // 111 = HFINTOSC - (16 MHz) // 011 = HFINTOSC/16 - (1 MHz) // 110 = HFINTOSC/2 - (8 MHz) // 010 = HFINTOSC/32 - (500 kHz) // 101 = HFINTOSC/4 - (4 MHz) // 001 = HFINTOSC/64 - (250 kHz) // 100 = HFINTOSC/8 - (2 MHz) // set 48MHz , don't forget to set _XTAL_FREQ is set the delay routine OSCTUNE = 0X80; // 1000 0000 3XP OSCCON = 0X70; // 0111 0000 16mhZ OSCCON2 = 0X10; // 0001 0000 PPL enabled AC_Enable_Interrupts(void); while (1) { CLRWDT(); . . . } } |
|
相关推荐
3个回答
|
|
16兆赫INT.OSC。和一个3X的PLL,你得到一个48 MHz的FoSC的指令时钟(FoSC / 4)的12兆赫或83.2纳秒每分钟2计数。Time2使用FoC/4指令时钟进行计数。0xDa的PR2值应该导致大约3.08个USEC的Time2周期,我想……编辑:我认为这段时间实际上是在18个USEC,这对我来说有点早。
以上来自于百度翻译 以下为原文 With 16 Mhz int. osc. and a 3x PLL you get 48 Mhz Fosc for an instruction clock (Fosc/4) of 12 Mhz or 83.2 nsec per Timer2 count. Timer2 uses the Fosc/4 instruction clock to count. A PR2 value of 0xDA should result in a Timer2 period of around 3.08 usec I think.... EDIT: I think the period would actually be around 18 usec, it was a bit early in the morning for me..... |
|
|
|
目前还不清楚你想要的是什么时期。你的评论说2.08U.PR2= 0xE8(232)=&;(232 + 1)/16MHz=14563USEC PrPr2= 0xDa(218)=&;(218 + 1)/16MHz=13688 USEC周期振荡器是+/-2%,除非你使用ACT,所以附加不确定性。
以上来自于百度翻译 以下为原文 It's unclear what period you want. Your comment says 2.08us. PR2 = 0xe8 (232) => (232+1)/16MHz = 14.563usec period PR2 = 0xda (218) => (218+1)/16MHz = 13.688usec period oscillator is +/-2% unless you're using ACT, so additional uncertainty. |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5184 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3179 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2229 浏览 5 评论
739浏览 1评论
626浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
511浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
637浏览 0评论
535浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 08:02 , Processed in 1.339487 second(s), Total 80, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号