Author Topic: counter required to count to near 1 million  (Read 23108 times)

0 Members and 1 Guest are viewing this topic.

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
counter required to count to near 1 million
« on: March 17, 2013, 09:01:00 pm »
I need to count to nearly 1'000'000 on a counter, can anyone suggest a good counter ? this is for  a clock signal generator
 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 4283
  • Country: nl
Re: counter required to count to near 1 million
« Reply #1 on: March 17, 2013, 09:14:09 pm »
You need to provide a bit more information, what are you looking for? A pulse out after the counts or do you need a readout of the counts?
What are you trying to brew this time?  8)
Keyboard error: Press F1 to continue.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 7571
  • Country: nz
Re: counter required to count to near 1 million
« Reply #2 on: March 17, 2013, 09:23:32 pm »
I dunno how/if they work or do what you want but DX sell industrial (looking) counters which go up to 999,999

http://dx.com/p/cg8-digital-counter-ac-110-220v-118803
http://dx.com/p/dhc3j-1-1-lcd-digital-counter-grey-black-138035

Edit: looking at your comment about it being for a "clock signal generator" im thinking you want an IC counter and not a finished unit??

« Last Edit: March 17, 2013, 09:28:11 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #3 on: March 17, 2013, 09:28:42 pm »
no just a digital counter / frequency divider IC, I'm putting in a 32.768 KHz clock and want to fire an impulse every 30 seconds so make a circuit send an impulse every time the counter resets (or other convenient number occures)
 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 4283
  • Country: nl
Re: counter required to count to near 1 million
« Reply #4 on: March 17, 2013, 09:47:48 pm »
Looking at cost and board space the best solution is probably a PIC10XXX.
Keyboard error: Press F1 to continue.
 

Offline Thor-Arne

  • Supporter
  • ****
  • Posts: 503
  • Country: no
  • tinker - tinker, little noob.....
Re: counter required to count to near 1 million
« Reply #5 on: March 17, 2013, 09:48:51 pm »
74HC160 or 74HC4059 should be usable.
 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 4283
  • Country: nl
Re: counter required to count to near 1 million
« Reply #6 on: March 17, 2013, 09:50:49 pm »
74HC160 or 74HC4059 should be usable.
Not enough counts.
Keyboard error: Press F1 to continue.
 

Online krish2487

  • Frequent Contributor
  • **
  • Posts: 441
  • Country: dk
Re: counter required to count to near 1 million
« Reply #7 on: March 17, 2013, 09:51:17 pm »
Cascade 6 decade counters...

 :-//

@thor-arne

you beat me by seconds...
 :D
If god made us in his image,
and we are this stupid
then....
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: counter required to count to near 1 million
« Reply #8 on: March 17, 2013, 09:53:39 pm »
Looking at cost and board space the best solution is probably a PIC10XXX.

Yep. I'm often the last to suggest a microcontroller, but they do make for nice, quick, custom "logic" chips when you need something this specific. I've got a pile of PIC10F200s (both DIP-8 and SOT-23-6 - holy crap that is a small microcontroller, it's smaller than its 0805 decoupling cap!) that frequently get used for this sort of application. A cascade of 7400 series counters would work, but I'd probably prefer a single 10F200.
No longer active here - try the IRC channel if you just can't be without me :)
 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 4283
  • Country: nl
Re: counter required to count to near 1 million
« Reply #9 on: March 17, 2013, 09:58:17 pm »
A DIP-8 $ 0.30 is hard to beat with 2-4 DIP 16-24 devices...
Keyboard error: Press F1 to continue.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 7571
  • Country: nz
Re: counter required to count to near 1 million
« Reply #10 on: March 17, 2013, 10:06:44 pm »
I had a very quick look at clock divider chips on digikey but you really need a divide and then a multiply to get 30s, which is two chips.
A mcu is going to be cheaper unless you can find a dirt cheap clock logic IC with a half-minute output.
« Last Edit: March 17, 2013, 10:11:19 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Thor-Arne

  • Supporter
  • ****
  • Posts: 503
  • Country: no
  • tinker - tinker, little noob.....
Re: counter required to count to near 1 million
« Reply #11 on: March 17, 2013, 10:07:45 pm »
Both 74HC160 and 74HC4059 can be pre-programmed with dip switches, that's why I suggested those.

A micro controller is also usable ofcourse, I just generally don't suggest those if it can be done easily with standard logic.
 

Offline jimmc

  • Frequent Contributor
  • **
  • Posts: 284
  • Country: gb
Re: counter required to count to near 1 million
« Reply #12 on: March 17, 2013, 10:09:30 pm »
As has been said PIC route is the simplest, there's a ready made solution here http://www.tayloredge.com/reference/Circuits/ClockDivider2/.

Using standard logic devices a '4060 will divide by 16384, followed by a '4024, '390 or '393 plus gate to divide by 60

Jim
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2011
  • Country: nl
Re: counter required to count to near 1 million
« Reply #13 on: March 17, 2013, 10:10:28 pm »
The MCU gets my vote.

... even if it is a PIC. XD
 

Offline Thor-Arne

  • Supporter
  • ****
  • Posts: 503
  • Country: no
  • tinker - tinker, little noob.....
Re: counter required to count to near 1 million
« Reply #14 on: March 17, 2013, 10:13:51 pm »
As has been said PIC route is the simplest, there's a ready made solution here http://www.tayloredge.com/reference/Circuits/ClockDivider2/.

Using standard logic devices a '4060 will divide by 16384, followed by a '4024, '390 or '393 plus gate to divide by 60

I agree, this is the simplest solution.  ;)
 

Online rdl

  • Super Contributor
  • ***
  • Posts: 2928
  • Country: us
Re: counter required to count to near 1 million
« Reply #15 on: March 17, 2013, 10:24:16 pm »
Could you use a higher frequency crystal with a 4521?
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 7571
  • Country: nz
Re: counter required to count to near 1 million
« Reply #16 on: March 17, 2013, 10:27:53 pm »
Using standard logic devices a '4060 will divide by 16384, followed by a '4024, '390 or '393 plus gate to divide by 60

how would it work?
32768Hz / 16384 = 2 second clock
2Hz / 60 = 33ms clock
Greek letter 'Psi' (not Pounds per Square Inch)
 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 4283
  • Country: nl
Re: counter required to count to near 1 million
« Reply #17 on: March 17, 2013, 10:37:46 pm »
how would it work?
32768Hz / 16384 = 2 second clock
2Hz / 60 = 33ms clock

Having a bad day Psi?
32768Hz / 16384 = 0.5 second
0.5 second / 60 = 30 second
Just saying...
Keyboard error: Press F1 to continue.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #18 on: March 17, 2013, 10:56:24 pm »
the MCU is out, I'm getting fed up with MCU's at the moment as nothing about C is made simple and when you nearly have your problem solved but for a detail and ask a question on a forum you get told you missed some basic concept and have to go back to learning. Waste of time.

From my school days i seems to remember that I can have a counter that counts to t least what i need and use logic gates to sent out a reset signal at the right count, simples I'll get it done faster with basic digital circuitry than any of the MCU jargons, anythinf complex i'll take to an arduino, sad i know but as it is only with arduino that everything is made easy for idiots like me that is the route i will have to take.

