need help building an up/down counter circuit

papops

Joined Mar 21, 2016
5
Hi All,

I'm trying to build an up/down counter circuit using a sequential counter. Ideally, it would count 0 to 10 and stop, then count down to 0 and stop again, then repeat the up count. The intent of the circuit is drive a series of LED's to come on sequentially and stay on to the end of the up count, then turn off sequentially on the down count.

This isn't a homework project but it is a hobby project. any ideas will be greatly appreciated.

Thanks,
Walt

k7elp60

Joined Nov 4, 2008
562
There are a number of up/down counters that will count up to 10 and then count back down to 0. As I recall they all have binary out put, so you would need a decoder circuit if you want 1,2,3,4,5,6,7,8,9,10. Tell is more of the LED's, like is there one to be turned on with each count? How would like to power the unit, and do you want to use a push button switch to activate the counting?

GopherT

Joined Nov 23, 2012
8,012
Hi All,

I'm trying to build an up/down counter circuit using a sequential counter. Ideally, it would count 0 to 10 and stop, then count down to 0 and stop again, then repeat the up count. The intent of the circuit is drive a series of LED's to come on sequentially and stay on to the end of the up count, then turn off sequentially on the down count.

This isn't a homework project but it is a hobby project. any ideas will be greatly appreciated.

Thanks,
Walt
@papops (Walt)

Please tell us how you want the up/down counting to occur. Will the circuit pulse automatically to tick the counts up or will there be some other trigger (external to the circuit discussed so far) or will a single push button cause each press to increment the counter.

Also, once 10 is reached, do you want a numeral 10 to be displayed or a series of dots/LEDs (representing 0 (no dots) and one dot for each to 10). Or what ever else you can describe

When 10 is reached, does any action have to be taken to make the counter reverse? Or just additional ticks of clock, button or external pulse train?

Finally, you have 11 total positions right now, 0, 1 ... 10. Is that correct?

Sorry, it looks like I rambled on and repeated some of @k7elp60 questions.

papops

Joined Mar 21, 2016
5
@papops (Walt)

Please tell us how you want the up/down counting to occur. Will the circuit pulse automatically to tick the counts up or will there be some other trigger (external to the circuit discussed so far) or will a single push button cause each press to increment the counter.

Also, once 10 is reached, do you want a numeral 10 to be displayed or a series of dots/LEDs (representing 0 (no dots) and one dot for each to 10). Or what ever else you can describe

When 10 is reached, does any action have to be taken to make the counter reverse? Or just additional ticks of clock, button or external pulse train? Finally, you have 11 total positions right now, 0, 1 ... 10. Is that correct?

Sorry, it looks like I rambled on and repeated some of @k7elp60 questions.

GopherT and K7elp60,
Thanks for the reply. This circuit needs be autonomous, in other words, turn on the power and it starts running. it will drive 10 LED's. Each LED needs to be turned on in sequence and stay on until the #10 LED has been turned on, then each LED needs to turn off in sequence until they are all off. Then, the sequence starts all over again. The counter chip gets it's clock pulses from a 555 timer. There are numerous up/down counter chips but they all turn on one output at a time. I need to have each of the outputs stay on after being turned on and stay on until it is turned off again in sequence. I'm currently using a CD4017 up/down counter which has 10 outputs BUT they turn off when the next one turns on. I'm trying to come up with some kind of diode matrix to do what I need but I'm not having much luck. I'm using a 4013 flip/flop triggered by the #10 and #0 count outputs to reverse the sense of the up/down count sequence. That part seems to work O.K. but of course, I need a way to keep the LED's on until they are turned off during the down count.

I hope that has made what I'm trying to do a little more clear. Again, thanks for your interest.

Walt

Picbuster

Joined Dec 2, 2013
1,027
Forget the good old 555 timer its to limited. use a PIC12f675 or a bigger one.
All type of counts stop, up down, flash at different output pins is possible and build in no time. programming is simple costs are low and hardware is limited to a few components. Flexibility/applications are limited by our brains.
I willing to give you basic schematic and a simple program to start from.
Let me know.
Picbuster

Dodgydave

Joined Jun 22, 2012
9,956
Sounds like a knight rider display, the cd4017 only counts up,not down,

If its a knight rider display, use a lm3914 and 555 timer ramp generator.

