完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用一个标准的定时器模块采取了一些在设定的时间间隔的交流波形样本;我基本上是做一个RMS电压测量,所以需要能够确保我取32个样本在输入的交流信号的半个周期,利用定时器,设定采样周期。根据输入交流信号的频率(或50Hz或60Hz),我需要改变我的计时器- 50Hz工频周期的缓冲值需要的样品应稍远时相比,60Hz的周期。
在我的代码中,首先上电,我计算输入的交流信号的频率,然后我写了一个适当的值(freqval)进入我的定时器使用命令timer_writeperiod时期缓冲(freqval);这似乎正确的工作。 然后,当我要开始我的定时器,我使用的命令timer_start();全是工作…我这样想。 这个问题似乎是,而不是使用价值freqval我写进期缓冲之前,启动定时器使用timer_start()命令出现抢我设置组件的周期缓冲区的默认值,有效地忽略了以前的提姆ErthRead时期(FRQVALL)命令。 在阅读这一部分的数据表,这实际上是做了应该做的: tcpwm_start虚空(void)描述:初始化默认值时,称为定制tcpwm第一次使tcpwm。随后调用配置保持不变,成分简单地启用 但我不想这样做。我想用我写的freqval值在早期对我的代码每次我启动它(我做每10秒左右,在操作过程中)。但因为我开始计时的第一次后,我已经写了freqval更新后的值到定时器周期,它只是默认设定值和我的RMS计算都是错的! 我也试着改变所有引用timer_start()到timer_enable();看来这一命令不使用默认的周期值从定制。然而我的代码开始表现得有点不规律基本上与看门狗定时器超时,所以我怀疑我从来没有真正触发定时器中断。我没有真正深入研究这一点。 我已经成功地能够正常工作的唯一方法,就是如果我打电话给timer_start()第一,然后立即打电话给timer_stop(),使初始设置使用默认值完成。然后我打电话给timer_writeperiod(freqval)设置定时器周期,以及所有后续调用将确保我timer_start()定时器运行使用freqval价值的时期。 这似乎有点凌乱的我,所以我想初始化一个计时器的正确方式是什么,所以,我写任何值期缓冲区将以确定其时代价值。 干杯,迈克 以上来自于百度翻译 以下为原文 I am using a standard TIMER block to take a number of samples of an AC waveform at set time intervals; I'm basically doing an RMS voltage measurement, so need to be able to ensure I take 32 samples over one half cycle of the incoming AC signal, and the TIMER is used to set the sample period. Depending upon the frequency of the input AC signal (either 50Hz or 60Hz), I need to change the value of the Period buffer in my timer - a 50Hz cycle requires the samples to be taken slightly further apart when compared to a 60Hz cycle. In my code, at first power on, I calculate the frequency of the incoming AC signal, then I write an appropriate value (FreqVal) into the Period buffer of my timer using the command Timer_WritePeriod(FreqVal); This appears to work correctly. Then, when I need to start my timer, I use the command Timer_Start(); That all seemed to work...or so I thought. The issue with this, it seems, is that rather than use the value of FreqVal that I wrote into the Period buffer earlier, starting the Timer using the Timer_Start() command appears to grab the default value for the Period buffer from the component I have set up, effectively ignoring the previous Timer_WritePeriod(FreqVal) command. In reading the datasheet for this component, that is actually what it is supposed to do: void TCPWM_Start(void) Description: Initializes the TCPWM with default customizer values when called the first time and enables the TCPWM. For subsequent calls the configuration is left unchanged and the component is simply enabled But I don't want it to do that. I want it to use the FreqVal value I wrote in their earlier on in my code each time I start it (which I do about every 10 seconds during operation). But because I start the Timer for the first time after I have written the updated value of FreqVal into the Timer Period, it just defaults to the preset value and my RMS calcs are all wrong! I did try changing all references to Timer_Start() to Timer_Enable(); as it appears this latter command doesn't use the default Period value from the customizer. However my code started to behave a bit erratically - basically timed out with the Watchdog timer, so I suspect my Timer was never actually triggering an interrupt. I didn't really look into this much further. The only way I have been successfully able to get things to work correctly, is if I make a call to Timer_Start() first, then immediately make a call to Timer_Stop(), so that the initial setting up using the default value is completed. Then I make a call to Timer_WritePeriod(FreqVal) to set the Timer Period, and all subsequent Timer_Start() calls will ensure my timer runs using the value of FreqVal for the period. This seems a bit messy to me, so I was wonder what the correct way to initialise a Timer is, so that whatever value I write into the Period buffer will be the value it uses to set its period. Cheers, Mike |
|
相关推荐
5个回答
|
|
你找到了一个经常使用的工作解决方案。
以较低的频率60hz你可以开始计时,立即改变的时期。CPU速度相当快。 鲍勃 以上来自于百度翻译 以下为原文 You found a working solution which is quite often used. With low frequencies as 60Hz you may start the timer and immediately change the period. The CPU is comparably fast. Bob |
|
|
|
或者,你可以用timer_writeperiod()时期设置,然后调用timer_enable()启动计时器。
如果你看看底层代码start_timer()只有一个或两个功能,和timer_init()是函数,改写阶段,所以就不应该运行的很好,如果你不想有“乱码” 以上来自于百度翻译 以下为原文 Alternatively, you can set the period with Timer_WritePeriod(), then call Timer_Enable() to start the timer. If you look at the underlying code for Start_Timer() there are only one or two functions, and the Timer_Init() is the function that is rewriting the period, so just skipping that one should work pretty well if you don't want to have the "messy code" |
|
|
|
好的,谢谢鲍伯。这似乎是一种奇怪的方式,仅此而已。另外,我在60Hz交流波形的单个周期中有效地取64个样本,这意味着我的定时器周期为1(/ 60×64)=260USEC。所以,我真的只有260usec从我开始计时,当我需要freqval写入定时器缓冲更新后的值,我不确定这是足够长的时间。 以上来自于百度翻译 以下为原文 OK, thanks Bob. Seems a weird way of going about it, that's all. Plus, I'm effectively taking 64 samples over a single cycle of the 60Hz AC waveform, which means my Timer period is 1/(60*64) = 260usec. So, I've really only got 260usec from the time I start the Timer to when I need the updated value of FreqVal written into the Timer buffer and I'm not sure this is long enough. |
|
|
|
yuhe82 发表于 2018-10-15 13:29 是的,按照我原来的帖子,我尝试使用TimeReNeable(),但是我的代码被锁定并调用了看门狗重启(大概是由于某种原因让它自己在无尽的等待循环中)。我不想花几个小时试图理解为什么,所以回到了使用TimeRySistTo();调用TimeRySistAd();然后调用TimeReScript();在调用TimeReWrdErrEff句t(FrQVALL)之前; 以上来自于百度翻译 以下为原文 Yeah, as per my original post, I tried using Timer_Enable(), but my code then locked up and invoked a WatchDog restart (presumably got itself in an endless wait loop for some reason). I didn't want to spend hours trying to understand why, so went back to using Timer_Start(); with the call to Timer_Start(); then Timer_Stop(); prior to calling Timer_WritePeriod(FreqVal);; |
|
|
|
hzdembed 发表于 2018-10-15 13:42 是的,真不幸 鲍伯对改变时期的评论可能是指在定时器运行期间改变周期的可能性。由于CPU速度足够快,它可能只在定时器被更改之前丢失了一些计数,但是如果它正在工作,则没有理由中断它。 以上来自于百度翻译 以下为原文 Yeah; Unfortunate really Bob's comment towards changing the period might have been referring to the possibility of changing the period while the timer is running? Since the CPU is fast enough, it might only lost a couple counts on the timer before being changed, but if it is working now, then no reason to break it |
|
|
|
只有小组成员才能发言,加入小组>>
757个成员聚集在这个小组
加入小组2130 浏览 1 评论
1872 浏览 1 评论
3690 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1808 浏览 6 评论
1554 浏览 1 评论
CY8C4025LQI在程序中调用函数,通过示波器观察SCL引脚波形,无法将pin0.4(SCL)下拉是什么原因导致?
624浏览 2评论
CYUSB3065焊接到USB3.0 TYPE-B口的焊接触点就无法使用是什么原因导致的?
473浏览 2评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
460浏览 2评论
413浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
1102浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-28 09:43 , Processed in 1.011274 second(s), Total 83, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (威廉希尔官方网站 图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号