My main concern is that I remeber something about counters not being sycronous and drifting due to propagation delays as one flip/flop clocked another, that is my main concern. What about the HCF4060M013TR ? it has built in oscillator circuitry
« Last Edit: March 17, 2013, 11:03:31 pm by Simon »
 

Offline jpb

  • Super Contributor
  • ***
  • Posts: 1706
  • Country: gb
Re: counter required to count to near 1 million
« Reply #19 on: March 17, 2013, 11:04:10 pm »
 A brief search at Farnell  led to the SN74LV8154N which can be used as a 32 bit counter (you need 20 bits I guess). It is a dual 16bit but can be connected as one 32bit. They only seem to have the SMD version in stock. You might need a 4 input AND gate (or 3 x 2 input AND gates) to detect when it reaches 0xF0000 and use that as both a reset and the clock (I may be out by one on this but the error of 1 part in a million is probably worth living with to simplify the circuit).
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: counter required to count to near 1 million
« Reply #20 on: March 17, 2013, 11:04:51 pm »
the MCU is out, I'm getting fed up with MCU's at the moment as nothing about C is made simple

 :-DD Then I guess my suggestion of PIC10F200 is way the hell out! With 384 bytes ROM and 16 bytes RAM, I don't think you'd have much luck programming it in anything but assembly.

I can definitely understand the draw of discrete logic chips. I use them a lot and love them. Sorry I can't help much with this specific problem though, if you want to use discrete logic - digital timing isn't exactly my forte.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #21 on: March 17, 2013, 11:09:30 pm »
A brief search at Farnell  led to the SN74LV8154N which can be used as a 32 bit counter (you need 20 bits I guess). It is a dual 16bit but can be connected as one 32bit. They only seem to have the SMD version in stock. You might need a 4 input AND gate (or 3 x 2 input AND gates) to detect when it reaches 0xF0000 and use that as both a reset and the clock (I may be out by one on this but the error of 1 part in a million is probably worth living with to simplify the circuit).

so long as it does not have ripple type drift problems. I don't mind a slightly more complicated logic gate array to detect the overflow.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: counter required to count to near 1 million
« Reply #22 on: March 17, 2013, 11:59:51 pm »
the MCU is out, I'm getting fed up with MCU's at the moment as nothing about C is made simple and when you nearly have your problem solved but for a detail and ask a question on a forum you get told you missed some basic concept and have to go back to learning. Waste of time.

Sounds like you need to put in some time to learn how to write (C or asm) code.  The real waste of time happens when you refuse to learn.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #23 on: March 18, 2013, 12:01:39 am »
What about the HCF4060M013TR ? it has built in oscillator circuitry
I've never been a fan of the 4060. A better discrete chip for large counts is the MC14541B. It has 2^8, 2^10, 2^13, and 2^16 outputs, with the built-in oscillator circuitry, and pin controls for auto-reset and output logic level - plus it's not a ripple counter like the 4060 - and has a smaller pin count.

Combine this with any Divide-by-N 4-bit counter (like the MC14526B) and you can easily have precision 30 second pulses from 32kHz - done completely with synchronous counters - and without the need for any extra gates.
« Last Edit: March 18, 2013, 12:28:06 am by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #24 on: March 18, 2013, 07:06:55 am »
So do I need to specifically look for a synchronized counter to make sure it does not drift off timing due to propagation delays ?
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #25 on: March 18, 2013, 07:10:12 am »
the MCU is out, I'm getting fed up with MCU's at the moment as nothing about C is made simple and when you nearly have your problem solved but for a detail and ask a question on a forum you get told you missed some basic concept and have to go back to learning. Waste of time.

Sounds like you need to put in some time to learn how to write (C or asm) code.  The real waste of time happens when you refuse to learn.

I conclude my dyslexia must be worse than I realized as what seems simple to everyone else I am mystified by. I will go forth with the arduino for now (I never dreamt I'd ever have to say that) as at least stuff is plainly explained all in one place and I don't have to read books written for PC's to adapt to different hardware and try and understand how to use libraries.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: counter required to count to near 1 million
« Reply #26 on: March 18, 2013, 08:07:45 am »
Honestly, some people poo-poo the Arduino but it really can help people get over that initial hurdle in programming.

I even used one recently to delve into the world of touch screens at short notice.  Thanks to the "sketches" available I had it running in minutes. That showed me that it should be equally doable on a PIC without reinventing the wheel.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #27 on: March 18, 2013, 08:14:08 am »
you may not be doing it on a pic as it is avr's that have built in touch sense interfaces. Unless your looking at a secondary unit dedicated to the touch bit
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: counter required to count to near 1 million
« Reply #28 on: March 18, 2013, 08:20:21 am »
you may not be doing it on a pic as it is avr's that have built in touch sense interfaces. Unless your looking at a secondary unit dedicated to the touch bit

Almost all of the TFT screens with touch on eBay, etc come with the LCD controller and touch A2D chips.  The UTFT and UTouch libraries make it super simple on the Arduino and it shouldn't be too much harder on a PIC.   :)
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #29 on: March 18, 2013, 08:30:59 am »
So do I need to specifically look for a synchronized counter to make sure it does not drift off timing due to propagation delays ?

Anyone got an answer ?
 

Offline Thor-Arne

  • Supporter
  • ****
  • Posts: 503
  • Country: no
  • tinker - tinker, little noob.....
Re: counter required to count to near 1 million
« Reply #30 on: March 18, 2013, 09:21:35 am »
So do I need to specifically look for a synchronized counter to make sure it does not drift off timing due to propagation delays ?

Anyone got an answer ?
If my memory serves me well, the propagation delay issue was quite high in frequency, between 10 and 20 MHz.

Take a look at the 74HC4060 you can use a couple of those to divide the 32.768kHz down to 2 Hz (divide by 256 and divide 64). It has internal gates for hooking up a crystal- or rc-oscillator.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #31 on: March 18, 2013, 09:32:38 am »
So do I need to specifically look for a synchronized counter to make sure it does not drift off timing due to propagation delays ?

It's not about drift but unstable outputs (since overflow ripples). For most uses (especially divide-by-n), it doesn't make any difference.

Take a look at the 74HC4060 you can use a couple of those to divide the 32.768kHz down to 2 Hz (divide by 256 and divide 64). It has internal gates for hooking up a crystal- or rc-oscillator.

As mentioned already, the 4541 is a better chip than the 4060 - and also has the built-in oscillator..
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 7571
  • Country: nz
Re: counter required to count to near 1 million
« Reply #32 on: March 18, 2013, 09:52:18 am »
how would it work?
32768Hz / 16384 = 2 second clock
2Hz / 60 = 33ms clock

Having a bad day Psi?
32768Hz / 16384 = 0.5 second
0.5 second / 60 = 30 second
Just saying...

lol, yeah, bad day  ::)
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #33 on: March 18, 2013, 10:08:56 am »
I think i may be getting confused between lack of synchronization between outputs and frequency error. I'll have a look at some of the suggested parts
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #34 on: March 18, 2013, 11:04:30 am »
The 4541 will not use a crystal and only has certain outputs available
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 12124
  • Country: gb
    • Mike's Electric Stuff
