Show Posts
Pages: [1]
1  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: March 01, 2011, 12:19:46 am
No the code above was a sample attempt at programming, however, we have finally achieved success! (With getting RPM)  Using the extra Interrupt on the Arduino Mega, it was much easier.
So the way it works is by attaching the encoder's output (either A or B or the Index) to pin 18, then attaching the interrupt to interrupt 5
which is only triggered when pin 18 goes from low to high.
It then calls the incrementit function that does just that, increments the counter.
Then after 10, or 100 ms the count is tallied.
(Thus far tested to 17Khz or 1900+ RPM)
Code:
#include <MsTimer2.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(52, 50, 48, 46, 44, 42);

volatile int count = 0;
double out = 0.0;
double motorout = 0.0;
double kp = 3.0;
double setpoint = 1450.0;

void setup()
{
  lcd.begin(16, 2);
  pinMode(12, OUTPUT);
  Serial.begin(115200);   // start serial communication
  attachInterrupt(5, incrementit, RISING);  //attaches interrupt to the mega's pin 18 (interrupt 5)
  MsTimer2::set(100, flash); // 100ms period
  MsTimer2::start();
}



void loop()
{
//  out = (1450 - out);
//  lcd.print(out);
//  delay(500);
//  lcd.clear();
}

void incrementit()
{
  count++;
}
void flash()
{
  lcd.clear();
  out = count;
  out = (setpoint - out);
  lcd.print(out);
 
  motorout = (setpoint+kp*out)*(5735.0/10000.0) - 661;
  motorout = constrain(motorout, 0, 255);
  Serial.println(motorout,DEC);
  analogWrite(12, motorout);
  //Serial.println(count,DEC);
  count = 0;
}
2  Using Arduino / Motors, Mechanics, and Power / Re: What kind of servos for hexapod walk? on: February 24, 2011, 10:52:47 pm
You might check out this site: http://hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=8496
The website is pretty good, and those particular servos should give you ample torque if they fit within your design.
(I don't know about these servos for quality, but due to good reviews and good pricing, it might be worth it to try 'em!
Oh and I recognize that they are not Hitec, but can you afford the difference?  These are about 25 + shipping, 33 kg cm (457 oz-in), the corresponding hitec would be the HS-7950TH which will run you around 149 ish
3  Development / Other Software Development / Re: MSTimer2 and the Arduino 2560 (UNO Mega) on: February 24, 2011, 10:21:26 pm
What software can I use to apply this patch to the original MSTimer2 or better yet, do you have a link to where I can download your modified .cpp and .h files? 
Thanks!
4  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: February 24, 2011, 10:17:45 pm
Also, does anyone know off the top of their head, what the precision and maximum measurable frequency is for the Arduino? (using freqCounter.h)
Thanks again for all the great posts, keep them coming!  (Oh after we finish this project, I plan on posting everything learned for others so they don't have to struggle like we are!  smiley-razz )
5  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: February 24, 2011, 06:29:15 pm
Thank you for your post, and we will probably give it a try if we can't get the freqcounter.h library to work, which is currently having problems, because it won't work with the arduino mega 2560.  (Keeps saying sbi and cbi are not defined, which I don't understand)   I'm pulling most of what I'm doing from this forum: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1231326297/15
Anyone with ideas on how to fix the freqcounter.h for the mega 2560, that would be amazing!  I've tried entering the 2560 to the #define section, but no luck.  Please help!  Thanks ahead of time! smiley
6  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: February 08, 2011, 12:17:40 am
So I re-wrote the program again due to my class using the Arduino Mega and the Mstimer2 not working with it.  So here is the new revision, which when outputting to the screen at 1/10th of a second, is fairly accurate, but when going above that, it quickly loses accuracy, any ideas why?
Code:
#include <SimpleTimer.h>
SimpleTimer timer;


int signalstate = 0;
int laststate = 0;
long int counter = 0;
long int screen = 0;
void repeatMe()
{
  long int tempequ = ((counter / 5) * 6);
  screen = tempequ;
  Serial.println(screen, DEC);
  counter = 0;
}
 
void setup()
{
  pinMode(9, INPUT);
  Serial.begin(9600);
  timer.setInterval(100, repeatMe);
}
//each time through the loop it does a read on the digital port,
//nothing happens till the pin goes "LOW" then each time through
// it checks to see if the state has changed, if so, then and
//only then does it increment the counter.
void loop()
{
  timer.run();
  signalstate = digitalRead(9);
  if(signalstate == LOW)
  {
    laststate = 1;
  }
  if(laststate == 1 && signalstate == HIGH)
  {
    counter++;
    laststate = 0;
  }
 
}
7  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: February 05, 2011, 09:35:32 pm
I have re-written the code and so let me know what you think-
Code:
#include <MsTimer2.h>

// Switch on LED on pin 13 each second

int signalstate = 0;
int laststate = 0;
long int counter = 0;
void flash() {
  Serial.println(counter, DEC);
  counter = 0;
}

void setup()
{
  pinMode(9, INPUT);
  MsTimer2::start();
}
//each time through the loop it does a read on the digital port,
//nothing happens till the pin goes "LOW" then each time through
// it checks to see if the state has changed, if so, then and
//only then does it increment the counter.
void loop()
{
  signalstate = digitalRead(9);
  if(signalstate == LOW)
  {
    laststate = 1;
  }
  if(laststate == 1 && signalstate == HIGH)
  {
    counter++;
    laststate = 0;
  }
  
}
8  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: February 02, 2011, 05:29:54 pm
I apologize for the naming, but I actually wanted to measure each pulse from the IC chip, so it should be a relatively clean TTL signal not really requiring debouncing (I hope).  My biggest worry is that I will measure a "high" signal twice thus incrementing my timer twice for the same signal.  So I guess you could sum up my entire problem as finding a way to measure the digital frequency with an arduino.
Any ideas for the coding would be great!
9  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: February 01, 2011, 10:18:37 pm
Here is an attempt at coding, I'm looking for any thoughts for improvement and more importantly for thoughts of implementation.
Thanks ahead of time:
#include <MsTimer2.h>

//Output the value of count to the serial monitor

int buttonstate = 0;
long int counter = 0;
void flash()
{
  Serial.println(counter, DEC);
  counter = 0;
}

void setup()
{
  pinMode(9, INPUT);
  MsTimer2::start();
}

void loop()
{
  buttonstate = digitalRead(9);
  if(buttonstate == LOW)
  {
    buttonstate = digitalRead(9);
    if(buttonstate == HIGH)
    {
      counter++;
    }
  }
}
10  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: January 29, 2011, 11:10:40 pm
Thanks for the replies, I will start digging for the spec sheet on Monday.  In the mean time the decoder chip converts the AB signals, to a speed pulse on pin 1 for forward and if the motor reverses, it stops sending pulses on pin 1 and starts sending pulses on pin 2.  Which should make it easier to sample the incoming data especially while I'm just trying to determine the RPM in one direction (for now  smiley-wink )

**EDIT**

So in forward pin one (TTL)pulses and pin 2 is off.  Then in reverse pin one turns off and pin 2 starts a TTL pulse at a proportional value to RPMs.  Oh and we are using the Arduino MEGA.
11  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: January 29, 2011, 02:29:28 pm
We are using a quadrature encoder, however our IC chip takes the A/B Pulses and outputs on two pins their combined pulse. (ex. Pin 1 is putting out an 11khz pulse telling me that the motor is rotating at about 1300 RPMs in forward motion, while pin2 is kept in a low state.  Vice versa for when the motor rotates backwards, causing pin 1 to go low and pin 2 to start pulsing)  I would go with the Idea from Graynomad, save I do need PWM for driving said motor.  But thanks for the ideas so far!
I was thinking about using this library: http://www.arduino.cc/playground/Main/MsTimer2  And set a sample in the "Loop" portion of the program so that it is continously sampling and every time there is a change in state from low to high (thus eliminating the chance of sampling the same pulse twice) I could increment a counter. Then every 1 second, it outputs the count to the screen.  If this sparks any ideas, let me know.
12  Topics / Science and Measurement / Re: Measuring the Frequency of a TTL circuit on: January 27, 2011, 12:12:02 am
It is for a quadrature encoder, however I already have a IC chip that converts the A and B signal into two separate pins for forward and back, so now all I need to do is count those pulses to know the RPM of the motor this encoder is connected to.  (Using it for a PWM output eventually, but for now, just focusing on getting accurate sampling)
Thanks for the replies thus far!  Keep 'em comin'!

**EDIT**
Oh and using an Oscilloscope, have measured the "forward pulses" at about 11khz, hence the need for a quick sample.
13  Topics / Science and Measurement / Measuring the Frequency of a TTL circuit on: January 26, 2011, 07:57:18 pm
I'm looking for help in measuring accurately a 20KHZ digital signal, its to read the pulses from a 500 pulse per revolution encoder that at top speed will spin around 1700 RPMs.  Any ideas on how fast the arduino can read a digital signal and how to count them?  (Also need to read two at a time, so will want to connect to more than one pin) 
Thanks!
Pages: [1]