View Single Post
Old 01-30-2011, 11:36 PM   #28 (permalink)
dcb
needs more cowbell
 
dcb's Avatar
 
Join Date: Feb 2008
Location: ÿ
Posts: 5,038

pimp mobile - '81 suzuki gs 250 t
90 day: 96.29 mpg (US)

schnitzel - '01 Volkswagen Golf TDI
90 day: 53.56 mpg (US)
Thanks: 158
Thanked 269 Times in 212 Posts
mkay, made some progress at 160 baud. The code isn't quite ready for 1892 however (never synchs up). Might need to get more specific with the baud rates (or possibly the outbound uart code is piggy or the new arduino timer code is and has to be neutered again).

here is an arduino script that uses an aldl signal tied to pin2 and pin3 and converts it to a byte stream @57600 baud. two bytes per aldl character to preserve the synch character
PHP Code:
//aldl to serial adapter
//converts 9 bit aldl stream to integers over serial port.
extern volatile unsigned long timer0_overflow_count;

volatile byte lastbit=255//positive is a one, negative is a zero, 0 is already processed
volatile long falllength 0;
volatile long riselength 0;

void falling(){ 
  
riselengthtimer0_overflow_count;
  
timer0_overflow_count=0;
  
lastbitfalllength>riselength?1:0;
}

void rising(){
  
falllength timer0_overflow_count;
  
timer0_overflow_count=0;
}

void setup(){                    // run once, when the sketch starts
  
attachInterrupt(0falling,FALLING );
  
attachInterrupt(1rising,RISING );
  
Serial.begin(57600);
}


byte synched 0;
int onecount=0;
int bf=0;
byte bp=8;

void loop(){
  
byte lb=255;
  while (
lb == 255){
//    cli();
    
lb=lastbit;
//    sei();
  
}
//  cli();
  
lastbit=255;
//  sei();
  
  
if(synched==0){
    if(
lb==0){
      if(
onecount>=9){
        
synched=1;
        
Serial.print((char)1);//repeat the synch sequence for the client
        
Serial.print((char)255);
      }else
        
onecount=0;
    }else
      
onecount++;
  }
  
  if(
synched==1){//ok, we are synched
    
bf=bf|lb << bp;
    
bp--;
    if(
bp ==255){//we have 9 bits worth, send it over the port
       
Serial.print((char)(bf>255?1:0));
       
Serial.print((char)(bf));
       
bf=0;
       
bp=8;
    }   

  }

Here is the arduino test script (I run it on a second arduino and run its pin 13 to the aldluino's pins 2 and 3), ground pin 12 and reset to simulate 8192-ish baud
PHP Code:
//test script for aldluino
#define sigpin 13
#define baudpin 12

/*   from http://www.techedge.com.au/vehicle/aldl160/aldl160b.htm
 T0-T1 = B = 0.5 mSec.
 T1-T3 = C = 4.75 mSec.
 T3-T4 = E = 1.0 mSec.
 T0-T4 = total = 6.25 mSec 
*/
int low0=500;
int high0=5750;
int low1=5250;
int high1=1000;


void setup(){ 
  
pinMode(baudpin,INPUT);
  
digitalWrite(baudpin,HIGH);
  if(
digitalRead(baudpin)==LOW){//set up 8192
    
low0=10;
    
high0=112;
    
low1=103;
    
high1=19;
  }
  
pinMode(13,OUTPUT);
  
cli();
}


void sendch(int ch){//send out the msb 9 'bits'
    
for(int p=8;p>=0;p--){
      
int b=ch&1<<p;
      
digitalWrite(sigpin,LOW);
      
long d b==0?low0:low1;
      
delayMicroseconds(d);
      
digitalWrite(sigpin,HIGH);
      
b==0?high0:high1;
      
delayMicroseconds(d);
    }  
}




void loop(){
//cycle through sending 511 (synch), then an ascending odd number followed by a descending even
  
sendch(511);
  for(
int x 1;<=255x+=2){
    
sendch(x);
    
sendch(255-x);
  }


Here is a bit of java to read the serial data and print it in hex format
PHP Code:
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
public class 
Serial {
    static 
InputStream input;
    static 
OutputStream output;
    public static 
void main(String[] argsthrows Exception {
        
CommPortIdentifier portId CommPortIdentifier
            
.getPortIdentifier("COM6");
        
SerialPort port = (SerialPortportId.open("serial madness"4000);
        
input port.getInputStream();
        
output port.getOutputStream();
        
port.setSerialPortParams(57600,
                
SerialPort.DATABITS_8SerialPort.STOPBITS_1,
                
SerialPort.PARITY_NONE);
        
int i=0;
        while (
true) {
            
i=input.read();
            while(
== -1)
                
i=input.read();
            
System.out.print(Integer.toHexString(i));
            
i=input.read();
            while(
== -1)
                
i=input.read();
            
System.out.println(Integer.toHexString(i));
        }

    }


Here is a little bit of output from the java program, you can see the synch character 1ff here generated from the test arduino through the aldluino
Code:
0f9
06
0fb
04
0fd
02
0ff
00
1ff
01
0fe
03
0fc
05
0fa
07
0f8

Test circuit is trying to simulate this
http://ecomodder.com/forum/showthrea...tml#post196642
__________________
WINDMILLS DO NOT WORK THAT WAY!!!

Last edited by dcb; 01-30-2011 at 11:50 PM..
  Reply With Quote