完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我是PIC编程的新手。我正在编程一个PIC16F1615单片机,很好奇我怎么能写一个代码,把ADC的时间输入5秒。我可以调整计时器Primar,Fosc,并获得PR2值调整为5s,我在编写C代码在MPLAB有困难。我的问题陈述:当电压在2V和3V之间时,它必须保持在5秒的范围内,如果不是,那么代码将保持复位直到满足这个条件。如有任何帮助,我们将不胜感激。谢谢您!
以上来自于百度翻译 以下为原文 Hi, I am new to the world of PIC programming. I am programming a PIC16F1615 MCU, was curious to know how can i write a code to time the ADC input for 5 seconds. I can adjust the timer prescalar, Fosc and get the PR2 value to adjust for 5s, I am having difficulty in writing the C code in MPLAB. My problem statement: As the voltage is between 2V and 3V, it has to be held in that range for 5 seconds, if not then the code will keep resetting until this condition is met. Any help would be appreciated. Thank you! |
|
相关推荐
10个回答
|
|
这意味着什么?你想测量某事发生的时间吗?什么“保持”电压?你是说如果电压不符合这个条件,你想让代码“重置”,或者你说现在正在发生,你想修复它吗?
以上来自于百度翻译 以下为原文 What does this mean? Do you want to measure how long something occurs for? What "holds" the voltage? Are you saying that you want the code to "reset" if the voltage doesn't meet that condition, or are you saying that this is happening now, and you want to fix it? |
|
|
|
谢谢你的答复,我很抱歉不清楚。我希望电压保持在范围(在2V和3V之间至少5s和最大10s),如果满足这些条件,那么我将执行一个不同的功能,如果上述条件不正确,那么代码将不得不重置。我很难在MPLAB中编写一个C代码来做同样的事情。我已经成功地完成了ADC工作和定时器工作分开,但不能写“如果”的条件ADC电压范围和计时器一起。
以上来自于百度翻译 以下为原文 Thank you for your reply and I am sorry to be unclear. I want the voltage to hold in the range (between 2V and 3V for atleast 5s and maximum 10s), if these conditions are met, then I will execute a different function, if the above conditions are not true then the code will have to RESET. I am having difficulty writing a C code in MPLAB to do the same. I have successfully made the ADC work and timer work separately but not able to write 'if' conditions for both ADC voltage range and timer together. |
|
|
|
嗯,为什么“重置”?你到底需要什么?无论如何,显示你的当前代码…
以上来自于百度翻译 以下为原文 Mmmm, why "reset"? What do you need exactly? Anyway, show your current code... |
|
|
|
如果((伏特&2)&;(伏特& lt;=3)&&;(时间<5)){} &&;是逻辑的,是逻辑或复位意味着重置CPU,你不想这样做,你想跨越测试,我假设
以上来自于百度翻译 以下为原文 if((volts > 2) && (volts <=3) && (time < 5) ) { } && is Logical AND || is Logical OR Reset means resetting the CPU, you do not want to do that You want to strat the test over ,I assume |
|
|
|
嗨,PIC16F1615充满了强大的CIP(核心独立外设)。你想做什么,我相信可以通过结合使用内部可编程逻辑门与各种外设结合的外围设备自动完成。你的图片:HTTP://www. McCHIP.COM/MCC.有许多技术概要展示了使用CIP的例子。在你的情况下,你需要2个比较器,DAC,FVR,CLC,HLT的组合达到5 SI,相信这个应用程序CNA只使用初始化代码和AlMSOT什么都不做。在主循环中;=)
以上来自于百度翻译 以下为原文 Hi, The PIC16F1615 is packed with powerful CIP (Core Independant Peripherals). What you want to do could I believe be done automatically by combining peripherals using the internal programmable logic gates combined with the various peripherals. To do this I recommend using MCC plugin to help you configure your PIC : http://www.microchip.com/MCC There are many technical briefs showing examples to use CIPs. In your case you'll need the 2 comparators, the DAC, the FVR, the CLCs, a combination of HLTs to reach 5 s I believe this application cna be done using only initialization code and almsot nothing in the main loop ;=) Regards |
|
|
|
我会完全阻止这一点,但我同意这很有趣。
以上来自于百度翻译 以下为原文 I would COMPLETELY DISCOURAGE this but yep I agree it can be interesting |
|
|
|
谢谢大家的回复!我很抱歉这么晚回复。@ CHIZIAG,如果条件不满足,代码需要重置,这是我们的问题的一部分,这个条件只是子例程的一部分,通过重置,我的意思是,代码需要从主函数重新开始,并降到这个子例程中,这些CON这是我迄今为止编写的子例程,而不是按设计的:如果(PrI1BIT.TMR1IF=1){No.++;AdCON0BIT。GO=1;//开启ADC捕获(AdCON0BITE.GO=1)//ADC获取完整的输入项=ADRESL+((ADRESH和0x03)& lt;0x08);/存储转换二进制值IF(InPvV & Gt;and & and Apple and &&计数&G&Apple and Lt.lt;200)//Ct & Gt;166是计数大于5S{LaTcBIT。LATC4=1;否则,如果(计数和gt;200){LaTcButs.LATC4= 0;ReSET();计数=0;} PrI1BIT.TMR1IF=0;
以上来自于百度翻译 以下为原文 Thank you for your reply everyone! I am sorry for the late reply. @CinziaG, if the conditions are not met, the code needs to be reset, that is the part of our problem, this condition is only a part of a sub-routine, by reset i mean, the code needs to start again from the main function and come down to this sub-routine where these conditions will be tested. This is the sub-routine i have written so far and not working as designed: if(PIR1bits.TMR1IF == 1) { count++; ADCON0bits.GO=1; //Turning on ADC acquisition while(ADCON0bits.GO==1) //ADC acquisition complete inputV= ADRESL + ((ADRESH & 0x03)<< 0x08); //Storing the converted binary value if (inputV > 500 && inputV < 750 && count > 166 && count < 200) //count > 166 is i.e. count is more than 5s { LATCbits.LATC4=1; } else if (count > 200) { LATCbits.LATC4=0; RESET(); count=0; } } PIR1bits.TMR1IF = 0; |
|
|
|
@ NKurzmanI尝试相同但不能使它工作,谢谢你的回应!@ RISCThank你为你的回应,试试吧!
以上来自于百度翻译 以下为原文 @NKurzman I tried the same but not able to make it work, thank you for your response! @RISC Thank you for your response, will give it a try! |
|
|
|
好,是的,删除重置,它只会引起问题-你知道,硬件必须初始化,需要一些时间…试着测试LED的ADC和阈值。还添加一个闪烁的LED进行调试,也许…
以上来自于百度翻译 以下为原文 Ok, yep, REMOVE the reset, it will only cause issues - you know, hardware must be initialized, needs some timing... Try testing just the ADC and your threshold to the leds. Also add a blinking led for debugging, maybe... |
|
|
|
细节取决于电压变化的速度和触发错误的时间。采样率需要至少是瞬态的等效频率的两倍,以确保它们被检测到。你应该使用一个计时器中断,也许在1毫秒的间隔,开始转换和增加一个MSEC计数器变量。另一个ISR将处理转换的结果。然后你可以这样做:
以上来自于百度翻译 以下为原文 The details depend on how fast the voltage might change and how long it may be out of spec to trigger an error. The sampling rate needs to be at least twice the equivalent frequency of the transients, to be sure they are detected. You should use a timer interrupt, perhaps at 1 mSec intervals, to start a conversion and increment a mSec counter variable. Another ISR will handle the results of the conversion. Then you can do something like: TIMERISR: { mSec++; ADCGO; } ADCISR: { voltage = ADCresult(); if (voltage < LOWLIMIT || voltage > HIGHLIMIT) voltageOK = FALSE; } volatile int mSec, voltageOK; main() { while (1) { mSec = 0; // reset variables voltageOK = TRUE; while( mSec < 5000 && voltageOK ); if (voltageOK) fOK(); // function to handle voltage good else fOutOfSpec(); // function to handle voltage high or low // loop back and go again } |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
733浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
505浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 06:40 , Processed in 1.342795 second(s), Total 96, Slave 80 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号