reset the counter
haim
Posts: 25
Hi all,
I am using one cog as a pulse counter, and another cog to watch an input. When the input is true than reset the counter. Is there any sample code available or give me some hints.·Please help! Thanks.
haim
I am using one cog as a pulse counter, and another cog to watch an input. When the input is true than reset the counter. Is there any sample code available or give me some hints.·Please help! Thanks.
haim
Comments
PHSa := 0
note that this has to be done with the cog that is counting, there are a set of registers for each cog and they are independent
you will have to either combine the functions into one cog or devise a way of signalling the counting cog to do the reset
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Parallax Forums - If you're ready to learn, we're ready to help.
Post Edited (CJ) : 10/2/2007 3:05:13 AM GMT
As I undersdand,·the counter only can be reset within the same running cog.
Like·cog1·can not reset cog0's counter, right? Thanks.
haim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Thanks for the reply. The reason I am asking is, I need to set up a counter that can be reset by a in coming trigger, send a pulse out when the counter reach a preset number, also the preset can be changed by two push buttons (Up and Down), and display that counter counts on a LCD display. Because with the LCD didplay, the delay is too long(one second), and it may missing some input signals while it is waiting. I am apreciated your help. Thank you very much.
haim
This is in fact the same question as: "When do I need a thread?" in more common environments, and is rarely comprehensively answered....
One guideline can be: Consider one of the older "design patterns" called MVC!
Meaning: split your program into
- a Model, responsible for the algorithmic aspect
- a View, showing the user what is going on (this has no priority!)
- a Control, giving the User a chance to act on the Model (or View), by changing parameters (this generally has the lowest priority, but on the other hand can somtimes need immediate attention in safty critical situations..)
Structuring your code in this way, can improve even smaller programs!
haim
I like the MVC approach, and I since I have learned about it, I have been applying it to any software that is user-event driven. For some embedded control applications it doesn't necessarily fit, however. State machine models are often good for the latter. These two approaches are not necessarily mutually exclusive however. Your model can be a state machine, for instance.
[noparse][[/noparse]edit] or....perhaps the controller should be a state machine..... I guess that all depends on your problem [noparse][[/noparse]/edit]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?