Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Inputting a clock from a 555 timer

$
0
0

This is my first project so I am trying to do something simple. I have this board called a Bread Board Companion. I made in my high school digital electronics class and it includes some switches, LEDs, a 555 timer, and a potentiometer to vary the 555's clock pulse. The board has header pins attaches so you can use all of those items on a breadboard. I wanted the MSP430 to output various numbers to a seven segment display based on binary inputs from the four switches on the BBC. I also wanted one of the switches to be used to switch on a counter using the rising edge of a clock pulse from the 555 timer to count up from 0 to 9. I would be able to use the potentiometer to make it count faster or slower. I was able to get the chip to output different numbers to the seven segment based on three of the switches. However, once I flip the fourth switch the MSP430 does not output the correct numbers. When it is hooked up to the clock, the seven segment alternates between displaying an 8 and a zero. I tried to hook it up to a switch to see if it would do the same thing but it doesn't. When hooked to a switch, when the switch is high, the seven segment displays an 8, but once it goes low it will display a random number between 0 and 9. The first thing I would like to do is get the clock to at least do the same thing the switch is doing, then I can worry about getting it to count correctly. So my question for you guys is does the MSP430 behave differently with clock pulses verses manual inputs. 

 

Below is the code concerning the clock input

I am using Energia

 

// Outputs for SSD
int zero[] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,LOW};
int one[] = {LOW,HIGH,HIGH,LOW,LOW,LOW,LOW};
int two[] = {HIGH,HIGH,LOW,HIGH,HIGH,LOW,HIGH};
int three[] = {HIGH,HIGH,HIGH,HIGH,LOW,LOW,HIGH};
int four[] = {LOW,HIGH,HIGH,LOW,LOW,HIGH,HIGH};
int five[] = {HIGH,LOW,HIGH,HIGH,LOW,HIGH,HIGH};
int six[] = {LOW,LOW,HIGH,HIGH,HIGH,HIGH,HIGH};
int seven[] = {HIGH,HIGH,HIGH,LOW,LOW,LOW,LOW};
int eight[] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};
int nine[] = {HIGH,HIGH,HIGH,HIGH,LOW,HIGH,HIGH};
int ssd[] = {segA,segB,segC,segD,segE,segF,segG};
// Counter variables
int cycleCounter = 0;
int clockState = 0;
int lastClockState = 0;

 

void loop()
{
// Watch the state of the inputs
  clockState = digitalRead(clk);  
  sS1 = digitalRead(s1);
  sS2 = digitalRead(s2);
  sS3 = digitalRead(s3);
  sS4 = digitalRead(s4);

 

if(sS4==HIGH)

  {
    // Cycle States 1xxx
    // compare the clockState to its previous state
    if(clockState != lastClockState)
    {
      // if the state has changed, increment the counter
      if(clockState == HIGH)
      {
        // if the current state is HIGH, then this is a rising edge
        cycleCounter++;
        // Large if statement for counting
        // As count increases SSD increases
        if(cycleCounter==1)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],zero[x]);
          }
        }
        else if(cycleCounter==2)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],one[x]);
          }
        }
        else if(cycleCounter==3)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],two[x]);
          }
        } 
        else if(cycleCounter==4)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],three[x]);
          }
        }
        else if(cycleCounter==5)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],four[x]);
          }
        }
        else if(cycleCounter==6)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],five[x]);
          }
        }
        else if(cycleCounter==7)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],six[x]);
          }
        }
        else if(cycleCounter==8)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],seven[x]);
          }
        }
        else if(cycleCounter==9)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],eight[x]);
          }
        }
        else if(cycleCounter==10)
        {
          for(int x = 0; x < 7; x++)
          {
            digitalWrite(ssd[x],nine[x]);
          }
        }
        else
        {
          cycleCounter = 0;
 // Probably want a cary bit here
        }
      }   
    }            
  }
 
 

Viewing all articles
Browse latest Browse all 2077

Trending Articles