AnalogKid

Joined Aug 1, 2013
9,260
Sounds like a bar graph display. There is a great chip for this, but it takes an analog voltage. Since you have the clock, counter, and up/down reverser all worked out (excellent!), then one approach that sounds complicated but isn't too bad is to whip up a digital to analog converter (D/A) to take your increasing/decreasing binary count and turn it into an analog voltage, and use that to drive a chip that was designed from the ground up to do exactly what you want, the LM3914 linear bar/dot display driver.

The 4017 is a great part, but it never will do what you want and there is no other part that is the same thing plus up/down (unless you want to learn how to program a PIC). There are other circuit tricks to turn a decoded output group into a bar graph, but with 10 steps you would need a 24 V supply and level translating driver transistors and and and. Another approach is to use a left/right shift register to produce the outputs, and have your counter and reverser drive it.

A significant question is whether or not you want an all-off state when the display is reversing at the low end. For example, does the number of LEDs that are on go like this:

3, 2, 1, 2, 3 ...

or

3, 2, 1, none, 1, 2, 3 ...

Big difference.

ak

Bernard

Joined Aug 7, 2008
5,788
555, 4515 4 line binary to 1 of 16, 4516 binary up-dn counter, 4071 OR, & ?
Old preliminary stacker drawing to convert sequential pulses to bar graph style.
The 4516 has output low, so 4514 might be better with output high.
If 74AC32 was used for ORing it has enough drive to light LEDs with 5V or 6V supply.
10 stage decoder, BCD up-dn counter also available.

Last edited:

k7elp60

Joined Nov 4, 2008
562
I agree with Picbuster by using a PIC, But I did some research and if you use the 4017 and and 5ea 4013's connected as D flipflops between the 4017 outputs and your LED's, . Connect the LED's to the Q output, with the set and clear connected to ground. When the output of the 4017 goes high the D flip-flops with change state and the LED will come on. When that same output goes high again the LED will turn off. This will be a one way counter so for example if #1 LED turns on/ it will be the first one to turn off. I have lots of parts, and I will be glad to give part if you need some.

papops

Joined Mar 21, 2016
5
Forget the good old 555 timer its to limited. use a PIC12f675 or a bigger one.
All type of counts stop, up down, flash at different output pins is possible and build in no time. programming is simple costs are low and hardware is limited to a few components. Flexibility/applications are limited by our brains.
I willing to give you basic schematic and a simple program to start from.
Let me know.
Picbuster
I think it's time I started using Pic or Arduino to do some of these projects but it's been a long, long time since I did any kind of programming. I used to know Basic and a few brands of PLC logic programming, but again, that was so long ago it's like starting all over again. But I'm willing to give it a shot. So if you can help point me in the right direction, I'd appreciate it.

AnalogKid

Joined Aug 1, 2013
9,260
Programing a PIC is nothing like the systems you are familiar with. Even PIC Basic is a very real learning curve an experienced Basic programmer. This sounds like an excellent get-your-feet-wet project if that's what you're after, but it will take much longer than wiring up a few chips on perf board.

ak

Picbuster

Joined Dec 2, 2013
1,027
I think it's time I started using Pic or Arduino to do some of these projects but it's been a long, long time since I did any kind of programming. I used to know Basic and a few brands of PLC logic programming, but again, that was so long ago it's like starting all over again. But I'm willing to give it a shot. So if you can help point me in the right direction, I'd appreciate it.
Ok I will compile some stuff for you.
Schematic and simple program will speed it's way to you soon.

Picbuster

Joined Dec 2, 2013
1,027
I think it's time I started using Pic or Arduino to do some of these projects but it's been a long, long time since I did any kind of programming. I used to know Basic and a few brands of PLC logic programming, but again, that was so long ago it's like starting all over again. But I'm willing to give it a shot. So if you can help point me in the right direction, I'd appreciate it.
A simple program. I did avoid all the pointer stuff. next step get the free mplab with xc8 compiler from microchip.
This program will work in most of the 12f and 16F chips (move pic16f690 or higher when more outputs are needed)
picbuster

C:
#include <htc.h>
#include <pic12f675.h>
#include <xc.h>
#define _XTAL_FREQ 4000000  // Needed for delay_ms macro