Re: counter required to count to near 1 million
« Reply #35 on: March 18, 2013, 11:55:33 am »

 :-DD Then I guess my suggestion of PIC10F200 is way the hell out! With 384 bytes ROM and 16 bytes RAM, I don't think you'd have much luck programming it in anything but assembly.

It's entirely feasible to do C on the 10F200 (using the non-free version of the microchip compiler).
If written carefully, efficiency isn't that far off assembler.
For something a simple as this, probably even the free version and sloppy coding would still do the job
 
 
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #36 on: March 18, 2013, 11:58:18 am »
except I want to do this the old fashioned way. It will drive an old clock so still be in keeping ;)
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #37 on: March 18, 2013, 12:36:18 pm »
The 4541 will not use a crystal and only has certain outputs available

True - I've always had an external clock available when I used it - although I do wonder if hooking a crystal up to the RC pins (as shown for a 4060) wouldn't work just fine - I'll have to breadboard that if I get a chance. As far has only having certain outputs available, for high counts (like one million) the salient point is the highest division output - with a 32kHz frequency, the 4060 divides down to a minimum of 2Hz; the 4541 down to .5Hz - which just means 4 bits more needed to get to .033Hz (30 seconds) - instead of 6.

But in any case, if you use a divide-by-n counter as the final stage you can avoid extra decode logic. So if you combine a 4060 (2Hz frequency at it's 2^14 output) with, for example, a MC14569B (which is a divide-by-n dual 4-bit counter), you can have any timing period between 1 - 127.5 seconds (in .5 second increments) - settable with switches if desired.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #38 on: March 18, 2013, 12:41:31 pm »
yes that is true
 

Offline olsenn

  • Frequent Contributor
  • **
  • Posts: 993
Re: counter required to count to near 1 million
« Reply #39 on: March 18, 2013, 12:44:05 pm »
I just finished making a frequency counter with the Timer/Counter1 module of a Atmel Atmega328P. Technically the counter is 16-bit, but by incrementing a variable on overflow, you can keep track of as many counts as you'd like.

I'm not sure if this helps?
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #40 on: March 18, 2013, 12:45:06 pm »
well I'm going to avoid an MCU on this one
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 12124
  • Country: gb
    • Mike's Electric Stuff
Re: counter required to count to near 1 million
« Reply #41 on: March 18, 2013, 01:45:50 pm »
In terms of cost vs. division ratio, the (74hc)4020,40 and 60 are hard to beat if you can live with binary ratio. The HC4060 has an oscillator as well, so probably a very cheap 2-chip solution.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #42 on: March 18, 2013, 03:07:17 pm »
what do you mean by binary ratio ? like 1000 versus 1024 ?
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #43 on: March 18, 2013, 03:40:00 pm »
what do you mean by binary ratio ? like 1000 versus 1024 ?

Most discrete chips which can count very high are binary counters, so they do binary division - divide by 2, 4, 8, 16, etc; i.e. 2^n.  This matters when you consider what frequency you are starting with - and what frequency you want to end up with. In your case, starting with 32.768kHz and wanting to end with .033Hz means that you can't do it with a simple binary divide. OTOH, if you wanted to end up with a 32 second pulse, this would be easy to do with a single chip (like the MC14536B) since .03125Hz is 32768 divided by 2^20.

Since you want a final frequency which is not evenly divisible (from 32768) by a power of 2 (and you don't want to use an MCU), you have to use a minimum of two discrete chips - either two counters or a counter and decode logic. In binary terms (or hex for easier writing), you want to divide 8000h by F0000h.
 

Offline SeanB

  • Super Contributor
  • ***
  • Posts: 15381
  • Country: za
Re: counter required to count to near 1 million
« Reply #44 on: March 18, 2013, 03:49:59 pm »
Divide by 2 instead of divide by ten. Much simpler with the logic, as there is only one pin to decode. With divide by 10 you need to decode a few pins to get the terminal count and use that to reset the counter.

As to ripple counters having issues, it is only if you are using them and decoding the outputs, which can very briefly have invalid counts as the counters change state, the count ripples down the chain from the fastest to the slowest. Only an issue if you are latching the outputs, if you are going to just decode to get the TC to reset you just add a RC delay to the comparator output to both ignore these very short duration pulses and to get a long enough reset pulse so the counters are going to be reset correctly ( nothing worse than having half the counters being reset by a too short pulse, it just needs to be less in time than a half of your clock, at 32kHz that will be pretty long).

If you are using a clock crystal drive it with a 4007 uncommitted gate, there is a 32kHz oscillator in the appnotes that has both low drift and low drive so it has best accuracy.

Otherwise just take a clock module and power it off 1V5 from a red LED, and use the drive pulses to clock a pair of 4017 chips arranged as a divide by 3 and the other as divide by 10 ( no jumpers at all) and use either the carry out to give a 15s pulse or one of the count outputs to give a 3s clock.
 

Offline jimmc

  • Frequent Contributor
  • **
  • Posts: 284
  • Country: gb
Re: counter required to count to near 1 million
« Reply #45 on: March 18, 2013, 04:24:58 pm »
I think Sean has covered most of it.
I would just point out that the internal oscillator of the '4060 can drive a 32768Hz crystal e.g. http://www.doctronics.co.uk/4060.htm.

Turn away now Simon. :)

As an idea of what can be done with a PIC see http://www.leapsecond.com/tools/PPSDIV.ASM
9 simultaneous square wave outputs -- one for each frequency decade from 100 kHz to 0.001 Hz (1000 s) from a 10MHz clock!

Jim
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #46 on: March 18, 2013, 04:36:22 pm »


Turn away now Simon. :)

As an idea of what can be done with a PIC see http://www.leapsecond.com/tools/PPSDIV.ASM
9 simultaneous square wave outputs -- one for each frequency decade from 100 kHz to 0.001 Hz (1000 s) from a 10MHz clock!

Jim

The sort of thing I'd have been doing as a full version but not right now. I just need to get this thing ticking every 30s
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #47 on: March 18, 2013, 04:39:29 pm »
If you are using a clock crystal drive it with a 4007 uncommitted gate, there is a 32kHz oscillator in the appnotes that has both low drift and low drive so it has best accuracy.

As many people already pointed out here, you can hook a 32kHz crystal directly to a 4060 - so why would you need a 4007?

Quote
Otherwise just take a clock module and power it off 1V5 from a red LED, and use the drive pulses to clock a pair of 4017 chips arranged as a divide by 3 and the other as divide by 10 ( no jumpers at all) and use either the carry out to give a 15s pulse or one of the count outputs to give a 3s clock.

Not sure what you mean by 'clock module', but this solution seems odd to say the least. The frequency he's after is not evenly divisible by 10 either, so why use decade counters? It's less counting in the same package size - and even with two of them cascaded the lowest frequency you could get from 32.768kHz is 327Hz - far from what he's after. This makes no sense - in less, by 'clock module' you mean a NON-discrete logic chip - which seems to defeat the point of the discussion - I thought we were talking about how to accomplish it with a couple of discrete chips.
« Last Edit: March 18, 2013, 04:42:23 pm by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #48 on: March 18, 2013, 04:42:29 pm »
At the moment I'm looking at a 4541 followed by any other counter that will finish it off right. As I'll have logic gates knocking around anyway I can use one or two to make the clock gen
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #49 on: March 18, 2013, 04:52:11 pm »
At the moment I'm looking at a 4541 followed by any other counter that will finish it off right. As I'll have logic gates knocking around anyway I can use one or two to make the clock gen

