Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Actively switching PWM? on: July 18, 2011, 07:20:58 pm
So i guess this just isn't easily achievable? it would save me much circuit board space, and hassle to get this working through software.
2  Using Arduino / Programming Questions / Re: Actively switching PWM? on: July 17, 2011, 04:43:29 pm
I have another controller made by kelly controller that I will use if I absolutely must. This is the stock controller, and has a remote that came with it that I need to use. Using another controller would mean I would have to greatly modify the way everything mounts to the board. I am trying to keep everything as simple as possible. I can fit the arduino inside the motor controller box too which makes the whole package perfect. This is little coding issue is literally the only thing standing in my way of completing this project.
3  Using Arduino / Programming Questions / Re: Actively switching PWM? on: July 17, 2011, 04:24:35 pm
OK, so basically I have this motor controller. In order to switch between regenerative braking, and accelerating I must input a 244 hz frequency into a pin to make it regen, and 48.8 hz to accelerate. In addition I must apply current to another pin, and control the acceleration with an analog signal. Why I need both I don't know. Needless to say, I hate this controller! I am soooo close to finishing this project, this is one of the final barriers standing in my way to completing this project.

Edit: here is the motor controller:

http://fastestelectricskateboard.co.uk/shop/index.php?act=viewProd&productId=11
4  Using Arduino / Programming Questions / Re: Actively switching PWM? on: July 17, 2011, 04:12:24 pm
Hmmm.... I'm trying my best to understand what to do. I keep looking at the pwmfrequency page, but I am just not making sense of it. What do you mean by including the function? Should I put void in front of it or something? I can't say I am a programmer. I did all this coding by the knowledge of a c++ class I took back in high school. Sorry for stupid questions. I am a little worried about this message in the article I am reading:

Quote
Please keep in mind that changing the PWM frequency changes the Atmega's timers and disrupts the normal operation of many functions that rely on time (delay(), millis(), Servo library).

As you can see, there is indeed a delay in my code. Should I be taking a different approach to coding? is this something that should not be done on the fly?
5  Using Arduino / Programming Questions / Re: Actively switching PWM? on: July 17, 2011, 03:33:32 pm
Sorry! I have been inhaling solder fumes working on this darn project all day lol. Here is the whole thing.
Thanks so much for the help!




Code:
// These constants won't change.  They're used to give names
// to the pins used:
const int sensorMin = 90;
const int enableMin = 0;

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

const int analogInPin2 = A5;  // Analog input pin that the potentiometer is attached to
const int analogOutPin2 = 10; // Analog output pin that the LED is attached to

int sensorValue2 = 0;        // value read from the pot
int outputValue2 = 0;        // value output to the PWM (analog out)

const int analogInPin3 = A1;  // Analog input pin that the potentiometer is attached to

int sensorValue3 = 0;        // value read from the pot
int outputValue3 = 0;       

int sensorValue4 = 0;        // value read from the pot
int outputValue4 = 0;     


const int digitaInPin1 = 2;  // Analog input pin that the potentiometer is attached to
const int digitalOutPin1 = 4;  // Analog input pin that the potentiometer is attached to

const int regenPin = 8;
const int throttlePin = 6;

int reversedOutput2 = 0;    // reverse output
int difference = 0;         // Average
int posNeg = 0;


const int numReadings = 10;     // Averaging speed

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int readings2[numReadings];      // the readings from the analog input
int index2 = 0;                  // the index of the current reading
int total2 = 0;                  // the running total
int average2 = 0;                // the average

int additive = 0;
int addthis = 0;
float squared = 0;
int direct = 1;
int prethrottle = 0;
int throttle = 0;
int throttlefinal = 0;
int regen = 0;
int reverse = 255;
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);           
  // map it to the range of the analog out:
  outputValue = map(sensorValue, sensorMin, 1023, 0, 255); 
  // change the analog out value:
 
if (outputValue < 0)
{
    outputValue = 0;
}

  // subtract the last reading:
  total= total - readings[index];         
  // read from the sensor: 
  readings[index] = outputValue;
  // add the reading to the total:
  total= total + readings[index];       
  // advance to the next position in the array: 
  index = index + 1;                   

  // if we're at the end of the array...
  if (index >= numReadings)             
  // ...wrap around to the beginning:
  index = 0;                           

  // calculate the average:
  average = total / numReadings;         
           

  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);     
  Serial.print("\t output = ");     
  Serial.print(outputValue);   
 

// SECOND SET--------------------------------
  // read the analog in value:
  sensorValue2 = analogRead(analogInPin2);           
  // map it to the range of the analog out:
  outputValue2 = map(sensorValue2, sensorMin, 1023, 0, 255); 
  // change the analog out value:

