完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好。
我已经建立了一个传输和接收超声波的电路。它有一个输入(控制TX -通常在40kHz的脉冲),和输出(逻辑高或低-如果反射脉冲检测)。 我在40kHz从PWM(1)驱动TX,然后用第二PWM(2)控制PWM(1)的开启时间。 IE,PWM(1)输出40kHz为0.5毫秒,关闭为64.5MS。 现在,我想把反射信号的时间花在时间上。我曾想过使用一个IpUTT,然后读取PWM值并将其转换成一个时间,或者使用定时器。 请你给我指出正确的方向,因为我不确定这是最好的软件或硬件处理(触发和捕获引脚在定时器/PWM)。 多谢 以上来自于百度翻译 以下为原文 Hi. I've built a circuit which transmits and recieves ultrasonic waves. It has an input (controlling the tx - normally pulsed at 40kHz), and an output (logic high or low - if reflected pulse detected). I am driving the tx from a PWM(1) at 40kHz, I am then controlling the on time of PWM(1) with a second PWM(2). ie, PWM(1) is outputting 40kHz for 0.5ms and is off for 64.5ms. Now, I would like to time the time taken for the reflected signal to occur. I've thought about using an interupt and then reading the PWM value and converting it into a time, or using a timer. Please could you point me in the right direction, as I am unsure wheather this is best treated in software or hardware (trigger and capture pins on the timers/pwms). Many Thanks |
|
相关推荐
4个回答
|
|
你好,
你可以使用一个计时器,测量了信号到达后反思的时间。 1)计时器必须在捕获模式下使用。 2)应该为这个定时器启用硬件触发器。当PWM(1)开始传输,触发定时器,定时器开始计数。 3)输出引脚(反射脉冲指标)应连接到输入捕捉。 四)时,反射信号的接收,定时器的值被捕获。这可以使用ISR读取。过去的数将由波被反射后到达接收机的时间指示。 5)如果使用定时器时钟是合理的高频率,可以得到更好的精度。Eg,如果时钟为1MHz,它以100计数的相关波到达后,那么所花费的时间为100微秒。 距离travesred可以计算出声音在空气中的速度是已知的。 以上来自于百度翻译 以下为原文 Hi Graeme44, You can use another Timer for measuring the time taken for the signal to reach back after reflection. 1) The Timer has to be used in Capture mode. 2) Hardware Trigger should be enabled for this Timer. When the PWM(1) starts Transmission, trigger the Timer so that the Timer starts Counting. 3) The output pin (reflected pulse indicator) should be connected to the Capture input. 4) When the reflected signal is received, the Timer's value is Captured. This can be read using an ISR. The counts elapsed will give an indication of the time taken by the wave to reach the receiver after reflection. 5) If the Clock used for Timer is of reasonably high frequency, better accuracy can be obtained. Eg, If Clock = 1MHz, and it takes 100 counts for the relected wave to reach back, then the time taken is 100 micro second. Distance travesred can be calculated as the speed of sound in air is known. |
|
|
|
谢谢,我会试试看。
我仍然认为我可以只读取PWM计数值,而不是使用计时器-将尝试两种方式。 标准的互斥不介入PWM和计时器模块,在ISR中是否存在对它们的交互? 谢谢 以上来自于百度翻译 以下为原文 Thank you, I will try that. I still think I may be able to just read the PWM count values instead of using a timer - Will try both ways. Standard interupts don't interupt PWM and timer modules, is there anyway of interupting them during a isr? Thanks |
|
|
|
使用ISR也是一种可能。但是请注意,对于ISR代码执行,由于各种寄存器的推送和弹出,存在一定的延迟。因此PWM或定时器读出值可能不精确和准确。只要你能提供较低的精度,这是很好的。正如DASG在帖子2中所说的,使用计时器捕获模式是实现这一点的更精确的方式。在这种情况下,来自超声模块的输出将触发硬件中的计时器捕获,并且不管是否执行ISR,所捕获的值被存储。您可以稍后从ISR或您的正常固件读取此值并获得准确的时序信息。正如DASG在评论2中所说的,定时器输入时钟的频率越高,定时的精度就越好。
以上来自于百度翻译 以下为原文 Using ISR is also a possibility. But note that for the ISR code execute, there is certain amount of delay due to the PUSH and POP of various registers. And hence the PWM or Timer read out value may not be precise and accurate. As long as you can afford to have lower accuracy this is fine. As told by dasg in post 2, using the Timer capture mode is more accurate way of implementing this. In this case the output from the Ultrasonic module will trigger a Timer capture in hardware and the value captured is stored irrespective of ISR being executed or not. You can later read this value from a ISR or your normal firmware and get the accurate timing information. Also as was told in comment 2 by dasg, higher the frequency of the Timer input clock, better will be the precision of the timing. |
|
|
|
使用ISR也是一种可能。但是请注意,对于ISR代码执行,由于各种寄存器的推送和弹出,存在一定的延迟。因此PWM或定时器读出值可能不精确和准确。只要你能提供较低的精度,这是很好的。正如DASG在帖子2中所说的,使用计时器捕获模式是实现这一点的更精确的方式。在这种情况下,来自超声模块的输出将触发硬件中的计时器捕获,并且不管是否执行ISR,所捕获的值被存储。您可以稍后从ISR或您的正常固件读取此值并获得准确的时序信息。正如DASG在评论2中所说的,定时器输入时钟的频率越高,定时的精度就越好。
以上来自于百度翻译 以下为原文 Using ISR is also a possibility. But note that for the ISR code execute, there is certain amount of delay due to the PUSH and POP of various registers. And hence the PWM or Timer read out value may not be precise and accurate. As long as you can afford to have lower accuracy this is fine. As told by dasg in post 2, using the Timer capture mode is more accurate way of implementing this. In this case the output from the Ultrasonic module will trigger a Timer capture in hardware and the value captured is stored irrespective of ISR being executed or not. You can later read this value from a ISR or your normal firmware and get the accurate timing information. Also as was told in comment 2 by dasg, higher the frequency of the Timer input clock, better will be the precision of the timing. |
|
|
|
只有小组成员才能发言,加入小组>>
715个成员聚集在这个小组
加入小组1896 浏览 1 评论
1651 浏览 1 评论
3401 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1567 浏览 6 评论
1379 浏览 1 评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
180浏览 2评论
179浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
318浏览 2评论
344浏览 1评论
58浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-4-19 07:23 , Processed in 0.660908 second(s), Total 77, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号