What are your parameters for the output pulse (I mean, aside from the 30s frequency)? Is there a minimum or maximum pulse length?
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #50 on: March 18, 2013, 05:32:45 pm »
not really, i'll need to have a bit of pulse circuitry connected to the reset line so that when the reset is trigered it make the pulse fire a pulse, even if it is something like charging a capacitor with resistor in parallel with a comparator or opamp
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #51 on: March 18, 2013, 05:33:48 pm »
At the moment I'm looking at a 4541 followed by any other counter that will finish it off right. As I'll have logic gates knocking around anyway I can use one or two to make the clock gen

Well, if you don't need the oscillator section of the 4541 - and can provide the 32768Hz clock signal from elsewhere - I would suggest using the 4541 as the last stage of the counter - as shown in the attached drawing. If you do it this way, you can set whether the output pulse every 30 seconds is positive or negative-going by just tying pin 9 on the 4541 high or low.
« Last Edit: March 18, 2013, 05:35:43 pm by marmad »
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #52 on: March 18, 2013, 05:43:53 pm »
Hmm... just realized that the HEF4526B may not be the cheapest divide-by-n counter  ;) - if so, you can substitute any divide-by-n 4-bit counter (dual or otherwise) - I haven't used any for awhile so I don't know which is currently the cheapest. You just want to divide by 15 before the 4541.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #53 on: March 18, 2013, 07:21:55 pm »
@Simon - BTW, I just breadboarded a 4541 clocked by a 32.768kHz crystal hooked to the built-in oscillator pins 1 and 3 (similar to the circuit shown in 4060 datasheets). As I thought, it's no problem at all getting it to work - I got a solid .5Hz output after tinkering with the load capacitor.
« Last Edit: March 18, 2013, 07:28:10 pm by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #54 on: March 18, 2013, 10:45:14 pm »
You mean it works ?
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #55 on: March 19, 2013, 01:23:46 am »
You mean it works ?

Yes, it worked fine - I got a perfect 500mHz square wave out at pin 8 of the 4541. Because you can basically hook up a crystal to any CMOS inverter or inverting gate (within the frequency limits of the device, of course). You're just biasing the inverter into it's linear region and using it like an amplifier with a feedback network that includes the crystal.

Edit: If you'd like, I'll draw the modified schematic including the crystal oscillator components - for the 33mHz output frequency.
« Last Edit: March 19, 2013, 02:35:07 am by marmad »
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2094
Re: counter required to count to near 1 million
« Reply #56 on: March 19, 2013, 01:33:59 am »

 :-DD Then I guess my suggestion of PIC10F200 is way the hell out! With 384 bytes ROM and 16 bytes RAM, I don't think you'd have much luck programming it in anything but assembly.

It's entirely feasible to do C on the 10F200 (using the non-free version of the microchip compiler).
If written carefully, efficiency isn't that far off assembler.
For something a simple as this, probably even the free version and sloppy coding would still do the job

Complete program for a PIC12F1822 which uses 4.1% of available program memory with the crappy free XC8 compiler (2.9% with the pro version). It pulses pin 5 high for 2 seconds in 30.

Code: [Select]
// PIC 12F1822 Timer project

#include <pic.h>

// Some Types
typedef unsigned long Dword;
typedef unsigned int Word;
typedef unsigned char Byte;
typedef signed char Char;       
typedef unsigned char Bool;
typedef bit Bit;

// PIC12F/LF1822 Configuration pragmas
 
// Oscillator Selection
// #pragma config FOSC=ECH      // External Clock, High Power Mode (4-32 MHz): device clock supplied to CLKIN pin
// #pragma config FOSC=ECM      // External Clock, Medium Power Mode (0.5-4 MHz): device clock supplied to CLKIN pin
// #pragma config FOSC=ECL      // External Clock, Low Power Mode (0-0.5 MHz): device clock supplied to CLKIN pin   
   #pragma config FOSC=INTOSC   // Internal Oscillator: I/O function on CLKIN pin
// #pragma config FOSC=EXTRC    // External Oscillator: External RC circuit connected to CLKIN pin
// #pragma config FOSC=HS       // High-Speed crystal/resonator connected between OSC1 and OSC2 pins
// #pragma config FOSC=XT       // Crystal/resonator connected between OSC1 and OSC2 pins
// #pragma config FOSC=LP       // Low-power crystal connected between OSC1 and OSC2 pins

// Watchdog Timer Enable
   #pragma config WDTE=ON       // Enabled
// #pragma config WDTE=NSLEEP   // Enabled while running and disabled in Sleep
// #pragma config WDTE=SWDTEN   // Controlled by the SWDTEN bit in the WDTCON register
// #pragma config WDTE=OFF      // Disabled

// Power-up Timer Enable
// #pragma config PWRTE=OFF     // Disabled       
   #pragma config PWRTE=ON      // Enabled

// MCLR Pin Function Select
   #pragma config MCLRE=ON      // MCLR/VPP pin function is MCLR
// #pragma config MCLRE=OFF     // MCLR/VPP pin function is digital input

// Flash Program Memory Code Protection
   #pragma config CP=OFF        // Disabled
// #pragma config CP=ON         // Enabled

// Data Memory Code Protection
   #pragma config CPD=OFF       // Disabled
// #pragma config CPD=ON        // Enabled

// Brown-out Reset Enable
   #pragma config BOREN=ON         // Enabled
// #pragma config BOREN=NSLEEP     // Enabled while running and disabled in Sleep
// #pragma config BOREN=SBODEN     // Controlled by the SBOREN bit in the BORCON register
// #pragma config BOREN=OFF        // Disabled

// Clock Out Enable
   #pragma config CLKOUTEN=OFF     // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
// #pragma config CLKOUTEN=ON      // CLKOUT function is enabled on the CLKOUT pin

// Internal/External Clock Switchover
// #pragma config IESO=ON          // Enabled
   #pragma config IESO=OFF         // Disabled

// Fail-Safe Clock Monitor
// #pragma config FCMEN=ON         // Enabled
   #pragma config FCMEN=OFF        // Disabled

// Flash Memory Self-Write Protection
   #pragma config WRT=OFF          // Write protection off                                                         
// #pragma config WRT=BOOT         // 000h to 1FFh write protected, 200h to 7FFh may be modified by EECON control
// #pragma config WRT=HALF         // 000h to 3FFh write protected, 400h to 7FFh may be modified by EECON control
// #pragma config WRT=ALL          // 000h to 7FFh write protected, no addresses may be modified by EECON control 

// X4 Clock PLL
// #pragma config PLLEN=ON         // Enabled 
  #pragma config PLLEN=OFF         // Disabled

// Stack Overflow/Underflow Reset
   #pragma config STVREN=ON        // Enabled 
