basic stamp to count encoder pulses?
oriol
Posts: 4
Hi!
I'm trying to use two basic stamps to get the model of a dc motor, one of them is used to give the motor the desired speed and the other is used to count the pulses of the encoder and send it to the pc. I'm using the USB port for communication and I have a MATLAB program runing in the pc to read the counts and calculate the speed, I need to get at least 500 samples. My first approach was to storage the counts in the stamp, but it can only hold 11 samples, so I saved 10 samples and send them later, like a buffer, but it takes about 65 miliseconds to send them all, (and not counting in that time).
The final approach I made was to send one count at a time, but the serial communication takes about 7.5 to 7.8 miliseconds, my question is: is there a way to have an exact serial communication? I mean that it takes exactly the same time to send the data?
I saw that extra memory can be added to the basic stamp, can that be the solution?
do I have to use an external clock or something like that?
Is the propeller better for this job?
Thanks for your time and help!!
Oriol
ps: attached is the bs2 code I'm using.
I'm trying to use two basic stamps to get the model of a dc motor, one of them is used to give the motor the desired speed and the other is used to count the pulses of the encoder and send it to the pc. I'm using the USB port for communication and I have a MATLAB program runing in the pc to read the counts and calculate the speed, I need to get at least 500 samples. My first approach was to storage the counts in the stamp, but it can only hold 11 samples, so I saved 10 samples and send them later, like a buffer, but it takes about 65 miliseconds to send them all, (and not counting in that time).
The final approach I made was to send one count at a time, but the serial communication takes about 7.5 to 7.8 miliseconds, my question is: is there a way to have an exact serial communication? I mean that it takes exactly the same time to send the data?
I saw that extra memory can be added to the basic stamp, can that be the solution?
do I have to use an external clock or something like that?
Is the propeller better for this job?
Thanks for your time and help!!
Oriol
ps: attached is the bs2 code I'm using.
Comments
Joms: I tried something like that, but i don't get a constant sampling time, so that's not a good solution for my application.
jeffjohnvol: I saw the encoder, I just have a question, can it be used to get speed? and even if it can be used for speed I might end up having the same error that I have with the other encoder, because my greatest trouble is in the serial communication, in order to get a constant sampling and a constant sampling frequency (the time between sampling periods).
I need real time speed measuring and now I realize it's not possible with the basic stamp, I'll try with another mc.
Thanks a lot for your time and help!!
I use a BS2 to count encoder pulses quite accurately. However, depending on serial communication to relay the pulse event to another device is--in my opinion--beyond the capability of the BS2: At 4000 instructions per second, it is simply too slow. While it is waiting on the serial communication to take place, it will miss encoder events. Not good.
My BS2 code is based on a very tight loop that merely monitors a single encoder output. When that output is high, the BS2 signals another, much faster Stamp, else the BS2 signals the faster Stamp that the signal is low. It works very well for the full rpm range that I use on my robot, Ugly Buster: 0 - 72 rpm at the gearmotor.
The faster Stamp (a BS2p40) is the "Master" and receives information from the encoder-Stamps and, based on that information, sends commands to the Stamps that control the gearmotors. (Well, actually the Master sends commands to the HB-25 motor controllers that, in turn, send commands to the gearmotors.)
A microcontroller, such as the Stamp, does not have an interrupt system and thus is incapable of halting and resuming an operation in mid-stream and performing another, higher priority operation that may arrive at any time. That is why Ugly Buster has five Stamps, the Master and four Slaves. Each Slave does a single VERY simple thing in a VERY tight loop and is more than fast enough to perform that task and raise or lower an I/O line on one of its pins, which is connected to the Master via a 470 ohm resistor.
As I add functionality to Ugly Buster, I will add a BS2 to handle each function. I go to extremes. For example, if I had an arm joint, a single BS2 would be devoted to monitoring the encoder that implies the joint angle. This method is far different than most use to control their machines.
Eventually, I will migrate to an SX microcontroller. The SX, which I may run at either 20MHz or 50MHz is probably capable of replacing all five of my current Stamps with capacity left over.
I'll find out.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
The motor that I'm using it's about the same rpm's (0-74) and it has a 500 cpr encoder, I'm only using channel A of the encoder, trying to make it faster. The only thing I do with the stamp is count the encoder pulses and send it to the pc using serial port (USB), everything else is done in the pc.
I was thinking about doing the same, switch to the SX, because the stamp it's just too slow for my application, right now I'm trying with a freescale (previously motorola) MC68HC908Q that a profesor had, it's suposed to be able to handle interrupts, so it might be my solution, but if that doesn't work I'll use the SX.
once again, thanks to all of you for your help.
oriol
Post Edited (oriol) : 7/5/2008 10:34:03 PM GMT
In my opinion--and that is all it is--a BS2 will not be fast enough to count pulses even at 74rpm AND use serial communication. If you try this, I will be extremely interested in your results, good or bad.
A BS2 is MORE than fast enough to count pulses and raise or lower an output pin to signal another processor, however. I have had great success doing this. But, I have never tried doing the same thing and substituting serial communication in place of bit-signaling.
Of course, like you I believe a single SX will handle all of it. However, my quest is to use true Stamps first. Later, I will go the SX route.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
If you want you can download the program I attached with my first post, it's a very simple code; it just waits for the character "A" followed by the sample period, then character "B" followed by the number of samples to be taken, then it goes in a loop for the number of samples, counts during the sample period and send this data to the pc. It works at a baud rate of 9600; I don't have a way to check if it's loosing counts, but when I plot the data in the pc it looks good, once again, I can't tell how good or bad it is because I don't have anything else to compare it.
The program was designed just to monitor the dc motor, not to controll it. Speed calculation it's made in the pc.
The serial communications takes about 7.5 to 8 miliseconds for every value sent, so in that time the stamps looses counts, it's up to the designer to decide if that's good enough for the application; in my personal case it's not good enough, that's why I'm looking for other solution(s).
Good day!
oriol