//#pragma CONFIG(FOSC_INTRCIO & CP_OFF & MCLRE_ON & WDTE_OFF); << depending from your wishes see manual

#define Output GPIO5
#define P3_On  GPIO4
#define Led  GPIO2  // pin5
#define On  1
#define Off  0
//========= end of pic specific
int Wanted_value;
int cnt;
int Flash;
unsigned int result;

//=========================== interrupts ====================
static void interrupt
peripheral_interrupt(void)

/*
//================== when adc under interupt is needed========
//================== set the int  (  ADIE=1;
// ========== ask in main for ana do ==>  ADCON0bits.GO = 1;
// == or  led a timer do it for you
// == doing so will provide you always an value

{
result <<=8;  // shift highbyte left
result |= ADRESL;  // and do low
//-------------------------------------

}
*/

{

//======================== timer =================================
if (TMR0IF)
TMR0IF=0;
cnt++;

Flash++;
if (Flash < 800){Led=Off;}
if (Flash > 1000 + (3000 * !Output))
{
Flash=0;
Led = On;  //Led= on
}

else
{
Led=On;
}
//------------------------------------------------------------------
if (cnt >6000){cnt=0;}
}
//================  end of interrupt ========================

void main()
{
//--------------------  settings -----------------------------------
OPTION_REG = 0b10000000;
ADCON0 =0b10000001; // bit 7 right justfied bit 1 conversion is operating

VRCON = 0x00;
CMCON = 0x07;
TMR0IE=1;
GIE=1;

TRISIO0 = 1;  // set for input
TRISIO1 = 0;  // set for output
TRISIO2 = 0;
TRISIO4 = 0;
TRISIO5 = 0;
// ============================== start
GPIO1=0;
cnt=1;  // wait
while(cnt){}
Output=0; // flash fast

//======================= main loop =====================
while(1)
{

//======  @ 5Vreference and 10bits  1024 = 5/1024 = 0,00488 V/bit input-->>  (204.8) 204 bits approx per volt

result <<=8;  // shift highbyte left
result |= ADRESL;  // and do low

//-----------------------------------------------------------------

if(result >=Wanted_value)  //
{
Output=1; // flash slow  when off it goes faster see  if (Flash > 1000 + (3000 * !Output))
// hence 1000 + 3000 * Output

}

}
}
Moderators note: used code tags for C

Attachments

• 39.9 KB Views: 1

papops

Joined Mar 21, 2016
5
Ok I will compile some stuff for you.
Schematic and simple program will speed it's way to you soon.
Picbuster,
I appreciate the help and as I said before, this is the way I want to go in the future. But as AnalogKid stated, this is going to take a long time to get comfortable with. I'm basically starting from scratch - so let's begin at the beginning - what would you suggest in the way of hardware to begin with - just something to make some lights blink while getting used the "feel" of this kind of programming. I've downloaded the Picaxe users manual and have started reading - this ain't exactly your grandpa's BASIC (the language I cut my teeth on).

BTW - do you think it would be more appropriate for me to be doing this on a Picaxe forum?

Thanks,
Walt

Picbuster

Joined Dec 2, 2013
1,027
If you look at the old basic and you did some programming in it, you have a base to start from.
Most of programming mechanism is similar but the expressions are different.
example:
in basic for a =0 to 100 : do something :next a
in C (int a=0; a<101;a++) { do something}
The dimension in a is not important integer, float or double but in C it is.
What I try to say is C is not really difficult you can avoid the complex things and start simple.

picaxe looks great however it will, as far as I could see, not directly interact with the hardware and the programming language looks like a special. This could put you later into a relearning curve.

Working example given is simple, showing hardware and how the interrupt timer works, producing a flashing light all at low cost pic+lm7805 + 'R's and cap 5 $/euro. The pickit3 (working for most of the pic's models and is about 30$/euro software compiler is free.
Ending up with an investment risk of 40 \$/euro.
I don't know the price of a picaxe starter kit not able to compare.
There is a manual call 'C for dummies'
note: choice C not C++ most of the microprocessor compilers using C apart from some exceptions.
Look also at http://www.cprogramming.com/
Load also the Microchip program examples for the selected chip.
Read all the stuff related to variables, loops, add, subtract, if, for loops and timers. give no attention yet to subroutines, printf, sprint, arrays, pointers or I/O.
Make a simple program set one port High.