// #pragma config STVREN=OFF       // Disabled

// Brown-out Reset Voltage Selection
// #pragma config BORV=LO          // Low trip point selected
   #pragma config BORV=HI          // High trip point selected

// Low-Voltage Programming
   #pragma config LVP=ON           // Enabled
// #pragma config LVP=OFF          // Disabled, high voltage on MCLR/VPP must be used for programming

// ID Location value assignment
#pragma config IDLOC0=0
#pragma config IDLOC1=0
#pragma config IDLOC2=0
#pragma config IDLOC3=0


// Counts down and kicks watchdog if not zero in timer interrupt
volatile Byte wd_interlock;


//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// initialise - set up all hardware

void
initialise(void) {

    // OSCON Defaults to 500kHz for INTOSC

    LATA = 0x00;
    ANSELA = 0x00;          // All I/O digital
    TRISA = 0x00;           // All outputs

    WDTCONbits.WDTPS = 12;  // approx 4 second watchdog time out

    // Setup Timer 1 to use 32kHz external crystal and generate
    // a timer interrupt at 0.5Hz

    // Disable Gate function
    T1GCON = 0x00;

    // Select T1OSC crystal, prescale of 1, enable T1OSC, no sync with FOSC
    // Timer 1 disabled
    T1CON = 0x8C;

    // Wait for T1OSC stable
    while(!OSCSTATbits.T1OSCR) {
    };

    // Clear Timer 1 interrupt flag and enable Timer 1 interrupts
    TMR1IF = 0;
    TMR1IE = 1;

    // Enable general and peripheral ints
    INTCON = 0xC0;

    // Run timer
    T1CONbits.TMR1ON = 1;   
}



//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Interrupt Service         
void interrupt
isr(void) {

    static Byte sec2 = 0;

    // Timer 1 interrupt at 0.5 Hz.
    if(TMR1IF) {
        TMR1IF = 0;

        // Handle watchdog and interlock
        if(wd_interlock) {
            wd_interlock--;
            CLRWDT();
        }

        // Count 15 interrupts in 30 seconds, set RA2 high for
        // 2 seconds
        sec2++;
        if(sec2 > 14) {
            sec2 = 0;
            LATAbits.LATA2 = 1;
        } else {
            LATAbits.LATA2 = 0;
        }
    }
}



//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//
void
main(void) {     

    initialise();

    for(;;) {           // Loop forever
       
        wd_interlock = 10;
        SLEEP();
    }
}

The 12F1822 might be a bit overkill but I had a spare tube of them and they are still only 85p 1 off of in DIP8 from Farnell. It has a specific 32kHz low power oscillator functional in sleep mode, haven't looked if anything cheaper has that. Timing was about 150 ppm fast with just a junk box watch crystal plugged into a bread board. Pulled about 28uA running on 3.3v.


 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #57 on: March 19, 2013, 01:38:32 am »
Do people even read previous messages posted in the threads here?

Without going back and re-reading, I'd estimate that Simon has stated between 5 - 10 times that he doesn't want to use an MCU.
« Last Edit: March 19, 2013, 01:42:15 am by marmad »
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: counter required to count to near 1 million
« Reply #58 on: March 19, 2013, 02:16:39 am »
Do people even read previous messages posted in the threads here?

Without going back and re-reading, I'd estimate that Simon has stated between 5 - 10 times that he doesn't want to use an MCU.

A MCU solution could help plenty of other people though.  Sometimes threads spawn some great ideas.

If Simon doesn't feel up to using a MCU, then he can still phaff around with the other methods and get there eventually.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #59 on: March 19, 2013, 02:30:18 am »
A MCU solution could help plenty of other people though.  Sometimes threads spawn some great ideas.

That's true - although it would feel more like a real discussion - and that people were actually perusing the thread - if they mentioned that fact. When people don't bother to do that, you get multiple posts all saying the same thing - such as the 5 or 6 people who each suggested the 4060 chip - as if they were the first to do so.  Just saying...  :P
 

Offline robrenz

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
  • Real Machinist, Wannabe EE
Re: counter required to count to near 1 million
« Reply #60 on: March 19, 2013, 03:03:13 am »
Do people even read previous messages posted in the threads here?

Without going back and re-reading, I'd estimate that Simon has stated between 5 - 10 times that he doesn't want to use an MCU.

IMO only because he does not have the time for the learning curve at the moment. If presented with a canned solution that he could plug and play he may change his mind. I dont think the post is out of line

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: counter required to count to near 1 million
« Reply #61 on: March 19, 2013, 03:38:45 am »
Here are a couple of ideas if your design isn't tied to a 32.768kHz crystal and really just require a pulse every 30 seconds...

Idea #1: Use a 74HC5555 and a 3.932160 MHz crystal.  Have the 74HC5555 divide by 217.  This will give a pulse exactly every 30 seconds.

Idea #2: Use a 30.72kHz crystal with a simple Pierce oscillator and a divide by 1024 IC.  (Or 512? or 2048?  My brain's not working at the moment.)
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #62 on: March 19, 2013, 04:04:02 am »
Idea #1: Use a 74HC5555 and a 3.932160 MHz crystal.  Have the 74HC5555 divide by 217.  This will give a pulse exactly every 30 seconds.

This will give a frequency of 30Hz (a period every 33mS) - not 33mHz (a period every 30 seconds).

Quote
Idea #2: Use a 30.72kHz crystal with a simple Pierce oscillator and a divide by 1024 IC.  (Or 512? or 2048?  My brain's not working at the moment.)

This also gives 30Hz - not 33mHz. It seems you're confused between frequency and period. It's not possible to get to the correct frequency using either of the crystal frequencies you mentioned and a single undecoded binary divider-chain.
« Last Edit: March 19, 2013, 04:07:16 am by marmad »
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: counter required to count to near 1 million
« Reply #63 on: March 19, 2013, 04:27:49 am »
Idea #1: Use a 74HC5555 and a 3.932160 MHz crystal.  Have the 74HC5555 divide by 217.  This will give a pulse exactly every 30 seconds.

This will give a frequency of 30Hz (a period every 33mS) - not 33mHz (a period every 30 seconds).

Quote
Idea #2: Use a 30.72kHz crystal with a simple Pierce oscillator and a divide by 1024 IC.  (Or 512? or 2048?  My brain's not working at the moment.)

This also gives 30Hz - not 33mHz. It seems you're confused between frequency and period. It's not possible to get to the correct frequency using either of the crystal frequencies you mentioned and a single undecoded binary divider-chain.

Yep.  I stand corrected.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: counter required to count to near 1 million
« Reply #64 on: March 19, 2013, 06:36:10 am »
Use a PIC.   >:D
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #65 on: March 19, 2013, 01:03:09 pm »
@Simon - Here is a quickly revised schematic (sorry about the sloppiness) showing the entire circuit with crystal putting out a 33mHz frequency (30 sec period) in it's simplest form (plus a DSO image of the output of the 4541). I don't think there's an easier - or smaller package count - way to do this using discrete chips. If you wanted programmability, adding switches to the 4526 could allow you to change the period from 4 - 32 seconds in 2 second increments - and adding a switch to the 4541 could give you shorter periods, for example, 0.5 - 4 seconds in 0.25 second increments. Of course, as many have mentioned, with a few lines of code it's incredibly simple to do using an MCU - and more flexible in the long run - but sometimes the old-fashioned way is kind of fun  ;)

