完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我在MPLAB X IDE V3.30中使用模拟器来测试程序的定时,这样我就可以在1秒的时间内闪动一个LED。我在代码中设置了一个断点,其中LED改变状态,然后我在MPLAB中使用秒表来查看断点之间已经过的时间。在模拟器中,我得到了1.048576秒,但是当我把程序发送到我的PIC16LF606时,闪烁大约发生了64秒。我用看门狗和time1也试过了,他们在MPLAB模拟器上跑得更快,在PIC上。有人知道这是为什么吗?代码如下…
以上来自于百度翻译 以下为原文 I used the simulator in MPLAB X IDE v3.30 to test the timing of my program so I can flash a LED at 1 second intervals. I put a break point in the code where the LED changes state and then I used the Stopwatch in MPLAB to see the time that has passed between breaks. In the simulator I was getting 1.048576 seconds but when I sent the program to my PIC16LF1906 the flashing was happening at about 64 seconds. I tried this with the Watch dog and Timer1 too and they both ran MUCH faster in MPLAB Simulator vs on the PIC. Anyone have knowledge of why this is happening? Code if below... // PIC16LF1906 Configuration Bit Settings // 'C' source line config statements #include // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. // CONFIG1 #pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin) #pragma config WDTE = ON // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LPBOR = OFF // Low-Power Brown-out Reset (Low-Power BOR is disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) //Always read the PORT //Always write the LAT //Variables********************************************************************* char flashCount;//incrament with timer 0 void main(void) { //Define IO pins TRISCbits.TRISC0 = 0;//output //Setup interrupts INTCONbits.GIE = 1;//enable all interrupts INTCONbits.PEIE = 1;//enable Peripheral interrupts (timer1, AD, Rx, Tx, LCD) INTCONbits.TMR0IE = 0;//disable timer0 interrupt INTCONbits.INTE = 0;//disable INT External interrupt INTCONbits.IOCIE = 1;//enable interrupt on change (port B) PIE1bits.TXIE = 0;//Tx interrupt disabled PIE1bits.TMR1IE = 1;//Timer 1 interrupt IOCBPbits.IOCBP0 = 1;//PortB0 interrupt on change enabled IOCBPbits.IOCBP1 = 1;//PortB1 interrupt on change enabled IOCBNbits.IOCBN0 = 1;//PortB0 interrupt on change enabled IOCBNbits.IOCBN1 = 1;//PortB1 interrupt on change enabled //timer0 setup OPTION_REGbits.TMR0CS = 0;//timer 0 clock source internal instruction clock (Fosc/4)) OPTION_REGbits.PSA = 0;//Prescaler assigned to timer 0 OPTION_REGbits.PS = 0b111;//prescale 1:256 //watch dog timer setup WDTCONbits.WDTPS = 0b10010;//256 second interval 4.27 minutes //WDTCONbits.WDTPS = 0b01101;//8 second interval //Timer1 setup T1CONbits.T1CKPS = 0b11;//timer 1 prescale 1:8 T1CONbits.TMR1CS = 0b00;//timer 1 clock source instruction clock(Fosc/4) OSCCONbits.IRCF = 0b0000;//31KHz, clock determined in configeration word 1 //timer1 about 524ms //timer0 about 65ms while(1){ INTCONbits.TMR0IE = 1; //enable timer0 interrupt } return; } void interrupt Interrupts(void){ if(INTCONbits.TMR0IF == 1 && INTCONbits.TMR0IE == 1){ //Timer 0 overflow****************************************************** INTCONbits.TMR0IF = 0;//clear the interrupt flag if(flashCount == 0x10){//about 1 second delay flashCount = 0;//reset the count LATCbits.LATC0 = !PORTCbits.RC0;//invert LED } flashCount++; } } |
|
相关推荐
5个回答
|
|
|
是否配置OSCCon寄存器来选择内部时钟源和正确的频率?
以上来自于百度翻译 以下为原文 Did you configure the OSCCON register to select internal clock source and correct frequency? |
|
|
|
|
|
嗨,迈克,当你使用模拟器时,我认为它实际上忽略了你的语用等,并使用你在模拟选项卡中定义的核心频率。确保你在模拟器中有正确的*核心频率,否则你会得到奇怪的结果。*我不确定模拟器中的PIC16核心频率是指指令速率还是循环速率。不同的MCU有不同的隐式除数/乘法器,在指定该数时必须考虑。
以上来自于百度翻译 以下为原文 Hi Mike, When you're using the simulator I think it actually ignores your pragmas etc. and uses a core frequency you define in the simulation tab. Make sure that you have the correct* core frequency set in the simulator or you will get odd results. *I am not sure if the PIC16 core frequency in the simulator refers to the instruction rate or the cycle rate. Different MCUs have different implicit divisors/multipliers you have to take in to account when specifying that number. |
|
|
|
|
|
我确实有OSCCon位设置。看起来它忽略了这些设置,我需要在模拟器设置中更改它们。谢谢你的回答!
以上来自于百度翻译 以下为原文 I do have the OSCCON bits set. Looks like it ignores those setting and I need to change them in the simulator settings. Thanks for the answer! |
|
|
|
|
|
我确实有OSCCon位设置。看起来它忽略了这些设置,我需要在模拟器设置中更改它们。谢谢你的回答!我认为Katela问的是,物理芯片是否在正确的频率上运行,因为这是模拟器不匹配硬件的另一半。我通常通过使用UART与PC进行通信来测试我的集成电路在正确的频率下运行。如果你离开了2或4的因素,这是很明显的。我很高兴关于模拟器设置的说明是有帮助的,因为这是另一半,但是两者都需要调整来匹配。
以上来自于百度翻译 以下为原文 I do have the OSCCON bits set. Looks like it ignores those setting and I need to change them in the simulator settings. Thanks for the answer! I think Katela was asking about whether the physical chip was running at the correct frequency, since this is the other half of the question when the simulator does not match the hardware. I typically test that my IC is running at the correct frequency by using a UART to communicate with the PC - if you are off by a factor of 2 or 4 it is obvious very quickly. I'm glad the note about the simulator settings was helpful as that is the other half, but both could need adjustment to match. |
|
|
|
|
|
模拟器甚至不想通过振荡器和配置设置来找出FCYC是什么。(通过1800个左右的设备模拟器支持太多不同的振荡器配置),但是你可以告诉模拟器Fcyc最终在项目属性中。(见附件)默认值是1兆赫,它解释你看到的秒表。
以上来自于百度翻译 以下为原文 The simulator doesn't even attempt to figure out what the Fcyc is via the oscillator and configuration settings. (Way too many different oscillator configurations across the 1800 or so devices simulator supports.) But you can tell the simulator what Fcyc ends up being in the project properties. (See attached.) The default value is 1 MHz, which explains what you see via the stopwatch. Attached Image(s) |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 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 10:30 , Processed in 0.715989 second(s), Total 82, Slave 65 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2426