Go Down

Topic: Shiftout 16bits data help.. (Read 4527 times) previous topic - next topic

nickgammon

Can you post your current code? The previous one didn't compile, right?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

doaway


Can you post your current code? The previous one didn't compile, right?

Hi Nick, I want to shift 16 bits data to a 16 bit series in-parallel out shift register.
Here is my code, I connect pin12 to oscillator, pin11 to multimeter,   I did not see a waveform  on the oscillator and 0 voltage on multimeter.

Maybe my code does not work.

Code: [Select]


  int PGb = 8;  //latchPinB
  int Clk = 12;
  int Din = 11;
  int Dout = 10;
  int Vpg = 9;
// byte Data0 = B00000000;  // 16 bits data
//  byte Data1 = B11111111;
  int Data = 500;

void setup(){
  pinMode(PGb, OUTPUT);
  pinMode(Clk, OUTPUT);
  pinMode(Din, OUTPUT);
  pinMode(Vpg, OUTPUT);
  pinMode(Dout, INPUT);
  shift();
}

void shift(){
  digitalWrite(PGb, HIGH);
  digitalWrite(Vpg, LOW);
  shiftOut(Din, Clk, LSBFIRST, Data);
  shiftOut(Din, Clk, LSBFIRST, (Data>>8));
  digitalWrite(PGb, LOW);
  digitalWrite(Vpg, HIGH);
  delay(1000);
  digitalWrite(PGb, HIGH);
  digitalWrite(Vpg, LOW);
}

void loop(){

}

nickgammon

I ran your code and got results. I moved the call to shift() to be inside loop rather than setup, so it would output repeatedly.


Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

doaway

Have no idea how long will the CLK will lasting. I want the CLK run forever and only shift 16 bits data once.

doaway


I ran your code and got results. I moved the call to shift() to be inside loop rather than setup, so it would output repeatedly.





Thanks, what software do you use to show the output ?

nickgammon

Hardware and software:

http://www.saleae.com/logic/
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Grumpy_Mike


Have no idea how long will the CLK will lasting. I want the CLK run forever and only shift 16 bits data once.

Then you can't use shift out in that case, or infact any serial shift protocol. What you want is not normal and I suspect it is not what you want to happen as the clock will continuously shift out data.

doaway



Have no idea how long will the CLK will lasting. I want the CLK run forever and only shift 16 bits data once.

Then you can't use shift out in that case, or infact any serial shift protocol. What you want is not normal and I suspect it is not what you want to happen as the clock will continuously shift out data.


yep, I do not want continuously shift out data, but I need clk to do another thing after shifting(read outputs of the shift register.)

Grumpy_Mike

#23
Jul 26, 2013, 08:50 pm Last Edit: Jul 26, 2013, 08:51 pm by Grumpy_Mike Reason: 1
Quote
yep, I do not want continuously shift out data,

But that is what happens if you keep the clock going, like it or not.
The only way you can have a continuous clock is with the PWM lines, but you can't use that to shift out data because you can't syncronise to it, well not very easly.

The only way to do this is have the PWM timer generate an interrupt and have the ISR output your data for 16 cycles, then set a flag that prevents any more data being output, or that disables the interrupt flag after the shift out.

However like it or not you will still be shifting out the data level of the last logic level you sent.

Go Up