Edit: Just did a quick check and it seems the 74HCT161 (another divide-by-n 4 bit counter) is perhaps a better buy than the HEF4526 - it just depends on what package size you need and if you plan on using higher CMOS voltages.
« Last Edit: March 19, 2013, 01:24:16 pm by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #66 on: March 19, 2013, 03:04:13 pm »
well I've got nothing against micro's I just had this row on the avr forum about the documentation of the libs. It seems that unless your a pro in programming mcu's take for ever so I'm going to give them a break, do some descrete stuff and play with the arduino for a bit.
 

Offline olsenn

  • Frequent Contributor
  • **
  • Posts: 993
Re: counter required to count to near 1 million
« Reply #67 on: March 19, 2013, 03:17:11 pm »
I can send you the code for my frequency counter if you'd like... you'll see just how easy using the built-in 16-bit counter of the atmega328 is. The best part is, if you have an Arduino, you already have the IC
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #68 on: March 19, 2013, 03:21:42 pm »
sure why now, I'll have a look
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: counter required to count to near 1 million
« Reply #69 on: March 19, 2013, 03:26:34 pm »
I can send you the code for my frequency counter if you'd like... you'll see just how easy using the built-in 16-bit counter of the atmega328 is. The best part is, if you have an Arduino, you already have the IC

Shhh... I was about to do a freq counter all in 7400s just for the fun of designing it. Stop tempting me with MCUs!  :)

(Oh well, I guess I'll at least need an external divider for the higher frequencies anyway...)
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #70 on: March 19, 2013, 03:27:35 pm »
haha, I guess a discrete solution will end up needing a wall wart
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: counter required to count to near 1 million
« Reply #71 on: March 19, 2013, 03:45:20 pm »
It seems that unless your a pro in programming mcu's take for ever

Programming and electronics intersect often, but they're definitely very different skills that each take a long time to master. I highly recommend anyone interested in either one to diversify and cross over into the other, but it's not easy. I sometimes forget that - I'll recommend a MCU for something as if it's "easy" to just bang out some code, but I've been programming since I was eight years old and it's as easy for me at this point to write "instructions" in C or assembly as to write them in English. I can forget that the process of going from "I want to do this" to finished code and an implementation is pretty daunting if you're not used to it.

Quote
I just had this row on the avr forum about the documentation of the libs

They're programmers. You can't tell them that their favorite stuff sucks, that's heresy. (AVR documentation in general does suck, and the library documentation sucks even harder. I'm with you there.)
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline Thor-Arne

  • Supporter
  • ****
  • Posts: 503
  • Country: no
  • tinker - tinker, little noob.....
Re: counter required to count to near 1 million
« Reply #72 on: March 19, 2013, 04:43:01 pm »
Shhh... I was about to do a freq counter all in 7400s just for the fun of designing it. Stop tempting me with MCUs!  :)

(Oh well, I guess I'll at least need an external divider for the higher frequencies anyway...)
It's fun playing with counters, get on with it.  ;)

I have one more or less compete sitting on a breadboard, just the control-timing left to do.
While waiting for parts for another project I got bored and slammed it together.  ;D
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #73 on: March 19, 2013, 05:02:59 pm »
I highly recommend anyone interested in either one to diversify and cross over into the other, but it's not easy. I sometimes forget that - I'll recommend a MCU for something as if it's "easy" to just bang out some code, but I've been programming since I was eight years old and it's as easy for me at this point to write "instructions" in C or assembly as to write them in English. I can forget that the process of going from "I want to do this" to finished code and an implementation is pretty daunting if you're not used to it.

In terms of super long-term reliability and ultra-low current, MCU's still have a way to go to prove themselves. I still have ~40-year old objects built from discrete logic continuing to run merrily along - and +20-year old objects built from discrete CMOS logic still running off the same battery cell.  In the same few decades, I've had numerous expired MCU-based objects due to lost bits from ROMs, PROMs, EPROMs, EEPROMs, Flash ROMs, etc. Of course, I know that they get continually better - but they can't yet compete against discrete logic's track record.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #74 on: March 19, 2013, 05:46:18 pm »

I just had this row on the avr forum about the documentation of the libs

They're programmers. You can't tell them that their favorite stuff sucks, that's heresy. (AVR documentation in general does suck, and the library documentation sucks even harder. I'm with you there.)

To be fair pics are equally confusing and lacking, people either try to explain what a digital signal is or how some function works without the bit in the middle, So I think it's a combination of me being very dense and people who can't be bothered to write proper instructions.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #75 on: March 19, 2013, 05:48:23 pm »
The 12F1822 might be a bit overkill but I had a spare tube of them and they are still only 85p 1 off of in DIP8 from Farnell. It has a specific 32kHz low power oscillator functional in sleep mode, haven't looked if anything cheaper has that. Timing was about 150 ppm fast with just a junk box watch crystal plugged into a bread board. Pulled about 28uA running on 3.3v.

Just for comparison purposes, the discrete circuit shown in the previous schematic (MC14541 + HEF4526) uses ~5.2uA at 3V, ~12uA at 3.3V, or ~24uA at 5V. Attached is an image of the 4526 output.
 

Offline olsenn

  • Frequent Contributor
  • **
  • Posts: 993
Re: counter required to count to near 1 million
« Reply #76 on: March 19, 2013, 08:19:49 pm »
As promised, here's my frequency counter. Don't worry about the lcd stuff, that's just my way of displaying the value on a HD44780. It's very simple

#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#include "lcd.h"

/* Definitions */
#define F_CPU 25000000

/* Prototypes */
void startTimer100mSec(void);
void startTimer1Sec(void);
void startTimer10Sec(void);

/* Declarations */
volatile unsigned long int overflow0, overflow1, frequency;
char disp[15];

/* Interrupt Handlers */
ISR (TIMER0_OVF_vect){
   overflow0++;
}   

ISR (TIMER1_OVF_vect){
   overflow1++;
}   

/* Functions */
void startTimer100mSec(void){
   unsigned long int tmp;
   tmp = F_CPU/10;
   overflow0 = 0;
   TCNT0 = 0;
   while((overflow0*256 + TCNT0) < tmp) {}
   return;
}   

void startTimer1Sec(void){
   overflow0 = 0;
   TCNT0 = 0;
   while((overflow0*256 + TCNT0) < F_CPU) {}
   return;
}

void startTimer10Sec(void){
   unsigned long int tmp;
   tmp = 10*F_CPU;
   overflow0 = 0;
   TCNT0 = 0;
   while((overflow0*256 + TCNT0) < tmp) {}
   return;
}        

