problems interfacing shiftout with arduino code

Hi all

I have been having issues shifting out my values of binary to the attenuator, [.following the information provided I cannot successfully attenuate the the required levels from the digital i/o pins.

Any thoughts on this?

my code

const int clockPin = 11;
const int prescale  = 1;
const int ocr2aval  = 3;
// Period in microseconds
const float period    = 5.0 * prescale * (ocr2aval + 1) / (F_CPU / 1.0e6);

// Frequency in Hz
const float freq      = 1.0e6 / period;
const int dataPin = 4;
const int latchPin = 2;

byte patterns [8] {
  B00111111 , B00000000 , B00111111 , B00000000 , B00111111 , B00000000
};
int index = 0;
int count = sizeof(patterns);


void setup() {
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);

  TCCR2A = ((1 << WGM21) | (1 << COM2A0));

  TCCR2B = (1 << CS20);

  TIMSK2 = 0;

  OCR2A = ocr2aval;

  Serial.print("Period    = ");
  Serial.print(period);
  Serial.println(" microseconds");
  Serial.print("Frequency = ");
  Serial.print(freq);
  Serial.println(" Hz");

  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

}

void loop() {

  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, patterns[index]);
  digitalWrite(latchPin, HIGH);
  digitalWrite(latchPin, LOW);
  delay(10000);
}

Where I use a prescaler to reduce the clock to a desired rate, and using the shift function to flip flop the attenuation levels

](http://www.minicircuits.com/pdfs/ZX76-31R5-SP+.pdf)

Why do you keep sending the same value every 10 seconds? What change do you expect to see as a result of doing that?

How is that thing connected to the Arduino?

I have been having issues shifting out my values of binary to the attenuator, .

and the issues are what ?

You have an array of values but only ever output the first one. Is that intentional or did you mean to increment the index variable in some way ?

PaulS:
Why do you keep sending the same value every 10 seconds? What change do you expect to see as a result of doing that?

How is that thing connected to the Arduino?

The arduino connects to it via the three pins clock latch and data, and I am using the shift out function to send alternating bytes of 00000000 and 00111111 to the shift register every 10 seconds in the hopes of seeing the attenuation changes occur, currently that is not working

UKHeliBob:
and the issues are what ?

You have an array of values but only ever output the first one. Is that intentional or did you mean to increment the index variable in some way ?

The program for some reason is not shifting the values into the 6 bit shift register, and therefore is not attenuating the signal, I though by sending on byte with 8 bits the first 2 bits would drop off and allow the attenuation to occur, I am trying to output the 00000000 00111111 bytes in an alternating fashion but for some reason I can't get it to work

Any thoughts?

and I am using the shift out function to send alternating bytes of 00000000 and 00111111 to the shift register every 10 seconds in the hopes of seeing the attenuation changes occur, currently that is not working

No, you are not. You are sending ONE value, every 10 seconds. That value is ALWAYS B00111111.

I am using the shift out function to send alternating bytes of 00000000 and 00111111 to the shift register every 10 seconds

Look carefully at your code. How does it change the value sent from 00000000 to 00111111 ?

UKHeliBob:
Look carefully at your code. How does it change the value sent from 00000000 to 00111111 ?

ok thanks for that info could you give me an idea of what to put in the sketch to make it shift out the second byte after the first?

Clumsy, but good enough for a quick and dirty test

void loop()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, patterns[0]);
  digitalWrite(latchPin, HIGH);
  delay(10000);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, patterns[1]);
  digitalWrite(latchPin, HIGH);
  delay(10000);
}
void loop() {
for (byte index = 0; index <2; index = index +1){
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, patterns[index]);
  digitalWrite(latchPin, HIGH);
  delay(10000);
  }

}

Or a for loop.