Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Making two waves simultaneously without using tone() on: May 31, 2013, 05:54:41 pm
Hey everyone

Looking for some guidance with my project. I need to create two separate square waves at variable frequencies. The frequency will be determined after the arduino has deciphered the frequency of an input wave. I have already gotten the frequency deciphering completed, now I need to figure out how to output two square waves simultaneously.


Code:
void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > ((1/infreq)/2)) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;  

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

The idea here is to create a 50% duty cycle by finding the period of the incoming wave and dividing by two to make the period for the new wave.
The problem with the code is that if I have, for example, a period of 3.3 for the incoming wave, I would divide this by two and use it as the inverval for the new wave.

This should return a frequency of 300hz, but on the scope I am only getting 246.23 hz.

Any idea on how I can fix the code, or any other ideas on how I can generate two waves simultaneously
2  Using Arduino / Project Guidance / Re: Manipulating RPM signals using arduino on: May 29, 2013, 11:02:42 am
If the 500 rpm signal is only needed to trick the ECU into believing the engine is running then I don't see any need for it to be variable speed - it could just be a fixed frequency square wave. The frequency is quite low and could easily be achieved in software using the approach demonstrated in 'blink without delay'. I would also use the same approach to generate the modified speedometer signal - have a global variable storing the current output interval, and toggle the output at that interval. Separately, read the input signal either by counting interrupts in a period (works better at higher frequencies) or by polling the input state and measuring the interval between state changes (works better at low frequencies), and update the global variable periodically.

I wouldn't use pulseIn(), just because it's a blocking function and that would require you to use hardware timers to generate the output signals - that's another layer of complexity that IMO you don't need.

I want the gauge cluster to display the electric motors' RPM, but I need power steering when I am not moving (Ie pulling out of the garage). Power steering only turns on when it senses an RPM signal ~ 500 RPM, and because my motors don't idle I need to create a fake signal.

I was thinking something along the lines of this, but haven't been able to get it to work.

Code:
void measure() {                        //measures the period of the signal in microseconds

  if(digitalRead(31) == HIGH) {           
    startTime = micros();   
    pulseLow = startTime - stopTime;
  }
  if(digitalRead(31) == LOW) {
    stopTime = micros();
    pulseHigh = stopTime - startTime;
  }
  period = pulseLow + pulseHigh;

}

Another choice I have is to use the 'freq measure library' seen here: http://www.pjrc.com/teensy/td_libs_FreqMeasure.html

I have tried this and it works, however I still have the issue of creating TWO seperate waves simultaneously, because only 1 tone() function runs per code.
3  Using Arduino / Project Guidance / Re: Manipulating RPM signals using arduino on: May 28, 2013, 09:35:15 pm
The electric car has no transmission, so the speed will be linear.

Therefore the RPM of the motor will be the RPM of the wheels.
MPH can be calculated from the wheel circumference (Pi * diameter) and the RPM.
For every revolution of your wheels, you know how far you've travelled (one circumference)  and you know the RPM of the wheels, so MPH is a simple maths problem.
Circ. * RPM *60 =distance per hour. Distance will need to be turned into miles by division.
Inches/(12 * 3 * 1760) = miles.

Thanks!
I have actually already figured that aspect of the program out, I am just stuck on how to count the frequency and how to output two waves simultaneously.
4  Using Arduino / Project Guidance / Manipulating RPM signals using arduino on: May 28, 2013, 08:21:33 pm
Hey everyone

I have converted my vehicle from gas to electricity, and am working on getting the electronic gauge cluster functioning again.
The car speedo interprets square waves, 0-12v for the MPH and 0-5v for the RPM signal.
Using a small signal generator, I was able to discover that the MPH is interpreted roughly by the function Mph = ((hz - 46.smiley-cool / 43.2) .
The electric car has no transmission, so the speed will be linear.

I need the arduino to
1. Interpret an incoming RPM signal from the electric motor
2. Create TWO new square waves

One signal will be the incoming RPM signal manipulated the function above to display MPH.
The other signal will be the incoming RPM signal from the electric motors, but the arduino will be required to recognize if the RPM signal is less that 100 RPM, and if so create a 500 RPM signal to 'trick' the ECU into thinking the car is on, and thus providing power steering.

So here is where I need help:
 
How would I create code to discern the electric motor's RPM signal's frequency?
Second, how would I create a new signal ? I was planning on just using the 'tone' function, however I would need to create two tones and the arduino is only capable of running one (as far as I know).

Thanks for the help !
5  Using Arduino / Project Guidance / Troubleshooting a sluggish push-button program on: May 26, 2013, 10:48:03 am
Hey guys

I have been working on controlling the tail lights in my car with arduino. The original tail lights had 4 bulbs (brake running lights, braking, turn signal, and reverse), but I replaced it with two LED rings connected in parallel, essentially one bulb. This has created the need for an arduino and relays to control the LED ring to flash in correspondence to the car's brake, turn, running signals.

The program for tail lights is very simple, all it does is read if there is power at XX pin, and if there is, set another pin to HIGH or LOW to control a 8 relay module I purchased off ebay. The relays dictate when the LED tail lights get power.

Before setting the arduino up in the car, I decided to try it on the bench. I have 3 arduinos, 2 Unos and one pro mini 5v. I have encountered the same issue with all of them
The relay board's VCC and ground are connected to the arduino's VCC and ground, and the a IN pin on the relay board is connected to digital pin 11 on the arduino. Meanwhile, i have a loose wire inserted into digital pin 5 on the arduino, and the other end is stripped so that I can touch it to VCC on the arduino and make pin 5 HIGH.

Here is the example code I am running

 
/* Basic Digital Read
 * ------------------
 *
 * turns on and off a light emitting diode(LED) connected to digital 
 * pin 13, when pressing a pushbutton attached to pin 7. It illustrates the
 * concept of Active-Low, which consists in connecting buttons using a
 * 1K to 10K pull-up resistor.
 *
 * Created 1 December 2005
 * copyleft 2005 DojoDave <http://www.0j0.org>
 * http://arduino.berlios.de
 *
 */


int ledPin = 11; // choose the pin for the LED
int inPin = 5;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
}

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, HIGH);  // turn LED OFF
  } else {
    digitalWrite(ledPin, LOW);  // turn LED ON
  }
  Serial.println(val);
  delay(1000);
 
}