int main(void)
{
   DDRB = 0x3E;              // PB0=Input, PB1-PB5=Output
   
   /* Timer/Counter0 - Gate Time */
   PRR = (0<<PRTIM0);        // Power-on Timer/Counter0
   TCCR0A = 0;               // Normal Mode
   TCCR0B = 1;               // No Prescaler
   TIMSK0 = 1;               // Enable Overflow Interrupt
   TCNT0 = 0;
   sei();
   
   /* Timer/Counter1 - Counter */
    PRR = (0<<PRTIM1);        // Power-on Timer/Counter1
   TCCR1A = 0;             
   TCCR1B = 7;               // Normal Mode, T1-Pin as Clk
   TIMSK1 = 1;               // Enable Overflow Interrupt
   TCNT1 = 0;                // Initialize Counter
   sei();                    // Enable Interrupts
   
/* Specifics */   
   lcd_init(LCD_DISP_ON);    
   while(1){
      frequency = 0;
      overflow0 = 0;
      overflow1 = 0;
      TCNT0 = 0;
      TCNT1 = 0;
      startTimer1Sec();
      frequency = (65535*overflow1) + TCNT1;
   
      sprintf(disp,"%lu",frequency);
       lcd_clrscr();
      lcd_home();
      lcd_puts(disp);
   }
    return 0;
}
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: counter required to count to near 1 million
« Reply #77 on: March 19, 2013, 08:22:36 pm »
Nice, clean code. I like it. Not a single line that I have a question about.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #78 on: March 29, 2013, 06:16:38 pm »
@Simon - Here is a quickly revised schematic (sorry about the sloppiness) showing the entire circuit with crystal putting out a 33mHz frequency (30 sec period) in it's simplest form (plus a DSO image of the output of the 4541). I don't think there's an easier - or smaller package count - way to do this using discrete chips. If you wanted programmability, adding switches to the 4526 could allow you to change the period from 4 - 32 seconds in 2 second increments - and adding a switch to the 4541 could give you shorter periods, for example, 0.5 - 4 seconds in 0.25 second increments. Of course, as many have mentioned, with a few lines of code it's incredibly simple to do using an MCU - and more flexible in the long run - but sometimes the old-fashioned way is kind of fun  ;)

Edit: Just did a quick check and it seems the 74HCT161 (another divide-by-n 4 bit counter) is perhaps a better buy than the HEF4526 - it just depends on what package size you need and if you plan on using higher CMOS voltages.

Hm, my result is rather different a short pulse every 2.5ish seconds, i need to go recheck. I couldn't work out what MR was on the 4526, is it Reset ?
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #79 on: March 29, 2013, 06:45:40 pm »
Hm, my result is rather different a short pulse every 2.5ish seconds, i need to go recheck. I couldn't work out what MR was on the 4526, is it Reset ?

Yes, MR is master reset - 0 = count / 1 = reset. If you are using my previously posted schematic, it sounds like the crystal may be running at a fifth harmonic or higher; use your DSO or a frequency counter to check the oscillator frequency at pin 1 to make sure you're getting the correct 32.768kHz.

If you're not, you might have to fiddle with the load capacitance of the p.i. network/low pass filter for the crystal - I didn't have any spare 20-30pF caps laying around when I breadboarded it, so I used 100 and 110pf - but the lower values might work better. You can experiment with a few sizes until you get a lock with the crystal.

Edit: If the oscillator frequency is good, then it would have to be incorrect logic in the divider chain.
« Last Edit: March 29, 2013, 06:51:10 pm by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #80 on: March 29, 2013, 06:55:04 pm »
ok, found my problem, I'm oscilating at about 200KHz, may i assume due to the breadboard concoction ?
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #81 on: March 29, 2013, 06:59:32 pm »
ok, found my problem, I'm oscilating at about 200KHz, may i assume due to the breadboard concoction ?

Yes - as noted above, I had only a few values of caps available to me when I breadboarded, so I experimented until I got a lock with the crystal at 32768Hz.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #82 on: March 29, 2013, 07:07:48 pm »
hm with 10pF I get nearly 1MHz  ;)

I've got wires going all over the place though and my 10M resistor is made up of 10x 1M resistors so i guess I've made a real mess. I guess I should get some 10M resistors and then try veroboard
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #83 on: March 29, 2013, 07:32:28 pm »
hm with 10pF I get nearly 1MHz  ;)

I've got wires going all over the place though and my 10M resistor is made up of 10x 1M resistors so i guess I've made a real mess. I guess I should get some 10M resistors and then try veroboard
My 10M was actually 2x 4.7M  :)   Try going slightly higher with the caps if you can - you're trying to create a low-pass filter that blocks the harmonics - while still allowing phase inversion. You can play with the 22k resistor as well: 22kOhms + 200pF is a 36kHz low-pass filter.  I still have my breadboard assembled so if you get stuck and need some help, let me know.
« Last Edit: March 29, 2013, 07:34:18 pm by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #84 on: March 29, 2013, 07:33:54 pm »
Rechecking I miswired it all. will have another go and let you know
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #85 on: March 29, 2013, 08:37:15 pm »
Right got it going, 100pF and 150-160K. Only problem is it i jump around near the circuit I get a load of oscilations that are much higher so cause false fires, could it be because I have the osciloscope connected ?, It was coming from the first counter on the low part of the cycle so maybe lack of load on the output ?
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #86 on: March 29, 2013, 08:52:52 pm »
Right got it going, 100pF and 150-160K. Only problem is it i jump around near the circuit I get a load of oscilations that are much higher so cause false fires, could it be because I have the osciloscope connected ?, It was coming from the first counter on the low part of the cycle so maybe lack of load on the output ?

If you have the DSO connected to the oscillator portion of the circuit (between pins 1 and 3 of 4541), you can affect the oscillation. Probably better to connect the DSO to the divider stage between chips (pin 8 on the 4541 should output 500mHz / 2 pulses per second) for final adjustment. CMOS doesn't normally require a load - it's output is a rail to rail swing.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #87 on: March 29, 2013, 09:14:17 pm »
BTW, it is important to remember with CMOS to pull all unused inputs high or low.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #88 on: March 29, 2013, 09:16:11 pm »
I think it is a grounding problem cause by the scope. The problem is not when I'm probing the oscillator but when just looking at either output stage. The random oscillations are occurring on the output of the first stage while the output is low. I'm not overly concerend for now as i also have a mess of wires on the breadboard that might be causing a problem.

My next job is to create the correct length pulse as a 1s pulse is too much, I'd rather have 50-100ms, I'm thinking a 555, but it seems the trigger pulse has to be shorter than the output pulse, they are suggesting AC coupling, I guess i'll need to use say a 2N7000 as a buffer between the counter and the 555 unless there are other tricks available to get the short pulse.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: counter required to count to near 1 million
« Reply #89 on: March 29, 2013, 09:17:03 pm »
Simon, this must surely be a "longest development time for a simple project" contender!  LOL
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #90 on: March 29, 2013, 09:34:59 pm »
I think it is a grounding problem cause by the scope. The problem is not when I'm probing the oscillator but when just looking at either output stage. The random oscillations are occurring on the output of the first stage while the output is low. I'm not overly concerend for now as i also have a mess of wires on the breadboard that might be causing a problem.
Very strange. CMOS is normally super-stable; I didn't have any problems with my breadboard once I got the crystal caps adjusted.

