accurate timing/clock for microcontroller? (for measuring bpm)

I would like to build a drum machine/metronome using a BASIC Stamp 2 (maybe later on PICAXE) which would allow the user to control the beats per minute (bpm) with a dial/potentiometer. They could select a value from 1-255 (later I might add a module to display the current value).

I would like the timing to be as accurate enough to a real clock to be comparable to a real metronome or drum machine.

This is the main problem, since the BASIC Stamp 2 (and PICAXE models I am considering) don't have a real time clock (see link/citation below). Would I need to connect the microcontroller to a Dallas real time clock to accurately control the timing or would it be possible to make my own with a

555 timer or other component for less money?

For my purpose the 555 or similar would have to be accurate enough to measure actual seconds (or milliseconds? how granular should it be?) to get real beats per minute. I have found numerous "555 calculator" pages (some listed below) which let you enter different resistor/capacitor values and see what the time high / time low would be (you can reverse the math to figure out what R/C values to measure milliseconds, or 1/100 of a second, or whatever would be accurate enough).

You can get gold resistors with +/- 5% tolerance, would this variance throw off the timing? Furthermore I read that capacitors of the type needed for the 555 are a lot less tolerant (+/- 20%) than gold resistors. If this is true, would this totally throw off the timing? I picture myself having to buy 100 capacitors and test each one with a meter until I find the exact value, and even then its capactiance might change as it ages, making the device not accurate.

Any advice or links to a similar project or good solution would be most appreciated... The simpler the better : )

Thanks again

----------

Shaun's Basic Stamp II Beginners Page

formatting link
Real Time clock (RTC) - Since the Stamp only uses a resonator for its clock, it is not accuarate enough to keep track of dates and times. Resontors usually have a +/- 1% error, that means over a 24 hour period error could be close to an hour. But since the Stamp usually only is working with milli seconds, mirco seconds,and seconds a resonator does the job. Real Time Clock can keep track of years, months, weeks, days, hours, minutes, and seconds. So as you can see any project that requires an accuarate time base then a RTC is what you need. Dallas semi conductor make some of the most popular RTC's.
formatting link

555 Calculator
formatting link

555 Timer Calculator

formatting link

555 Timer Calculator
formatting link
Reply to
mad.scientist.jr
Loading thread data ...

A pic has an internal oscillator which is tunable using an internal register, giving you about 5% accuracy on the absolute clock speed, which is suitable for many applications. It changes with temperature, however. You can also use an external crystal, which will get you to better than 1%, independent of temperature (at room temp += 10C). Using an external crystal uses up two pins, but may be what you need. You can also use an external crystal oscillator, which may have comparable accuracy, but only needs a single pin input. You can get them in packages where you input 5V and GND, and get a TTL signal out with the clock.

These will be much cheaper than an RTC chip, most of which's features you won't need. If you use a dial pot, you won't be able to tune the thing much more accurately than 5% anyway, I think, so the internal PIC oscillator will probably be fine.

Regards, Bob Monsen

Reply to
Bob Monsen

--
Sorry, but you're completely off base.

What you want to do is program your basic stamp to be an astable
multivibrator with a period which varies according to the user
input.

For example, if your basic stamp has a 1MHz resonator generating the
clock and you want to output 60 beats per minute, then you need to
count up the equivalent of 1 million clocks and generate an output
at that time.  Also, if your output's pulsewidth isn't being
generated by an independent internal interrupt driven timer, you'll
need to subtract the width of the output pulse and the times
required for the instructions to generate it from the one million
clocks so that things come out right.
Reply to
John Fields

--
Oops...

I misread your post, blow mine off.
Reply to
John Fields

Well, for one thing, that's more than enough accuracy for what's essentially a high-end metronome. :-) Remember the "real" metronomes? They were mechanical! ;-)

Or, if you're totally ooky about it, don't use a BASIC Stamp. Use a micro that can take a crystal. You can get temp-controlled crystals in an oven that have insane stability and stuff, or you could sync it to WWV. ;-)

Good Luck! Rich

Reply to
Rich Grise

If you don't use the PLL(jitter of +-2%) then you probably have about 1% jitter(which is the real problem except for drift). The clock has about 5% inaccuracy but you can calibrate that out or get a more accurate clock.

1% jitter using the internal 8Mhz clock is +-2bpm at around 200bpm. This isn't acceptable but you can use it anyways for development(its not bad though for starters). Its very easy to use a more precise external clock so its no big deal.

Also, Timer1 can use an external clock so if you use this for your timing you can easily hook up a better clock later on to get more precision.

The point being is that the clock, at this point in development, doesn't matter. The PIC is good enough at this point to do everything that is needed and its very simple to make it better.

Except of course if you do use timer1 and plan on using an external clock you need to keep the secondary osc pin free... although theres no real point when you can just use that for the primary clock.

So my suggestion is you go ahead and develop the software and hardware and then after you get a prototype you can worry about getting a more precise oscillator. (if you do any layout you can lay out for some clock and/or clock conditioner and then its just a matter of configuring the pic). This is really a non issue so go ahead and get with it! ;)

Reply to
Jon Slaughter

You might want to start with a BasicX-24 instead of a BASIC Stamp 2 [

formatting link
] It is superior to the Basic Stamp in many ways, one of which is having a stable crystal oscillator.

--
Guy Macon
Reply to
Guy Macon

Basic stamps can't use external crystals? I didn't know that. Useful bit of information.

Reply to
Bob Monsen

I guess you could unsolder the SMT ceramic resonator and replace it with capacitors and a crystal, but they've got so many other disadvantages I would not recommend it.

In this case, a microcontroller with a hardware timer that can toggle an external pin (called the CCP module on Microchip's parts) is called for, as well as the crystal timebase.

The OP may be able to find a suitable chip that has a free C compiler such as PICC Lite, or some other language of his/her choosing.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.