Show Posts
Pages: 1 2 3 [4] 5
46  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 07, 2013, 06:42:11 am
would an "else" statement be more effecient or is two "if" statements ok?
47  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 07, 2013, 06:31:49 am
oops sorry missed that out too. You can tell I'm a newbee smiley-roll
Code:
/*
Read square wave speed signal in on pin2 and output squarewave speed on pin4
 */

volatile uint32_t lastPulseTime = 0;
volatile uint32_t lastPulseWidth = 0;


const int speed_in = 2; //sqaure wave input from speed source
const int gear_in = 3;     //gear select input
const int speed_out = 4; //sqaure wave output

// variables for calculation
const float ratio1 = 1/ 2.315;
const float ratio2 = 1/ 1.731;
const float FD = 1 / 4.7;
const float idler = 1.04;
const float pulses = 4; //pulses per simultated revolution
float square_in; //speed received
float square_out; //speed to send

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.

  pinMode(speed_in, INPUT);
  pinMode(speed_out, OUTPUT);
  pinMode(gear_in, INPUT);

attachInterrupt(0, registerPulse, RISING);
}

// the loop routine runs over and over again forever:
void loop() {
  //Sample data to test
  square_in = 1000000UL / lastPulseWidth;


/*
 read the square wave speed input from "speed_in" into variable "sqaure_in"
*/



  if (gear_in == HIGH) {        //ratio1 is selected
    square_out = square_in / 2 * ratio1 / idler * FD * pulses;
  }//end of ratio1


if (gear_in == LOW) {        //ratio1 is selected
  square_out = square_in / 2 * ratio2 / idler * FD * pulses;
  }//end of ratio2


/*
  //output the variable "sqaure_out" as square wave to "Speed_out"
*/
}
void registerPulse() {
  uint32_t cur = micros();
  lastPulseWidth = cur - lastPulseTime;
  lastPulseTime = cur;
}
48  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 07, 2013, 05:11:25 am
oops sorry smiley-roll forgot about that (again!)

Code:
/*
Read square wave speed signal in on pin2 and output squarewave speed on pin4
 */

volatile uint32_t lastPulseTime = 0;
volatile uint32_t lastPulseWidth = 0;


const int speed_in = 2; //sqaure wave input from speed source
const int gear_in = 3;     //gear select input
const int speed_out = 4; //sqaure wave output

// variables for calculation
const float ratio1 = 1/ 2.315;
const float ratio2 = 1/ 1.731;
const float FD = 1 / 4.7;
const float idler = 1.04;
const float pulses = 4; //pulses per simultated revolution
float square_in; //speed received
float square_out; //speed to send

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.

  pinMode(speed_in, INPUT);
  pinMode(speed_out, OUTPUT);
  pinMode(gear_in, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  //Sample data to test
  square_in = 1000000UL / lastPulseWidth;


/*
 read the square wave speed input from "speed_in" into variable "sqaure_in"
*/



  if (gear_in == HIGH) {        //ratio1 is selected
    square_out = square_in / 2 * ratio1 / idler * FD * pulses;
  }//end of ratio1


if (gear_in == LOW) {        //ratio1 is selected
  square_out = square_in / 2 * ratio2 / idler * FD * pulses;
  }//end of ratio2


/*
  //output the variable "sqaure_out" as square wave to "Speed_out"
*/
}
void registerPulse() {
  uint32_t cur = micros();
  lastPulseWidth = cur - lastPulseTime;
  lastPulseTime = cur;
}
49  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 07, 2013, 05:05:36 am
Thanks for your input,

I'd like to  update the output sqaurewave as quick as possible, accuracy wise, an error margin of around 5% would be acceptable.

I've merged your code into mine, have I understood your code correctly?

Code:
/*
Read square wave speed signal in on pin2 and output squarewave speed on pin4
 */

volatile uint32_t lastPulseTime = 0;
volatile uint32_t lastPulseWidth = 0;


const int speed_in = 2; //sqaure wave input from speed source
const int gear_in = 3;     //gear select input
const int speed_out = 4; //sqaure wave output

