完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
好吧,我可能会弄错,但在我继续这之前,我就是这样: -
-Spartan 3E,Basys board 2,50Mhz时钟,使用xilinx webpack ISE 我能够在10秒内记录超过5个过载电信号时创建一个简单的计时器来关闭电机。但是每次按下过载按钮,似乎(从我看到的)立即跳转到5个过载信号 - >从一个按钮按下过载按钮。即使在一次模拟过载后,它立即锁定我的电机5秒钟(锁上灯亮)。 这是我的代码: - 模块SenseCircuit( //输入 输入时钟, 输入OverloadButton,///用于模拟电机过载信号输出(我想计算在10秒钟内关闭电机可以获得多少这些) //输出 输出Testlight1,//测试灯,每隔10秒打开和关闭一次 输出Overloadlight,//这只是表明我已按下过载按钮(成功模拟过载) 输出LockLight //此输出显示锁定计数器正在计数且电机处于锁定状态 ); reg [28:0]柜台; //在50MHz时钟10秒后计数重置 reg Testlight1var; reg [28:0] OverloadCounter; reg [28:0]锁定; 初始开始//当我打开FPGA时将两个变量归零 Testlight1var = 0; //简单地显示电机主计数器计数到10秒,此reg设置为每10秒开启和关闭 counter = 0; //计数到10秒然后重置 OverloadCounter = 0; //计数到5然后启动锁定计数器,如果大于或等于5 锁定= 0; //如果电机锁定计数开始,电机将锁定5秒钟 结束 总是@(posedge clock) 开始 if(counter == 500_000_000&& Lockout == 0)///如果计数器达到10s并且电机未处于锁定状态,则继续像往常一样重置整个电路 开始 counter = 0; OverloadCounter = 0; Testlight1var =〜Testlight1var; //否定testlight的当前值(这只显示计数器计数到10秒) 结束其他开始 counter = counter + 1; 结束 if(OverloadButton == 1)//如果按下过载按钮(模拟电机过载),请对此进行计数以跟踪此情况 开始 OverloadCounter = OverloadCounter + 1; 结束 if(OverloadCounter> = 5)//如果超过5次重载,则开始递增锁定计数器(电机锁定) 开始 锁定=锁定+1; 结束其他开始 闭锁= 0; 结束 if(Lockout == 250_000_000)// 5秒后将锁定定时器复位为零,使电机退出锁定状态 开始 OverloadCounter = 0; 闭锁= 0; 结束其他开始 结束 结束 分配Testlight1 = Testlight1var; //将testlight输出分配给测试灯变量(它只是显示主要的10秒计数器正在计数) assign Overloadlight = OverloadButton; //按下过载按钮时此指示灯亮起 分配LockLight =锁定; //当锁定计数器计数时(锁定电机),此指示灯亮起 endmodule 我的ucf是 //输入 NET“时钟”LOC =“B8”; NET“OverloadButton”LOC =“G12”; //输出 NET“Overloadlight”LOC =“N5”; NET“Testlight1”LOC =“N4”; NET“LockLight”LOC =“P6”; 我有没有正确诊断出来? 问题是每次按下我的过载按钮时按钮注册为多个输入,或者我的代码是否有其他错误。 我怎样才能解决这个问题? 谢谢! 以上来自于谷歌翻译 以下为原文 Okay I could be mistaken but before i continue this is what I am on:- -Spartan 3E, Basys board 2, 50Mhz clock, using xilinx webpack ISE I was able to create a simple timer to shut down a motor when it records over 5 overload electrical signals in 10 seconds.However Each time I press the overload button, it seems(from what i see ) to instantly jump to 5 overload signals->from one single button press of overload button.So it instantly locks my motor for 5 seconds(locklight comes on) , even after just one simulated overload. here is my code:- module SenseCircuit( //Inputs input clock, input OverloadButton, ///used to simulate motor overload signal output(I want to count how many of these i can get in 10 seconds to shut motor) //Outputs output Testlight1, //test light that will alternate between on and off every 10 seconds output Overloadlight, // this just shows that i have pressed the overload button( succesfully simulated an overload) output LockLight //this output shows that lock counter is counting and that motor is in lockout );reg [28:0] counter; //counts up resets after 10 seconds of a 50MHz clock reg Testlight1var;reg [28:0]OverloadCounter;reg [28:0]Lockout; initial begin //zero out both variables when I turn on the fpga Testlight1var =0; //simply shows motor main counter is counting to 10 seconds, this reg is set to go on and off , every 10 seconds counter =0; //counts to 10 seconds then resets OverloadCounter =0; //counts to 5 then starts Lockout counter if more than or equal to 5 Lockout =0; //if motor Lockout count is started, motor is in lockout for 5 secondsendalways @(posedge clock) beginif(counter==500_000_000 && Lockout==0) ///if counter reaches 10s AND motor is not in lockout , then continue to reset the whole circuit as usualbegin counter =0; OverloadCounter=0; Testlight1var=~Testlight1var; //negate the current value of testlight (this just shows counter is counting to 10 seconds) end else begin counter =counter+1; end if(OverloadButton==1) //If overload button is pressed(simulate motor overload), count this to keep track of this begin OverloadCounter=OverloadCounter+1;endif(OverloadCounter>=5) //If over 5 overloads are registered, then start incrementing the lockout counter(motor in lockout) begin Lockout=Lockout +1; end else begin Lockout=0; end if(Lockout==250_000_000) //after 5 seconds reset lockout timer to zero to get motor out of lockout begin OverloadCounter=0; Lockout=0; end else begin endendassign Testlight1 =Testlight1var; //assign testlight output to test light variable( it just simply shows main 10 second counter is counting)assign Overloadlight =OverloadButton; //this light comes on when the overload button is pressedassign LockLight =Lockout; //this light comes on when the lockout counter is counting(motor in lockout)endmodulemy ucf is //InputsNET "clock" LOC = "B8";NET "OverloadButton" LOC = "G12";//OutputsNET "Overloadlight" LOC = "N5"; NET "Testlight1" LOC = "N4"; NET "LockLight" LOC = "P6"; Have I diagnosed this correctly,? is the problem just the button registering as several inputs each time I press my overload button or is there something else wrong with my code. how can i fix this? thank you! |
|
相关推荐
3个回答
|
|
|
首先,您应该将所有寄存器分配更改为延迟分配:计数器是的,OverloadCounter应该以时钟速率计数,这比您可以将手指从按钮上移开的速度快得多。
总是@(posedge clock) if(OverloadButton == 1'b1) OverloadCounter 将很快计算到5。 您可能想要去掉OverloadButton,然后在当前时钟周期中按下按钮以在上一个时钟周期内没有按下按钮,这表示您有一个新的按钮按下来计数。 就像是: reg [7:0] buttonReg = 8'd0; reg lastButtonReg = 1'b0; 总是@(posedge clock)开始 lastButtonReg 丹尼尔 以上来自于谷歌翻译 以下为原文 First off you should probably change all of your register assignments to delayed assignment: counter <= 0; And yes, the OverloadCounter should count up at the clock rate, which is a lot faster than you can take your finger off the button. always @(posedge clock) if(OverloadButton == 1'b1) OverloadCounter <= OverloadCounter + 29'd1; Will count up to 5 very quickly. You probably want to debounce the OverloadButton and then look for the button to not have been pressed in the previous clock cycle while it is pressed in the current clock cycle as an indication that you have a new button press to count. Something like: reg [7:0] buttonReg = 8'd0;reg lastButtonReg = 1'b0;always @(posedge clock) begin lastButtonReg <= & buttonReg; buttonReg <= { buttonReg, OverloadButton }; if( & buttonReg && ~ lastButtonReg ) OverloadCounter <= OverloadCounter + 29'd1;end Daniel |
|
|
|
|
|
这很大程度上取决于电机的运行方式。
如果电机在过载时保证产生一个正好一个时钟周期的脉冲,那么现有的代码就可以了 - 问题是你的手指在一个按钮上没有起到电机如何动作的作用。如果电机产生更长的脉冲 当它过载时,你需要检测脉冲的两侧 - 所以一个脉冲意味着信号变高然后再变低。 这样,需要五次按下并释放循环来触发锁定(*)。如果电机在过载时设置输出,并且输出一直保持到过载完成,那么你需要停止计数脉冲。 例如,如果电机只是过载并永久保持过载,那么它只会产生一个脉冲(过载信号变高并保持高电平) - 但这显然是关闭电机必不可少的情况。 这需要更多的思考。除此之外,你应该以不同的方式分配LockLight: 分配LockLight = |锁定; 这样,如果设置了Lockout中的任何位,LockLight将打开。 你现在写的方式是,只有当LockOut中的底部位置位时,LockLight才会打开 - 这只是Lockout计数时的一半时间。 以上来自于谷歌翻译 以下为原文 This is going to depend pretty heavily on how the motor behaves. If the motor is guaranteed to produce a pulse exactly one clock cycle long when it overloads, then the existing code is fine - the problem is that your finger on a button is not acting how the motor would act. If the motor produces a longer pulse when it overloads, then you need to detect both sides of the pulse - so one pulse means the signal going high and then going low again. That way, it takes five press-and-release cycles to trigger the lock (*). If the motor just sets an output when it overloads, and that output stays on until the overload is finished, then you need to stop counting pulses. For example, if the motor just overloads and stays overloaded permanently, then it'll only produce a single pulse (the overload signal goes high and stays high) - but this is clearly a situation where turning off the motor is essential. This will require a bit more thought. Apart from that, you should probably assign LockLight differently: assign LockLight = |Lockout;That way, if any of the bits in Lockout are set, LockLight will be on. The way you've got it written at the moment, LockLight is only on if the bottom bit in LockOut is set - which will only be true half the time when Lockout is counting. |
|
|
|
|
|
编辑(因为我仍然无法编辑该帖子):我忘了处理(*)。
(*)正如dwisehart所说,开关需要去抖(尽管电机可能不会)。 当您按下或松开开关时,它会在触点上上下跳动一会儿。 人类不会注意到这一点 - 整个过程需要几微秒或几毫秒才能完成。 然而,FPGA是具有20纳秒分辨率的时序,所以它肯定会注意到弹跳。 实际上,这会导致FPGA在按下按钮时计算几个脉冲,即使您的代码正在寻找每个脉冲的两端。 解决方案是应用一些逻辑:如果信号已经高电平一段时间(可能是10ms),则仅按下按钮,并且如果信号已经低电平一段时间,则仅注册按钮释放。 这样,如果开关上下跳动1ms,那么这些反弹将被安全地忽略。 这通常作为单独的模块完成,然后为主模块产生“干净”的过载输入。 以上来自于谷歌翻译 以下为原文 Edit (because I still can't edit that post): I forgot to deal with the (*). (*) As dwisehart has said, the switch will need debouncing (although the motor probably won't). When you press or release the switch, it'll tend to bounce up and down on the contacts for a short while. A human won't notice this - the whole process takes microseconds or milliseconds to complete. However, the FPGA is timing stuff with a resolution of 20 nanoseconds, so it'll definitely notice the bouncing. In practical terms, this results in the FPGA counting several pulses whenever you press the button, even when your code is looking for both ends of each pulse. The solution is to apply a bit of logic: only register a button press if the signal has been high for a while (maybe 10ms), and only register a button release if the signal has been low for a while. That way, if the switch is bouncing up and down for 1ms, those bounces will be safely ignored. This would generally be done as a separate module, which then produces a "clean" overload input for the main module. |
|
|
|
|
只有小组成员才能发言,加入小组>>
3148 浏览 7 评论
3437 浏览 4 评论
Spartan 3-AN时钟和VHDL让ISE合成时出现错误该怎么办?
2899 浏览 9 评论
4100 浏览 0 评论
如何在RTL或xilinx spartan fpga的约束文件中插入1.56ns延迟缓冲区?
3083 浏览 15 评论
请问vc707的电源线是如何连接的,我这边可能出现了缺失元件的情况导致无法供电
1363浏览 1评论
求一块XILINX开发板KC705,VC707,KC105和KCU1500
1201浏览 1评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-14 12:47 , Processed in 0.515601 second(s), Total 48, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
285