Quote
My next job is to create the correct length pulse as a 1s pulse is too much, I'd rather have 50-100ms, I'm thinking a 555, but it seems the trigger pulse has to be shorter than the output pulse, they are suggesting AC coupling, I guess i'll need to use say a 2N7000 as a buffer between the counter and the 555 unless there are other tricks available to get the short pulse.
Since you want a shorter output pulse than input, if you have a spare gate (or inverter), you can easily make an edge detector (half-monostable) circuit. See the bottom right of this diagram if you don't know what I mean. You just need a gate, cap, and resistor; for example, a 1M resistor and 100nF cap will give you an output pulse of ~80ms (T = .8RC).
« Last Edit: March 29, 2013, 09:53:57 pm by marmad »
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #91 on: March 29, 2013, 10:05:36 pm »
When I use to actually build these discrete logic circuits (doesn't happen much anymore  ;D ), I use to throw a MC14572 into the design as backup - it has 4x inverters, 1x 2-input NOR gate, and 1x 2-input NAND gate - which can be used in all kinds of different ways as glue logic.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #92 on: March 29, 2013, 10:48:56 pm »
I got it working with the 555, have the 100mS pulse, it is ticking nicely now but there is still instability with occasional bursts of clock that cuase the clock to tick more often than 30s, I'm now 3 minutes ahead in just under 15 minutes. Bearing in mind my breadboard is a mess of wires going up into the air and back again, it aint pretty so I guess that is a problem. Would I be best having a seperate clock gen ?

I mean If i put in a chip full of not gates I can use some for the clock and one for the edge detector, my 555 uses 3ma according to the datasheet so at the least I'd need to use the 1S pulse from the second counter to act on the enable pin as well as trigger the 555, not sure if that can be done with such close timings. i guess the cmos not gates will not use 3mA regardless ?
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #93 on: March 29, 2013, 10:50:27 pm »
Simon, this must surely be a "longest development time for a simple project" contender!  LOL

Well I took some time out due to other commitments, got around to ordering the parts and decided to do it this afternoon. I'm quite pleased with myself actually, working project in one afternoon but then I didn't design the counter circuitry so had a head start.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #94 on: March 29, 2013, 11:21:32 pm »
I got it working with the 555, have the 100mS pulse, it is ticking nicely now but there is still instability with occasional bursts of clock that cuase the clock to tick more often than 30s, I'm now 3 minutes ahead in just under 15 minutes. Bearing in mind my breadboard is a mess of wires going up into the air and back again, it aint pretty so I guess that is a problem. Would I be best having a seperate clock gen ?

Well, the crystal is oscillating through 5 gates inside the 4541 - as opposed to the usual single one. I didn't see any instability when I tested it - but I didn't run it for that long. As you mentioned, you can get around this problem - and add an edge detector - with a simple package of 4x NOR or NAND gates (or 6x inverters). Use one for the crystal oscillator, one as an output buffer between the oscillator and count input on the 4541 (to give it a nice full-amplitude square wave), one as the edge detector, and a spare to invert the edge detection output if needed (if you want a positive-going 50-100ms pulse).

Quote
I mean If i put in a chip full of not gates I can use some for the clock and one for the edge detector, my 555 uses 3ma according to the datasheet so at the least I'd need to use the 1S pulse from the second counter to act on the enable pin as well as trigger the 555, not sure if that can be done with such close timings. i guess the cmos not gates will not use 3mA regardless ?

No, not close to 3ma - it will use much less current then the 555.
« Last Edit: March 29, 2013, 11:48:47 pm by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #95 on: March 30, 2013, 08:43:02 am »
I'll use a set of nots then or maybe nands, I'll see what is cheaper and stock up. What is a good series of chips these days, I guess a CD4000 does not actually exist any more.

 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: counter required to count to near 1 million
« Reply #96 on: March 30, 2013, 08:48:43 am »
I'll use a set of nots then or maybe nands, I'll see what is cheaper and stock up. What is a good series of chips these days, I guess a CD4000 does not actually exist any more.
CD4000 maybe not, but HEF4000 is there and CD40106 at least is still kicking:http://www.digikey.com/product-search/en/integrated-circuits-ics/logic-gates-and-inverters/2556317?k=40106
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2011
  • Country: nl
Re: counter required to count to near 1 million
« Reply #97 on: March 30, 2013, 09:01:24 am »
As an aside ... if you DIY a oscillator from gates like this, then it can be advantageous to use a DFF at the end to serve as a divide by 2. Just connect nQ to D, and your oscillator output to CLK. That (mostly) takes care of any deviation from 50% duty cycyle you might have. Obviously you'll have to double the original clock frequency. ;)
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #98 on: March 30, 2013, 09:11:07 am »
Do you mean putting in a flip flop to act as a /2 counter ? Not much point really. I can't double the frequency as it's a watch crystal and if i did I'd just alter the second stage to divide by less to compensate. If i were to make more of these I'd put a dip-switch on the second counter to make it flexible for different timings
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2011
  • Country: nl
Re: counter required to count to near 1 million
« Reply #99 on: March 30, 2013, 09:55:53 am »
Well, as stated this is only if you have control over the input frequency and can double it. Or compensate for the output frequency being half in some other way. If not, well then that's out. :P
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #100 on: March 30, 2013, 10:18:50 am »
@Simon - Here's a nice webpage about the Pierce oscillator and choosing values for the various components. You'll want to use the second schematic from the top that includes the output buffer.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #101 on: March 30, 2013, 11:05:04 am »
I'll use a set of nots then or maybe nands, I'll see what is cheaper and stock up. What is a good series of chips these days, I guess a CD4000 does not actually exist any more.

If you don't need supply voltages above 5V, I think the 74HC04 is about as cheap as they come - but it's been awhile since I bought them.

Also, an interesting Fairchild application note on CMOS oscillators.
« Last Edit: March 30, 2013, 11:14:04 am by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #102 on: April 06, 2013, 09:34:46 am »
Well I tried a single gate clock gen and it works on, I get a clean-ish signal but my output from the whole lots is still bursting all over the place. Oddly I notice that it seems associated with sounds perhaps.

I've now setup with one channel on the clock, and one on the final output, the clock is fine, the output responds to sound levels from my speakers possibly of particular frequencies. At first I thought the crystal was acting as a mic but the clock it is producing is clean.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: counter required to count to near 1 million
« Reply #103 on: April 06, 2013, 10:26:19 am »
I've now setup with one channel on the clock, and one on the final output, the clock is fine, the output responds to sound levels from my speakers possibly of particular frequencies. At first I thought the crystal was acting as a mic but the clock it is producing is clean.

Well, this is not how CMOS gates act normally; they're usually very stable. It seems to me it has to be a power supply problem; unused/untied/incorrectly wired input; or a breadboard specific problem. Use your DSO to check each input and output against the datasheets to make sure they're at the correct levels.

Is your power supply clean? What voltage are you running the circuit at?
« Last Edit: April 06, 2013, 10:31:40 am by marmad »
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14765
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: counter required to count to near 1 million
« Reply #104 on: April 06, 2013, 10:42:48 am »
I've got it running off a 5V regulator, I'm wondering if it's pickup between wires as my breadboard looks like transmission central. I think I'll try veroboarding it and see if it settles down.

I need to get a smidtt gate and hopefully the pulse generator works on it.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf