Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Which PIC or related chip, to count & display pulses?

Status
Not open for further replies.

PhillDubya

New Member
Hey guys,

I am currently working on a project where pulses need to be counted down from a predetermined (programmable) number. The counted pulses are generated from a 555 timer which is fed by a condenser mic. (which picks up beeps), connected to an lm741 op-amp for amplification, and then these activate the monostable one-shot. This part of the circuit I have completed, although I am still trying to figure out how to adjust the sensitivity, yet that is unrelated right now.

I am just wondering what your ideas would be as the easiest way to set-up a programmable counting device?

I started out with the idea that cascaded decade counters would be best, but it got seriously complicated, when I started looking at ways to output the count to a 4 digit C.A. display, and then activate a circuit when the predetermined count was reached. Which led to an MCU.


I am currently looking at a PIC or MSP430, however, I believe the PIC in this case would be plenty capable.

Would anyone have any ideas as to which pick would be the best?
An idea, conceptually of some suedo-code or conceptual code?

Thanks in advance for your time,

Phill
 
so you just need to count X number of beeps, and when you reach that number of beeps, reset the count and send some sort of output?

i programmed assembly on the MSP430 for a while, not much experience with PICs but I think it should be similar.

since they're audible beeps I can't imagine them occurring at a high frequency, so you could do it with either polling or interrupts. how often do the beeps occur (about) and for how long are they on? either way the clocks on both chips should be way more than fast enough.



Interrupts:
connect to an interrupt pin, setup that pin as interruptable, and...

1. wait loop (i.e. make a loop where the chip does nothing)
2. on interrupt, enter subroutine:
---- add 1 to count register
-------- is count register equal to X?
------------YES: set output pin to desired output (high or low, depending on what you need) (youll need to code another counter in here that keeps the output pin high long enough for whatever youre using to read the count with to register it), then set count register to 0. if you need the output pin high for a while (i.e. other beeps will occur while its high), you could "subtract X from count register" to keep the # of counts that occurred while counting down for the output, or you could just make it work like a flipflop, and alternate the output every time X is counted, assuming your detection circuitry can and will detect both a rising and falling edge. if it can, thats the best way i can think of.
------------NO: go back to wait loop

Polling:
connect to input pin, and...

1. look at input
2. is it high?
----yes: add 1 to count register
----no: do nothing
3. is count register equal to X?
----yes: set the output (see interrupt method)
----no: go back to (1.)




msp430s are more expensive though i think. if the pic is fast enough clockwise to count your beeps, then go with that because its cheap msp430 actually has a lot of capability that you reallllly dont need for this project as far as I can see. a basic stamp might do the trick even (dunno how those are with interrupts though...)
 
My Dragonfly kit can be built with 4 digits (CC 14mm) it even has a handful of spare I/O. The schematic is in the Assembly Manual on my site.
 
@ Solis365: Thanks for the response.:)

I like your concept for the "Interrupt" method it is similar to what I have now, and have updated my code concept after reading your
suggestions.

Here is what I have now: (for the msp 430, which shouldn't matter as both the PIC and MSP430 both use assembly, and assembly is the same for all, correct?)

-Start
-Enter number to be counted down (Example 123)
-Display number out to LCD module (output contents of registers)
-*Wait until actual interrupt from 555 timer (TTL Pulse)
--For every pulse, dec. counter
-Counter > 0?
-No? GO back to *Wait (jnz command)
-Yes? Go to alarm loop & activate relay
-Some basic alarm activating loop
-Loop to output pulse to transistor to activate 12V relay
-Non-conditional jump back to start
-End

I am interested in the "Polling" method. What are the advantages to that, as opposed to an interrupt?

Thanks


Blueroomelectronics said:
My Dragonfly kit can be built with 4 digits (CC 14mm) it even has a handful of spare I/O. The schematic is in the Assembly Manual on my site.
Yesterday 03:56 PM

Thanks, I will check it out.
 
looks good to me, but:

"--For every pulse, dec. counter
-Counter > 0?
-No? GO back to *Wait (jnz command)
-Yes? Go to alarm loop & activate relay"

shouldnt that be a "Counter = 0?"
or switch your yes & no functions around

unless the counter hits zero, it will always be yes, so you will activate the relay on every pulse EXCEPT the "123rd" or Xth

adjust your jump commands if necessary. (disclaimer, i may have read the code wrong, but this should be a pretty easy thing to notice if it goes wrong ;) )

other than that, yeah assembly's basically the same for everything, different units might use slightly different names for commands and registers and such, so if your porting your code to pic just look in the manual and make sure everything is doing what you want.


as far as polling goes, interrupts tend to be more powerful and useful, polling is just a basic way of doing simple things i learned before learning more-complicated interrupts. I suppose if you were taking data, it would be useful if you wanted a fixed time interval between data points, because you could put a time delay between every "poll" of the inputs (use a decrement to zero command)


happy hunting
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top