// variables for calculation
const float ratio1 = 1/ 2.315;
const float ratio2 = 1/ 1.731;
const float FD = 1 / 4.7;
const float idler = 1.04;
const float pulses = 4; //pulses per simultated revolution
float square_in; //speed received
float square_out; //speed to send

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.

  pinMode(speed_in, INPUT);
  pinMode(speed_out, OUTPUT);
  pinMode(gear_in, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  //Sample data to test
  square_in = 1000000UL / lastPulseWidth;


/*
 read the square wave speed input from "speed_in" into variable "sqaure_in"
*/



  if (gear_in == HIGH) {        //ratio1 is selected
    square_out = square_in / 2 * ratio1 / idler * FD * pulses;
  }//end of ratio1

  square_out = square_in / 2 * ratio2 / idler * FD * pulses;



/*
  //output the variable "sqaure_out" as square wave to "Speed_out"
*/
}
void registerPulse() {
  uint32_t cur = micros();
  lastPulseWidth = cur - lastPulseTime;
  lastPulseTime = cur;
}
50  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 06, 2013, 11:49:15 am
Square_ and square out is going to be a frequency, but thats the problem I have, I don't know how to input and output this?
51  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 06, 2013, 09:26:34 am
yes I was missing the digitalRead, sorry I'm very new to C

Thanks for the info on the code tags.

Code:
/*
Read square wave speed signal in on pin2 and output squarewave speed on pin4
 */


const int speed_in = 2; //sqaure wave input from speed source
const int gear_in = 3;     //gear select input
const int speed_out = 4; //sqaure wave output

// variables for calculation
const float ratio1 = 1/ 2.315;
const float ratio2 = 1/ 1.731;
const float FD = 1 / 4.7;
const float idler = 1.04;
const float pulses = 4; //pulses per simultated revolution
float square_in; //speed received
float square_out; //speed to send

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.

  pinMode(speed_in, INPUT);
  pinMode(speed_out, OUTPUT);
  pinMode(gear_in, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  //Sample data to test
  square_in = 23890;


/*
 read the square wave speed input from "speed_in" into variable "sqaure_in"
*/



  if (digitalRead(gear_in) == HIGH) {        //ratio1 is selected
    square_out = square_in / 2 * ratio1 / idler * FD * pulses;
  }//end of ratio1


  if (digitalRead(gear_in) == LOW) {        //ratio2 is selected
  square_out = square_in / 2 * ratio2 / idler * FD * pulses;
 }//end of ratio2


/*
  //output the variable "sqaure_out" as square wave to "Speed_out"
*/
}

52  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 06, 2013, 09:18:00 am
Thanks for your input, I now see my mistake with the if loop, I've now updated this.
To give you a bit more background information. I am trying to simualte axle speed on a gearbox, and my sqaurewave signal is an igntion pulse from a engine ECU. The output will be connected to a 3rd party data logger for testing.

I made an error when I estitmated the speed of the sqaure wave, it's actually a max of 100 pulses per second, but I would need the output speed to update quicker than every 50ms

Here is my updated code:
Code:
/*
Read square wave speed signal in on pin2 and output squarewave speed on pin4
 */


const int speed_in = 2; //sqaure wave input from speed source
const int gear_in = 3;     //gear select input
const int speed_out = 4; //sqaure wave output

// variables for calculation
const float ratio1 = 1/ 2.315;
const float ratio2 = 1/ 1.731;
const float FD = 1 / 4.7;
const float idler = 1.04;
const float pulses = 4; //pulses per simultated revolution
float square_in; //speed received
float square_out; //speed to send

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.

  pinMode(speed_in, INPUT);
  pinMode(speed_out, OUTPUT);
  pinMode(gear_in, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  //Sample data to test
  square_in = 23890;


/*
 read the square wave speed input from "speed_in" into variable "sqaure_in"
*/



  if (gear_in == HIGH) {        //ratio1 is selected
    square_out = square_in / 2 * ratio1 / idler * FD * pulses;
  }//end of ratio1


  if (gear_in == LOW) {        //ratio2 is selected
  square_out = square_in / 2 * ratio2 / idler * FD * pulses;
 }//end of ratio2


/*
  //output the variable "sqaure_out" as square wave to "Speed_out"
*/
}
53  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 06, 2013, 07:19:48 am
Sorry I was getting confused, the input and outputs are not PWM and are sqaure wave.