if (outputValue2 < 0)
{
    outputValue2 = 0;
}
 
  // subtract the last reading:
  total2= total2 - readings2[index2];         
  // read from the sensor: 
  readings2[index2] = outputValue2;
  // add the reading to the total2:
  total2= total2 + readings2[index2];       
  // advance to the next position in the array: 
  index2 = index2 + 1;                   

  // if we're at the end of the array...
  if (index2 >= numReadings)             
  // ...wrap around to the beginning:
  index2 = 0;                           

  // calculate the average2:
  average2 = total2 / numReadings;         

 
   

  // print the results to the serial monitor:
  Serial.print("\t sensor = " );                       
  Serial.print(sensorValue2);     
  Serial.print("\t output = ");     
  Serial.print(outputValue2);   
 

 
  // wait 10 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(10);

//GUN CONTROLLER===================================

  // read the analog in value:
  sensorValue3 = analogRead(analogInPin3);
   
  outputValue3 = map(sensorValue3, 0, 1023, 10000, 500);
  //abs(outputValue3);
 
  outputValue4 = digitalRead(digitaInPin1);
 
 
  Serial.print(" \t sens3 = ");
  Serial.print(outputValue3, DEC);

//CALCULATIONS=====================================

difference = average - average2;

  if (difference > 0)
  {
    direct = 1;
  }
  else
  {
    direct = -1;
  }
 




difference = sq(difference);
difference = abs(difference);
difference = difference / outputValue3 * direct;


prethrottle = prethrottle + difference;

// Keep the output in the clear
if (prethrottle > 255)

  { 
    prethrottle = 255;
  }
 
if (prethrottle < -255)

  {
    prethrottle = -255;
  }
 
// Regen controls
if (prethrottle > 0)
// Positive?
  {
  regen = 255;
  setPwmFrequency(11, 128);
  }

if (prethrottle < 0)
// Regen?
  {
  regen = 0;
//  setPwmFrequency(11, 640);
  }

//Serial.print("\t diff = " );                       
//Serial.print(difference); 

  throttle = abs (prethrottle);

// Fall off, It stops

if (average <= enableMin && average2 <= enableMin)
{
  throttle = 255;
  regen = 0;
}

//Diagnostic outputs 
  Serial.print(" \t Throt = ");
  Serial.print(prethrottle, DEC);
   
  Serial.print("\t Cont = ");
  Serial.println(sensorValue3, DEC);
 
// Fix the throttle
  throttlefinal = map(throttle, 0, 255, 255, 0);

// Output that junk!

// Lights
  analogWrite(analogOutPin2, average2);
  analogWrite(analogOutPin, average);
 
// Controls
  analogWrite(throttlePin, throttlefinal); //Throttle Output
  analogWrite(regenPin, regen); // Regen Output
  digitalWrite(digitalOutPin1, reverse); // Reverse Output
  analogWrite(11, 128); //Frequency Output
}

6  Using Arduino / Programming Questions / Re: Actively switching PWM? on: July 17, 2011, 03:26:48 pm
I got rid of the 640, it still kicks back an error.

error: 'setPwmFrequency' was not declared in this scope
7  Using Arduino / Programming Questions / Actively switching PWM? on: July 17, 2011, 02:56:03 pm
Hello!

I need to switch a pin on the arduino from 244 hz to 48.8hz actively. I have tried using setPwmFequency, but it throws back an error. I have included a code snippet of what I have used. I can include the whole thing if needed. I have delays in the code, and the article told me that if I use this method that I will interfere with the delays. I have read some articles on this subject, but it is very confusing to me. Here is the article I where found this info. I don't think this is what I need though.

http://www.arduino.cc/playground/Code/PwmFrequency

Thanks so much to anyone who can help!



Code:
// Regen controls
if (prethrottle > 0)
// positive?
  {
  regen = 200;
  setPwmFrequency(11, 128);
  }

if (prethrottle < 0)
// Regen?
  {
  regen = 0;
  setPwmFrequency(11, 640);
  }
8  Using Arduino / General Electronics / Re: Flexiforce sensor with arduino, and only +5 volts on: April 26, 2011, 04:56:01 pm
 Thank you very much for that! Is that IC this op amp?

9  Using Arduino / General Electronics / Re: Flexiforce sensor with arduino, and only +5 volts on: April 26, 2011, 03:32:00 pm
That is actually how I had it set up initially for testing when I was using a less sensitive force sensor. I am now using the 100 pound sensor I plan to use with my project. This one is just so insensitive though, I figured I would set it up the way the schematic told me to. I am using a 10k trimpot shown below for my project. Maybe I need a larger trimpot (100k) to get the results I need? I could probably whack it with a hammer and have it barely light up the reference LED. I need it more sensitive than that lol.

http://www.sparkfun.com/products/9806
10  Using Arduino / General Electronics / Flexiforce sensor with arduino, and only +5 volts on: April 26, 2011, 03:11:02 pm
I need help modifying the following schematic to accommodate essentially the arduino power and nothing else. I tried switching the flexiforce pin from the inverting pin to the non-inverting pin of the op amp then powering it with +5v, but that did not work. I don't know the first thing about designing circuitry, so any help is greatly appreciated. I have done tons of googling with no luck.

If I have to use circuit, how I can get a -5 volt supply out of the 5v supplied on the arduino?

Thanks to anyone who can help me, I have been trying to solve this on my own for a couple days.

Pages: [1]