Here is my problem: When i short pin 5 to VCC to make it high, the relay will respond, but when I remove VCC from pin 5, it takes a second or two for the relay to respond again. It is sluggish in the time it takes for the arduino to interpret the signal, and I need it to be quicker. I realize that relays are relatively slow compared to mosfets and transistors, but my relays are going much slower than they are capable of going.
This same problem occurs when I remove the relay board, and instead set the output pin (LED pin in the code) from 10 to 13 (onboard LED). Again, when I short pin 5 to VCC and remove it instantly, the LED takes a couple of seconds to respond. Generally, once Pin 5 is shorted to VCC, the LED (or relay) turns on instantly, but takes a couple of seconds to shut off after the VCC to pin 5 has been removed. Its very frustrating!

Any ideas on whats going on?
6  Using Arduino / Project Guidance / Re: Making a 0-12v & 0-5v pulse on: January 30, 2013, 09:57:16 pm
If "source follow" doesnt work on a mosfet, does that mean that the circuit provided wouldn't work?

Correct.

Hmm
How would you do it then, assuming the arduino cant output a 12v for the 0-12v pulse
7  Using Arduino / Project Guidance / Re: Making a 0-12v & 0-5v pulse on: January 30, 2013, 08:32:28 pm
Thanks for the help guys!

I don't think the signal will be PWM, it should just be 0-12v with changes in frequency.
If "source follow" doesnt work on a mosfet, does that mean that the circuit provided wouldn't work?
8  Using Arduino / Project Guidance / Re: Making a 0-12v & 0-5v pulse on: January 29, 2013, 03:38:39 pm
bump help
9  Using Arduino / Project Guidance / Re: Making a 0-12v & 0-5v pulse on: January 28, 2013, 06:16:59 pm

I want to use an arduino, either a mega or an UNO R3, to make both signals at the same time. I know a mechanical relay would not be capable of running the necessary frequencies (0 - 100khz-ish), so how would I do this? Transistors?


Better use MOSFETs, they're more efficient in switching, faster, too. Provides more power if you need it, aswell.

Good luck on the project! Quite ambitious, but FUN! Post some pictures!

Would a mosfet like this work ? http://www.radioshack.com/product/index.jsp?productId=2062618
What would I do with each of the pins? I need a fritzing diagram!

As for the project, take a look here smiley http://www.s2ki.com/s2000/topic/975497-wait-that-isnt-an-f20c/
10  Using Arduino / Project Guidance / Re: Making a 0-12v & 0-5v pulse on: January 27, 2013, 09:42:02 pm
That's quite a ambitious project you've taken on. I can only give a possible answer (but not validated) to:

Quote
The computer also sends both the VSS and engine RPM signal to the electronic steering pump's control box so that power steering works. However, I am not sure how the power steering control box handles the signals - this is why I need to figure out how the signals interact before making a final circuit.

I believe the higher speed a vehicle is going the less power steering force it requires to prevent over sensitive steering control at higher speeds. So I suspect the signal was used to vary or bypass the hydraulic pressure applied to the power steering assist actuator.

Lefty

You're likely correct. I think the computer may search for an RPM signal (~1500 RPM, idle) at zero mph, and in turn give full power steering. After that point, I think it would moderate the power steering based on the mph reading. As you go faster (increase mph), less power steering.

11  Using Arduino / Project Guidance / Making a 0-12v & 0-5v pulse on: January 27, 2013, 08:50:01 pm
Hey guys!

I am in the process in converting my car to an electric drive train. Removing the stock engine / transmission have rendered my digital instrument cluster, as well as electronic power steering, useless. The two primary signals that feed the car's computer are the vehicle speed sensor (VSS) signal and the crank signal. From these signals, the computer calculates the vehicles speed (off of VSS) and the engine's RPM (off of crank signal). The computer also sends both the VSS and engine RPM signal to the electronic steering pump's control box so that power steering works. However, I am not sure how the power steering control box handles the signals - this is why I need to figure out how the signals interact before making a final circuit.

I want to use an arduino, either a mega or an UNO R3, to make both signals at the same time. I know a mechanical relay would not be capable of running the necessary frequencies (0 - 100khz-ish), so how would I do this? Transistors?
The engine RPM signal runs off of 0-5v square wave signal, while the VSS runs off of a 0-12v signal.
I should also add that the signals will not run at the same frequencies, the VSS may be running at 50khz while the crank signal may be running at 5 khz.

Thanks for the help guys :-)
Pages: [1]