Go Down

Topic: 5 bit binary counter (Read 6068 times) previous topic - next topic

sblachh1985

Hello Everyone!

I am trying to control a 32 to 1 multiplexer with 5 address lines (A0-A4).  I want to create a 5-bit binary counter that outputs the bits to the pins of the arduino. 

This is just a small part of a larger test set up which has four 32to1 mux's with their outputs to the switches on a 4 to 1 mux.  In other words I am designing a 128 to 1 multiplexer using four 32to 1's and one 4 to 1. I am trying to control all of them with the Arduino UNO.  The EN (enables) are hooked up to the A0 - A5 pins on my Arduino Uno.  If the EN is set low none of the switches will work.  The idea is to enable one 32 to 1 at a time, and switch to all 32 switches.  Then enable the second etc etc....

But for now a 5-bit binary counter will be sufficient.

Any suggestions are welcome as I am new to the Arduino programming environment.

Thank you!!!

CrossRoads

go to ti.com and look for cmos counter.
chip like 74HC4040 will do, is 14 bits.
you can find smaller ones, like 8 bit.
or use a 4 bit and add another flip-flop for bit 5.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

graynomad

#2
Mar 04, 2011, 02:53 am Last Edit: Mar 04, 2011, 02:55 am by Graynomad Reason: 1
Five-bit counter with auto wrap around to 0

Code: [Select]
counter++ & B00011111;

If your output pins are on the same port and in a row then something like this

Code: [Select]

PORTB &= B11100000;
PORTB != counter;


If they are on pins all over the place then extract the bits and use a series of digitalWrites() to set the pins.

______
Rob

Rob Gray aka the GRAYnomad www.robgray.com

John_Smith



I have the same requirements, and solved it as below, with 6 working lines.  The countPins output a normal binary sequence up to whatever is set by "switchbank"


Code: [Select]

int counter ;
int count0 ;
int count1 ;
int count2 ;
int count3 ;
int count4 ;

int countPin0 = 7;
int countPin1 = 8;
int countPin2 = 9;
int countPin3 = 13;
int countPin4 = 14;
  int switchbanks = 32;

void setup()
{   
  pinMode(countPin0, OUTPUT );
  pinMode(countPin1, OUTPUT );
  pinMode(countPin2, OUTPUT );
  pinMode(countPin3, OUTPUT );
  pinMode(countPin4, OUTPUT );
  counter = 0;
  Serial.begin(9600);
 
 
}
void loop ()
{
   for ( counter = 0; counter <= switchbanks ; counter ++ )  {
   if ( counter % 2 ) { count0 = HIGH; } else { count0 = LOW;   }
   if ( (counter / 2 )  % 2 ) { count1 = HIGH; } else { count1 = LOW;}
   if ( ( counter / 4 ) % 2 ) { count2 = HIGH; } else { count2 = LOW;}
   if ( (counter / 8 ) % 2 ) { count3 = HIGH; } else { count3 = LOW;}
   if ( (counter / 16 ) % 2 ) { count4 = HIGH; } else { count4 = LOW;}


   Serial.print ( "counter = "   );
  Serial.println ( counter );

    Serial.print ( "count0 = "   );
  Serial.println ( count0 );
 
  Serial.print ( "count1 = "   );
  Serial.println ( count1 );
 
  Serial.print ( "count2 = "   );
  Serial.println ( count2 );
 
    Serial.print ( "count3 = "   );
  Serial.println ( count3 );
 
    Serial.print ( "count4 = "   );
  Serial.println ( count4 );
 
  }
 
  delay ( 1000 );
}


 
45 years of editing projects with a knife and soldering iron, then I found Arduino !

Go Up