1 2 3 Previous Next 39 Replies Latest reply on May 20, 2013 6:05 PM by DaKn_263916

    Counter circuit



      I want to make the counter to be used in the circuit design my project.Example, Counter count 30 minute and then led  is on.What should I use component this circuit and How should I write a code. I find about itin forum, but I could not find an example forum.Can you  show me how to follow in the way

        • 1. Re: Counter circuit

          You can do this several ways.




          1) Place a counter on schematic, say fixed 16 bit, and  clock source and an ISR symbol to generate


          an interrupt.





          Config counter as 1800 period, 60 secs x 30 minutes, interrupt on Tc. Place clock, sournce ILO (1 Khz),


          and set its freq to 1 Hz. Note ILO has to be trimmed otherwise accuracy marginal. Or use buss clock,


          its accuracy is +/- 5% (depends on what freq you clock with). ILO trimmed is - 50%, + 100%, or use 32


          Khz xtal. Then in ISR flip pin that is driving LED.




          2) Use RTC and set an alarm for every 30 minutes.




          Regards, Dana.

          • 2. Re: Counter circuit

             Hi Dana,


            I want to set the time exchanging, Can I use this in RTC? I will set time with the button maybe 5 minute,then countdown 5 minutes  led on. So, can i set the time with the button?How do you need to write a program for it? Thanks for answers

            • 3. Re: Counter circuit

              Answer is yes, you can change time with a button(s). Usually a button for


              up, one for down, another for menu select.




              1) Buttons would have to be debounced, generally in firmware by polling the


              port with the pins in a for() or while() loop.


              2) You debounce a button by detecting first closure, then timing out a period, on the order of


              100 mS, and checking to see its still closed. If it is and doneflag == 0 then you do the function


              assigned to that pin/button and set doneflag==1. Keep in mind you also have to debounce the


              button open, and when it is open reset doneflag==0. The 100 mS can be done with a timer or


              counter, and an ISR to inc a variable every 100 mS. 100 mS is switch dependent, but should


              be OK for most switches.




              Some debouce info that may be of help.




              Regards, Dana.

              • 4. Re: Counter circuit

                 you can also use the debounce component from creator as well. It's all up to you. For simple test of idea, the hardware component would be quicker.

                • 5. Re: Counter circuit

                   I examined documents. I'm trying to do something. if there's an example Can you send me?

                  • 6. Re: Counter circuit

                    Are you looking for a already finished solution to your problem?


                    Try to play around with the components. Look at the example projects available with the kits. Use a debouncer component to just drive a LED. Use the timer component to drive a LED (let it just blink). Then combine the two. It is not that complicated :)


                    If you have a question regarding a specific problem, don't hesitate to ask here (but open a new thread for new questions, please).

                    • 7. Re: Counter circuit

                      I did some trials but I do not know how to connect debounce and timer maybe program is incorrect.I'd love can look at it

                      • 8. Re: Counter circuit

                        First, you could update Creator to the latest version, I was asked to update some components (but this should not be the source of your problems).


                        Second, since your button is connected to ground, you might want to use 'neg' output of the debouncer to detect button presses  instead of using the NOT gate inbetween.


                        But most important, remove the first for-loop from your code - I think it gets stuck there instead of going to the second one containing your real code...


                        The main loop looks OK at a first glance, but you never update the 'temp1' variable. But you should not write an integer starting at column 14 - it might overflow (when it has more than 2 digits).


                        I saw that the LED pin you draw in the schematic is assigned to P6[7], but in the 'test' ISR you change P6[3]. You should store the current state of the LED in a variable (e.g. a boolean) which gets toggled every ISR call and determines the output state. This is safer than directly reading the pin (e.g. you write a 1 to the pin, it starts to rise to 1, in the next ISR call you read the pin but get a 0 since it has not risen enough...)

                        • 9. Re: Counter circuit

                          btw: there is an AppNote regarding the debouncer: http://www.cypress.com/?rID=40974 which you might want to read besides the data sheet.

                          • 10. Re: Counter circuit

                            No small number of training videos here -




                            www.cypress.com/    Take PSOC 3 and 5 101 thru 104.




                            Almost all components, when placed on a schematic, if you right click


                            them, have a menu selection "find example project" than you can add


                            to the design you are working on, or open in a new design window to


                            look at.




                            Regards, Dana.

                            • 11. Re: Counter circuit

                              You are corerct to use the inverter, per AN60024 -








                              I would recommend setting clk to debouncer as 10 Hz, ie wait 100 mS


                              for all sw bounce to expire.




                              Add this to start of main() -




                                  /* Enable global interrupts */  




                              Regards, Dana.

                              • 12. Re: Counter circuit




                                I would just check off Positive edge only.




                                Regards, Dana.

                                • 13. Re: Counter circuit

                                  But this one-irq-too-much problem only happens if interrupts are already enabled when starting the debouncer component.


                                  The reason I suggested to remove the inverter is that, right now, it iss a double negation. First the active-low button signal is converted to an active-high signal, and then the ISR is set to react on a rising flank - whereas in reality a falling flank is meant (to detect the button press). In my experience this always has great potential to confuse people...

                                  • 14. Re: Counter circuit

                                    If the button has a pull up resistor and connect to ground when press.


                                    I will use the input directly to the debouncer, and only generate pulse on negative edge.


                                    That means a (high) pulse will generate every time the button is pressed(connected to ground).

                                    1 2 3 Previous Next