This is the code which I have come up with so far, the maths should be correct, and give you an idea of what I'm trying todo. What I'm unsure about is how to read in a sqaure wave and save the pulses as a variable, aslo read a variable and output as sqaure wave??

here is my code so far:
Code:
/*
Read square wave speed signal in on pin2 and output squarewave speed on pin4
 */


const int speed_in = 2; //sqaure wave input from speed source
const int gear_in = 3;     //gear select input
const int speed_out = 4; //sqaure wave output

// variables for calculation
const float ratio1 = 1/ 2.315;
const float ratio2 = 1/ 1.731;
const float FD = 1 / 4.7;
const float idler = 1.04;
const float pulses = 4; //pulses per simultated revolution
float square_in; //speed received
float square_out; //speed to send

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.

  pinMode(speed_in, INPUT);
  pinMode(speed_out, OUTPUT);
  pinMode(gear_in, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  //Sample data to test
  square_in = 23890;


/*
 read the square wave speed input from "speed_in" into variable "sqaure_in"
*/



  if (gear_in == HIGH) {        //ratio1 is selected
    square_out = square_in / 2 * ratio1 / idler * FD * pulses;
  }//end of ratio1

  square_out = square_in / 2 * ratio2 / idler * FD * pulses;



/*
  //output the variable "sqaure_out" as square wave to "Speed_out"
*/
}
54  Using Arduino / Project Guidance / Re: Devide 12v square wave signal and output 5v squarewave on: February 05, 2013, 11:14:01 am
Thats great news,

So would I read the input as PWM?

Has anyone got an code where they input and output this kind of data?

Thanks

Jimster
55  Using Arduino / Project Guidance / Devide 12v square wave signal and output 5v squarewave on: February 05, 2013, 07:24:36 am
I have a square wave signal with a range of 2400 - 300000 pules per second coming from a 12v source. I would like to read this signal do some maths (depending on a analogue input) and then output the signal to a 5v square wave.  The speed of the output would be in the range of 1000 - 80000 pulses per second. Is this possible with an arduino?

Is the ardunio quick enough todo this, has anything like this been done before? I've had a search but could not find anything. Any advice would be magic.

Thanks
56  Using Arduino / Project Guidance / Re: Wireless project 4 transmitters, one arduino as receiver on: February 01, 2013, 11:06:07 am
I've received my nRF24L01 boards. I see there are few libary's out there for this board. What's the generally feeling on which one is the best?

Whats not clear to me is how do you set the address of each nRF24L01 so they know who to talk to?
57  Using Arduino / Project Guidance / Re: Car rev limiter on: January 24, 2013, 07:30:48 pm
Has anyone made any progress on a rev limter for a car, I'm also looking for quick ignition cut system for when a car misses a gear change
58  Using Arduino / Project Guidance / Re: Wireless project 4 transmitters, one arduino as receiver on: January 23, 2013, 03:21:34 pm
Thanks, sounds like these nRF24L01+ may also be an option. I have had a quick read up on them Nd I love the price. If I wanted my arduino board to read 4 analogue inputs, would I need 5 or 8 of the nRF24L01+ boards?
59  Using Arduino / Project Guidance / Re: Wireless project 4 transmitters, one arduino as receiver on: January 23, 2013, 02:44:31 pm
The plan is to use an LCD display to view the sensor information, long term is like to add Bluetooth for smartphone access .  Don't want to use a pc if possible
60  Using Arduino / Project Guidance / Re: Wireless project 4 transmitters, one arduino as receiver on: January 23, 2013, 10:54:19 am
Paul, I've ordered a copy of that book, looking forward to a read. So with the xbee I can have one arduino with xbee module, and have 4 sensors, each with there own xbee module to talk the the xbee module attached to the single arduino?

Sound perfect. Do you know of anything online I can read up on this before my book arrives?

Thanks

Jimster
Pages: 1 2 3 [4] 5