Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Stepper Library Max speed bug on: January 16, 2011, 06:19:23 pm
yes I know there int type variables and thats why its not working so when you switch everything over from milliseconds to microseconds then the 0.966 thats seen as 0 is now seen as 996microseconds
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Stepper Library Max speed bug on: January 16, 2011, 03:49:55 pm
Ive recently been testing and driving some new steppers I got with the standard arduino Stepper Library, I am aware that a few bugs have been posted about this perticular Library.

If this bug has already been posted and reported my apologies but I was unable to find it in the forums and its still in the most recent release

During my test with the stepper i used a potentiometer to set the speed of the stepper,
I have a 45v powersupply @ 3A, so I know the voltage isnt the problem
and my Stepper is 1.8deg/step with total 200 steps/revolution

Here's the code I started with:

Code:
Stepper stepper(200,5,6,7,8);
void setup()  {
  
  Serial.begin(9600);
  
}

void loop()  {
  
  del = map(analogRead(0),0,1024,1,500);
  stepper.setSpeed(del)

  stepper.step(1);
}

This is suppose to map out the 0-1023 value from the analog pin to 0-500 for the rpm of the stepper library

While moving the knob through its full rotation I noticed the stepper reach a certain speed and any further the stepper stop moving and generated a semi high frequency,
I pulled out my osciliscope and noticed as I turned the knob the frequency on 1 of the 4 pins jumped from 245hz to 6000hz

This striked me as odd so i went back to the code and found that this happened when I set the setSpeed() function to 301, anything before 300 would be fine but 301+ generated alarming high frequency,

I looked through the Stepper Library code and found the problem and also came up with a solution

Heres the section of code that has the bug, where the delay is setup for the step function

Code:
void Stepper::setSpeed(long whatSpeed)
{
  this->step_delay = 60L * 1000L / this->number_of_steps / whatSpeed;
}

void Stepper::step(int steps_to_move)
{  
   if (millis() - this->last_step_time >= this->step_delay)
      this->last_step_time = millis();
}

in the setSpeed function it calculates the delay needed in milliseconds to achive the deisred switching frequency. It appears that the step_delay variable which is apparently an int-type variable freaks out when I use 301+ rpm @ 200 steps/revolution

heres why:

60 * 1000 / #ofsteps / speed
= 60 * 1000 / 200 / 301
= 60,000 / 200 / 301
= 300/301
=0.9966

due to the int-type variable the 0.996 dosnt work to well, becuase it uses that value and the millis() function to determin the delay

**FIXED**

by using the micros() function instead of the millis() function and multiplying the step_delay by 1000 it maps the 0.996 millisecond delay to 996 microsecond delay, because 1 millisecond = 1000 microseconds

CODE:

Code:
void Stepper::setSpeed(long whatSpeed)
{
  this->step_delay = 60L * 1000L / this->number_of_steps * 1000 / whatSpeed;
}

void Stepper::step(int steps_to_move)
{  
   if (micros() - this->last_step_time >= this->step_delay)
      this->last_step_time = micros();
}


This has been checked with an osciliscope and the 6000hz frequency that was being generated at 301rpm @ 200steps is now around 250hz, where as the 300rpm value that worked with the bug was around 245hz

PROBLEM FIXED!!

enjoy


Arch3r
3  Forum 2005-2010 (read only) / Interfacing / EEPROM VS SDCARD on: January 23, 2011, 06:28:28 pm
My current project needs to save stepper motor speeds to playback kind of hardware animation so-to-speak

Ive boiled it down to two different methods and im wondering if theres any problems with either ive overlooked

the data im saving is one byte (which step to change the stepper motor speed)  and one int -2bytes- (the actual speed for the motor) for every entry of data

first method
I stream the data from a computer via serial and save the first byte into arduino internal eeprom and the next int into an external eeprom
upon startup of the arduino i pull the internal eeprom bytes and place them into arduino RAM (atmega 328 - 1k RAM) for quicker access

Second Method
I save the byte and int onto a sd card from the computer then plug that into the arduino, the arduino reads the byte and again stores it into the RAM and leaves the int in the sdcard for lookup when it needs to

Any comments and suggestions are welcomed
4  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + CPLD + 200+ Photodetectors on: August 16, 2010, 04:47:45 am
The problem with using alot of shift registers say using an I2C bus, during other projects with them its hard to find which of the shift registers pin has changed, since the arduino only has 2 interupt pins using more than 2 shift registers produces problems in sending requests on every chip on the bus,
not to mention using 200+ detectors would need over 12 chips and alot of shift registers only let you use 8 on the same bus,

Agreen microsecond response isnt required but a fast detection < 5-10ms would be minumum

The detectors im using are IR phototransitors(analog output)

And for the LED's i have no problem because they are all just wired up to 5v and gnd rails so there always on, i dont think pulsing each individual led would work only since they have to shine their beam over 36" i dont think just a straght up pulse would give accurate results on the phototransistors, and possible when your done pulseing one side of the screen the object could move(innaccurate results)

I know im shooting down your input and ideas but input like this and any other is really appreciated
5  Forum 2005-2010 (read only) / Interfacing / Arduino + CPLD + 200+ Photodetectors on: August 16, 2010, 02:57:28 am
I am currently working on a 42" multitouch screen using an array of IR led's and IR photodetectors of over 200 of each, that creates and x-y grid along my screen. I need to find away to interface the 200+ detectors to the arduino,

My first thought and so far best idea(personal opinion), is to hook the detectors to one/multiple CPLD's and and have output pins that pulse high and low according to the detectors that caused the interupt and a high speed binary counter to pick up the pulse and turn them into an 8bit number the arduino can read

My question is if this is a good sulutions to my problem or are there tweaks needed or better solutions, its not easy interfacing 200+ detectors to an arduino smiley
Pages: [1]