View Single Post
Old 06-06-2008, 03:36 AM   #1 (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
Signal Generator

Not sure where this goes, but it is basically two duinos. One (the plain chip and crystal) has been programmed in arduino to simulate a vehicle vss and injector signal, and the other is running the mpguino code. The test code is at the bottom. Now it isn't single digit microsecond accurate, but it also isn't limited by the number of timers either. With this approach you can generate a lot of different signals, i.e. buttons, etc. And since both the guino and the signal generator are connected to the computer simultaneously it is quite possible to have a PC program with all kinds of scenarios that tell the signal generator what to generate and get the result from the gunio to see if it is correct.





PHP Code:
//GPL Software 
//cheesey signal generator, made for bench testing the mpguino
//signal generator pins
#define sig1Pin 2   //inj
#define sig2Pin 3   

//overflow counter used by millis()   
extern volatile unsigned long timer0_overflow_count;   
unsigned long lastMicroSeconds=millis() * 1000;
unsigned long microSeconds (void){  
  
unsigned long tmp_timer0_overflow_count
  
unsigned long tmp
  
byte tmp_tcnt0
  
cli(); //disable interrupts 
  
tmp_timer0_overflow_count timer0_overflow_count
  
tmp_tcnt0 TCNT0
  
sei(); // enable interrupts 
  
tmp = ((tmp_timer0_overflow_count << 8) + tmp_tcnt0) * 4;  
  if((
tmp<=lastMicroSeconds) && (tmp<4293967296)) 
    return 
microSeconds();  
  
lastMicroSeconds=tmp;
  return 
tmp;  



unsigned long elapsedMicroseconds(unsigned long startMicroSecondsunsigned long msec ){   
  if(
msec >= startMicroSeconds)   
    return 
msec-startMicroSeconds;   
  return 
4294967295 - (startMicroSeconds-msec);   
}   


/*
metro signal generator notes:
//#define vssPulsesPerMile 10000ul   
//#define microSecondsPerGallon 267857143ul //injector flow rate   
@20mph, 4th gear
~48mpg
~44000uS injector open time per 1/2 second
18 inj pulses per 1/2 second
55 vss pulses per 1/2 second
therefore: 
sig1, off for 2444uS, on for 25333uS
sig2, on for 16000uS, off for 2180uS
*/
unsigned long sig1Start//injector
byte sig1State HIGH//injector 1=closed
unsigned long sig2Start//vss
byte sig2State LOW//vss

#define sig1PinOffTime 2444
#define sig1PinOnTime 25333
#define sig2PinOnTime 16000
#define sig2PinOffTime 2180


void setup (void){    
  
pinMode(sig1Pin,OUTPUT);   
  
pinMode(sig2Pin,OUTPUT);   
}    

void loop (void){    

  
digitalWrite(sig1Pin,sig1State);
  
digitalWrite(sig2Pin,sig2State);
  
sig1Start microSeconds();
  
sig2Start sig1Start;
  while(
true){ 
    
//snapshot of the time variables:
    
unsigned long tmp microSeconds();  
    
unsigned long tmp1 elapsedMicroseconds(sig1Starttmp);  
    
unsigned long tmp2 elapsedMicroseconds(sig2Starttmp);  

    
//sig 1 timing logic
    
if(sig1State==HIGH){
      if (
tmp1>=sig1PinOnTime){
        
sig1Start=tmp;
        
sig1State=LOW;
        
digitalWrite(sig1Pin,sig1State);
      }
    }else{
      if (
tmp1>=sig1PinOffTime){
        
sig1Start=tmp;
        
sig1State=HIGH;
        
digitalWrite(sig1Pin,sig1State);
      }
    }  

    
//sig 2 timing logic
    
if(sig2State==HIGH){
      if (
tmp2>=sig2PinOnTime){
        
sig2Start=tmp;
        
sig2State=LOW;
        
digitalWrite(sig2Pin,sig2State);
      }
    }else{
      if (
tmp2>=sig2PinOffTime){
        
sig2Start=tmp;
        
sig2State=HIGH;
        
digitalWrite(sig2Pin,sig2State);
      }
    }  

    

     
//sig3?  sigX? 

  
}   


__________________
WINDMILLS DO NOT WORK THAT WAY!!!

Last edited by dcb; 06-07-2008 at 12:07 PM..
  Reply With Quote