Go Down

Topic: help please with 299 shift register (Read 733 times) previous topic - next topic

matelot

Would someone with experience of shift registers and particularly the 74ls299 please take a look at my sketch and let me know what I am missing?
the first code is a sketch for the hct4021 and it works fine.
Code: [Select]

/* set up CD4021 with
pin1 - i/p 1      pin16 - vcc
pin2 - n/c        pin15 - i/p 2     
pin3 - data in    pin14 - i/p 3
pin4 - i/p 5      pin13 - i/p 4
pin5 - i/p 6      pin12 - n/c
pin6 - i/p 7      pin11 - n/c
pin7 - i/p 8      pin10 - clock
pin8 - 0v         pin9  - ser/par switch (latch)
bias inputs with resistors to ov and put a switch on each input to vcc
*/


const int latchPinin  =  5; //4021 pin 9
const int dataPinin   =  6;  //4021 pin 3
const int clockPinin  =  7; //4021 pin 10
int myinput;
int a;

void setup() {
  Serial.begin(9600);
  pinMode(latchPinin,  OUTPUT);
  pinMode(clockPinin,  OUTPUT);
  pinMode(dataPinin,    INPUT);
}

void loop() { 
   delayMicroseconds  (20);
   digitalWrite       (clockPinin,HIGH);/*puts the clockpin high so the first
                                bit is read before the register is clocked on*/
   digitalWrite       (latchPinin,HIGH);//set it to 1 to collect parallel data
   delayMicroseconds  (20);             //pause to let digitalWrite finish
   digitalWrite       (latchPinin,LOW); //set it to 0 to transmit data serially
   delayMicroseconds  (20);             //pause to let latch go low
   myinput = shiftIn (dataPinin, clockPinin, MSBFIRST);//read register
   delayMicroseconds  (20);             //pause to let shiftin read register
   for (a=0;a<8;a++)                 /*bit read the contents of myinput so that
                                       it maintains leading '0's for the screen*/
   {
     Serial.print    (bitRead (myinput,(7-a)));
   }
   Serial.print  ("   ");               //space the outputs on the screen
   Serial.print (myinput);              //print myinput in decimal
   Serial.println();                    //add a line feed
   delay (1000);                        //delay to read output on screen
}

I am trying to understand how a 74ls299 works and trying to get it to do something similar.
I have done the same thing with a 74ls595 and converted it to work with the 74ls299, my ultimate goal is to integrate both programs and use the 74ls299 to send and receive 4 inputs and 4 outputs at the same time.

If I use the sketch below into the arduino, with I/O 7 high (switch on) I get all 1's with it low I get all 0's. I think it is not clocking through the  bits and I am just getting what is on the first gate, I think all the connection information is contained in the sketch.
Code: [Select]

/* set up 74ls299 with
pin1 - S0         pin20 - vcc
pin2 - OE1        pin19 - S1     
pin3 - OE2        pin18 - DS 7   
pin4 - I/O 6      pin17 - Q 7   
pin5 - I/O 4      pin16 - I/O 7   
pin6 - I/O 2      pin15 - I/O 5       
pin7 - I/O 0      pin14 - I/O 3     
pin8 - Q 0        pin13 - I/O 1         
pin9  - MR        pin12 - CP
pin10 - 0V        pin11 - DS0
put PINS 5, 15, 4, 16 to 0v bias (with resistors to 0v) side of switches connected to 5v.
MR is held high as are S0 and S1*/

const int latchPinin  =  9;  //299 pins 2 & 3 (OE1 & OE2)
const int dataPinin   =  6;  //299 pin 17 (Q7)
const int clockPinin  =  10; //299 pin 12 (CP)
int myinput;
int a;


void setup(){
  Serial.begin(9600);
  pinMode(latchPinin,  OUTPUT);
  pinMode(clockPinin,  OUTPUT);
  pinMode(dataPinin,    INPUT);
 
}
void loop() {

//  digitalWrite       (clockPinin,HIGH);/*puts the clockpin high so the first
//                               bit is read before the register is clocked on*/
   digitalWrite       (latchPinin,HIGH);//set it to 1 to collect parallel data
   delayMicroseconds  (20);             //pause to let digitalWrite finish
   digitalWrite       (latchPinin,LOW); //set it to 0 to transmit data serially
   delayMicroseconds  (20);             //pause to let latch go low
   myinput = shiftIn (dataPinin, clockPinin, LSBFIRST);//read register
   delayMicroseconds  (20);             //pause to let shiftin read register
   for (a=0;a<8;a++)                 /*bit read the contents of myinput so that
                                       it maintains leading '0's for the screen*/
   { 
     Serial.print    (bitRead (myinput,(7-a)));
   }
   Serial.print  ("   ");               //space the outputs on the screen
   Serial.print (myinput);              //print myinput in decimal
   Serial.println();                    //add a line feed
   delay (1000);                        //delay to read output on screen
 
 
 
}

I have tried many changes of connection but I am now stumped. I would appreciate someones help.
Thanks.

TomGeorge

Hi, can you post a pic of your project or a CAD or pic of a hand drawn copy of your circuit.

Hope to help.
Tom...... :)

Good to see you have had  try before jumping on the forum...
Everything runs on smoke, let the smoke out, it stops running......VK3DMK

matelot

#2
Jan 29, 2014, 08:24 pm Last Edit: Jan 29, 2014, 08:31 pm by matelot Reason: 1
Hi Tom,
The intention is to use the circuit in two programs. At the model railway society I go to we have a garden railway, the indication board in the signal box is well out of date, it has two plugs on the back, a 50 pin and a 37 pin, not all the pins are used but it still has a lot of wires.
I want to replace it with an up-to-date board, the layout is now about twice what it was when the present board was made so I am going to have lotssss of wires. There is also the facility of passing a magnet over the circuit on the layout and moving points or signals so the board has to be able to send as well as receive signals. I could do it with lots of 4021's and 595's but I wanted to try to do it with 299's.
The other project is to drive four signals around the track, these are four aspect signals and a sensor near each one, again I could use 4021's and 595's but it could be done with just one 299 in each signal head and an atmega chip in the controller.
I have added two pictures, one of the breadboard I am using and a drawing of the parallel to serial side of the circuit.
This only shows how to drive the p to s side for now and most of the n/a's are for the s to p side, i/o pins 0 to 3 for s to p and 4 to 7 for p to s.
I hope you can see what I am missing on my wiring or software. I am still trying various configurations and alterations to the software but without luck.
I have just noticed the breadboard shows pin 8 on the arduino going to pin 11 (DS 0) on the chip, this wire is doing nothing and was one I have been trying since I started this thread.

Go Up