完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
谢谢你的阅读。所以我今天收到了一个心跳信号板,并尝试设置我的PIC.PIC18F1320的输入。有ToKi的PIN RA4。希望我把它设置得很近,但我知道我的价值观是错误的,因为我总是每隔15秒就得到一个红色LED灯。只要我能使我的计时器/计数器正确配置,我就调整我的BPM值。*重要的一点是心跳板工作得很好,输出数字脉冲,所以它为每个心跳脉冲1次(如果说正确的话,LOL)。使用EasyPultV1.1,无模拟输出!
以上来自于百度翻译 以下为原文 thanks for reading. So I received a heartbeat signal board in today and trying to setup the input of my pic. PIC18f1320. Has TOCKI on pin RA4. Hoping I set this up close, but I know my values are incorrect because I keep getting a red LED lighting up every 15secs. So long as I can get my TIMER/COUNTER configured correctly I'll adjust my bpm values. ** An important mention is the heartbeat board works very well and outputting DIGITAL pulses, so it pulses 1 time for each heartbeat (if said that correctly, lol). Using the EasyPulse v1.1, NO ANALOG output! #define _XTAL_FREQ 4000000 #include #include #include #include #pragma config MCLRE=OFF,WDT=OFF,LVP=OFF unsigned short pulserate, pulsecount; unsigned int i; void Heartbeat(); void Delay_Ms(unsigned int delay); int main(void){ TRISAbits.RA0 = 0; // RED LED TRISAbits.RA1 = 0; // GREEN LED TRISAbits.RA4 = 1; // Heartbeat Counting T0CONbits.T08BIT = 1; // 8bit config T0CONbits.T0CS = 0; // rising edge T0CONbits.PSA = 1; while(1){ Heartbeat(); __delay_ms(10); } } void Heartbeat(){ PORTAbits.RA0 = 0, PORTAbits.RA1 = 0; // LEDs OFF pulserate = 0; TMR0=0; // Begin counting the pulse T0CONbits.TMR0ON = 1; Delay_Ms(105); // 15 secs of counting T0CONbits.TMR0ON = 0; pulsecount = TMR0; // updating variable with count value pulserate = pulsecount*4; // pulsecount(15secs worth) * 4 = 1 minute of sampling "BPM" if((pulserate >60) || (pulserate < 180)){ PORTAbits.RA1 = 1; // GREEN LED, alive and kicking Delay_Ms(15);} if((pulserate <= 60)||(pulserate >= 180)){ PORTAbits.RA0 = 1; // RED LED, dead Delay_Ms(15);} } void Delay_Ms(unsigned int delay){ do{ __delay_ms(1);} while (--delay);} |
|
相关推荐
19个回答
|
|
有几个建议:你应该设置AdCON1寄存器将PoTa引脚放入数字模式,默认为模拟。总是写入LATX寄存器,而不是PORTX寄存器:(从PORTX读取),而不是选择内部OSC。作为Time0的源:您想要:对于Rb4的外部输入,用于上升边沿触发器,您需要:
以上来自于百度翻译 以下为原文 A couple of suggestions: You should set the ADCON1 register to put the PORTA pins into digital mode, they default to analog. Always write to the LATx register, not the PORTx registers: (read from PORTx) LATAbits.LATA1 = 0; instead of PORTAbits.RA1 = 0; This selects the internal osc. as the source for Timer0: T0CONbits.T0CS = 0; // rising edge you want: T0CONbits.T0CS = 1; // external clock for external input on RB4 For rising edge trigger you want: T0CONbits.T0SE = 0; // rising edge |
|
|
|
杰克,我纠正了你提到的,最后一部分关于上升边沿触发器,希望我做了正确的那部分。重新编程它,我得到的是绿色LED,其次是红色的LED。
以上来自于百度翻译 以下为原文 Jack, I corrected what you mentioned, the last part regarding Rising Edge Trigger, hope I did that part right. Re-programmed it and all I get is the green LED, followed by the red LED. #define _XTAL_FREQ 4000000 #include #include #include #include #pragma config MCLRE=OFF,WDT=OFF,LVP=OFF unsigned short pulserate, pulsecount; unsigned int i; void Heartbeat(); void Delay_Ms(unsigned int delay); int main(void){ TRISAbits.RA0 = 0; // RED LED TRISAbits.RA1 = 0; // GREEN LED TRISAbits.RA4 = 1; // Heartbeat Counting ADCON1 = 0b01111111; // port A digital T0CONbits.T08BIT = 1; T0CONbits.T0CS = 1; // external clock T0CONbits.PSA = 1; T0CONbits.T0SE = 0; // rising edge trigger while(1){ Heartbeat(); __delay_ms(10); } } void Heartbeat(){ LATAbits.LATA0 = 0, LATAbits.LATA1 = 0; pulserate = 0; TMR0=0; // Begin counting the pulse (p49) T0CONbits.TMR0ON = 1; Delay_Ms(105); // Wait 15 secs while count adds up pulses T0CONbits.TMR0ON = 0; pulsecount = TMR0; // updating variable with count value pulserate = pulsecount*4; // pulsecount(15secs worth) * 4 = 1 minute of sampling "BPM" if((pulserate > 60) || (pulserate < 180)){ LATAbits.LATA1 = 1; // GREEN LED, alive and kicking Delay_Ms(15);} if((pulserate <= 60)||(pulserate >= 180)){ LATAbits.LATA0 = 1; // RED LED, dead Delay_Ms(15);} } void Delay_Ms(unsigned int delay){ do{ __delay_ms(1);} while (--delay);} |
|
|
|
|
|
|
|
我知道,但我算15秒:-我的延误吗?
以上来自于百度翻译 以下为原文 I know it does, but I'm counting 15 secs :-/ is my delays off ? |
|
|
|
嗯?如果你计数105个1毫秒的很多,你得到0.105秒,也就是一秒钟的一秒,而不是15秒。
以上来自于百度翻译 以下为原文 Huh? If you count 105 lots of 1 millisecond, you get 0.105 seconds, i.e. a fraction of a second, not 15 seconds. |
|
|
|
|
|
|
|
我理解数学,但每一个周期大约花费15秒从绿色LED灯,关闭,然后灯备份。
以上来自于百度翻译 以下为原文 I understand the math, but each cycle is taking approx 15 secs from time green LED lights up, turns off then lights back up. |
|
|
|
我不知道FRQ是怎么运行的,我想它是4M。试图找出如何调整它现在。
以上来自于百度翻译 以下为原文 I do not know what the freq is running no, I assumed it was 4M. Trying to figure out how to adjust that right now |
|
|
|
你使用内部OSC吗?还是外部晶体?
以上来自于百度翻译 以下为原文 Are you using the internal osc. or an external crystal? |
|
|
|
|
|
|
|
这条线告诉编译器你的PIC运行在4MHz,这是它用来计算它的延迟循环。它没有设置你的PIC运行的速度。你的配置线根本不选择时钟,所以你将得到默认设置的任何PIC。也请注意,你没有。需要任何这些线路:
以上来自于百度翻译 以下为原文 This line #define _XTAL_FREQ 4000000 is telling the compiler that your PIC is running at 4MHz, which is what it uses to calculate its delay loops. It does NOT set the speed your PIC runs at. Your config line is not selecting a clock at all, so you will be getting whatever the default setting is for that PIC. Also note, you don't need any of these lines: #include #include #include |
|
|
|
那么它不运行在4兆赫。请阅读数据表。振荡器模块上的部分。时钟将默认为低得多的频率。记住,xxTaluFReq设置只是告诉编译器PIC时钟运行的速度有多快,它没有设置它!
以上来自于百度翻译 以下为原文 Well then it is NOT running at 4 Mhz. PLEASE read the datasheet. The section on the oscillator module. The clock will default to a much lower frequency then that. Remember that the _XTAL_FREQ setting is only to tell the COMPILER how fast the pic clock is running, it DOES NOT set it! |
|
|
|
根据数据表,“FoC= 0B11xx”(这将是默认的),选择“外部RC振荡器,在Ra6上的CKO函数”,您可能需要“InTiO2内部RC振荡器,RA6端口功能和RA7端口功能”,然后写入OSCCon寄存器来选择您的速度。
以上来自于百度翻译 以下为原文 According to the datasheet, "FOSC=0b11xx" (which will be the default), selects "External RC oscillator, CLKO function on RA6" You probably want "INTIO2 Internal RC oscillator, port function on RA6 and port function on RA7" and then write to the OSCCON register to select your speed. |
|
|
|
|
|
|
|
另外,请看配置寄存器上的部分,具体是配置1h。这设置了上电时所选的时钟源,默认为外部RC模式。如果你不改变它,你是幸运的PIC运行在所有。
以上来自于百度翻译 以下为原文 Also look at the section on the configuration registers, specifically CONFIG1H. This sets the selected clock source on power-up and the default is for the EXTERNAL RC mode. If you do not change it you are lucky the pic is running at all. |
|
|
|
还有一些建议:对于所有的配置选项,总是有一个实用的设置,它很容易依赖默认值(如你在这里看到的)。
以上来自于百度翻译 以下为原文 Some more advice: ALWAYS have #pragma settings for ALL the configuration options, it is error prone to rely on defaults (as you may have seen here). |
|
|
|
好的,我纠正了FRQ,OSCCon=0B01100110,并且改变了在DelaySMS(15000)的计数之间的延迟,并且我也得到了15秒,奇怪的是另一个给出了相同的时间,很高兴这个部分被修正了。看来我只是得到绿色LED照明。
以上来自于百度翻译 以下为原文 Ok I corrected the freq, OSCCON = 0b01100110; And changed the delay in between the counting at Delay_Ms(15000) and I'm getting 15 secs as well, strange the other was giving same time, glad this part is corrected. Seems I'm only getting green LED lighting up. |
|
|
|
您是否更改了CONTH1H设置?如果没有,你没有正确地改变时钟选择。有一个用于编译FoSC选择的Apple PrimaMac配置,确保它被设置为正确的值fto使用内部振荡器块。
以上来自于百度翻译 以下为原文 Did you change the CONFIG1H setting? If not you have NOT changed the clock selection correctly. There is a #pragma config setting to set the FOSC selection, make sure it is set to the proper value fto use the internal oscillator block. |
|
|
|
我必须跑出门去做一个差事,我一定会把它修好并报告回来,再次感谢杰克。
以上来自于百度翻译 以下为原文 I have to run out the door for an errand, I will certainly fix that and report back here, thanks again Jack |
|
|
|
只有小组成员才能发言,加入小组>>
4814 浏览 9 评论
1823 浏览 8 评论
1743 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
2949 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2055 浏览 5 评论
452浏览 1评论
1107浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
355浏览 0评论
260浏览 0评论
LAN9252使用SQI通信,进行数字复位后读BYTE_TEST异常
1777浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-4-19 23:48 , Processed in 1.185135 second(s), Total 88, Slave 76 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号