Shop OBEX P1 Docs P2 Docs Learn Events
reset the counter — Parallax Forums

reset the counter

haimhaim Posts: 25
edited 2007-10-03 03:55 in Propeller 1
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

Comments

  • CJCJ Posts: 470
    edited 2007-10-02 02:58
    just set the PHSx register that you are using to 0

    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
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-02 06:12
    To be precise, there is not only a set of REGISTERs per COG but two DIFFERENT ccounters in EVERY COG (so there are SIXTEEN of them. Not to mention the video logics, where are EIGHT of!
  • haimhaim Posts: 25
    edited 2007-10-02 17:10
    Thanks CJ and deSilva,

    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
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-02 17:13
    Right! Of course it can not! It has enough to do with its own two counters smile.gif
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-10-02 17:28
    You could pass messages between cog 1 and cog 0, but that's beside the point. You should only need one cog to do the pulse counts (with the counter) and monitor the input pin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • haimhaim Posts: 25
    edited 2007-10-02 18:58
    All,
    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
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-02 22:36
    Hate to add to a "closed" thread, but I think Haim addressed an interesting "design pattern" question: What are the criteria to make you spend a COG?

    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!
  • haimhaim Posts: 25
    edited 2007-10-02 23:13
    Thanks, deSilva.

    haim
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-10-03 02:17
    If the display is taking a long time, I would spawn a cog process to manage the display. Let the other cog manage the counter. In this case, the display cog is the View, and the other cog is the Model and Control. Is this what you had in mind, deSilva?

    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?
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-10-03 03:55
    Interesting. Googling 'MVC model' returns 2.8M instances (sans the '). Turns out to have come out of Xerox Parc, as much else. Back when they didn't give a damn about software patents.
Sign In or Register to comment.