Generating an Aiken Biphase Signal Problem

Hello, I'm new to the arduino and fairly new to microcontrollers in general. So far I am very impressed with the arduino, but have run into a road block. I am hoping someone can give me a hand.

I have an array full of binary data that I need to properly output in the form of an Aiken Biphase signal (also known as Biphase mark code, or F2F, check out wikipedia).

I've made a for loop to see if an element of an array is a 1 or 0 and sent a digital output pin HIGH or LOW for a delay of .5 or 1 respectively. I'm 100% sure I am doing it wrong. How might I program this? Do I need some external hardware to properly create the signal? I've tried using my sound card and an audio recording program as sort of a scope to try to visualize what I'm doing wrong, but cant make heads of tails of whats up.

Thanks, Colby

Can you post your code up so we can have a look please.

Hey, thanks for the reply. Of course it would make sense to post my code ;). I’ve cut it down to the essentials so hopefully its easy to look over.

Basically it fills an array with 1’s and 0’s for testing and then switches a digital out high and low accordingly for the times defined (the one time should be half of the zero time).

I’m sure I’m just missing something obvious in the one and zero functions, they aren’t making the waveform right. I’ve been feeding it known data and using Audacity and my sound card as sort of a scope to compare it to a properly generated signal from the known data.

Any help would be greatly appreciated. Thanks!

#define ZEROSPEED 1000
#define ONESPEED 500  //ONESPEED should be half of ZEROSPEED in actual size

int outputPin = 26;
int i;
int data[100]; //the data (binary) that is sent out



void setup(){

  pinMode(outputPin, OUTPUT);
  digitalWrite(outputPin,LOW);



//fill data with random numbers or 0's for testing

  randomSeed(analogRead(0));  
  
  for(i=0; i<sizeof(data)/sizeof(int); i++){
   data[i] = random(2);
  }
 
}




void loop(){
 
  for(i=0; i < 100; i++){ //look through the whole array of binary data and act accordingly
    if(data[i]==1){
      one();
    }
    else if(data[i]==0){
      zero();
    }
  }
  
}



void one(){
  
    delayMicroseconds(ONESPEED);
    digitalWrite(outputPin,HIGH);
    delayMicroseconds(ONESPEED);  
    digitalWrite(outputPin,LOW);
    
}



void zero(){

    delayMicroseconds(ZEROSPEED);
    digitalWrite(outputPin,HIGH);
    delayMicroseconds(ZEROSPEED);
    digitalWrite(outputPin,LOW);

}

That doesn't look like biphase, more like a form of PWM. All you're doing is encoding ones as 1mS pulses and zeroes as 2mS pulses. Consecutive zeroes would have opposite polarity, IIRC.

Hey AWOL,

I was thinking the same thing just now. Is it possible to somehow flip the polarity of the output?

I’m building up what is essentially a mag stripe emulator. I have some python code I found that generates an aiken biphase .wav file that can then be used to drive a solenoid and effectively emulate a mag card. I’m hoping to get the arduino to generate the same signal.

I was wondering if the polarity was a problem, but I was comparing the generate wav file to the output from my arduino in Audacity and the waves seem to look very similar and appears in audacity like I am achieving a full wave (reversed polarity and all). ← hope that makes sense.

Anyone have any ideas?