Pulse counter to PC file

Status
Not open for further replies.

Thread Starter

frankpc

Joined Jul 25, 2010
41
I plan to attach a slotted opto coupler to the motor of my treadmill to generate pulses. The motor has a slotted wheel designed for this purpose. I will then divide and count the pulses using perhaps 74LS90's. Then interface that using rs232 to a desktop pc and somehow access the data, save it to a file and periodically, ftp it to a server. I know the count needs to encoded somehow along the way. And I am hoping this doesn't tie up a significant portion of the computer's processing power.

A big assumption is that this is the proper way to gain access and process the data. I've read on this forum that MScomm would be a candidate to acquire the data. I'm wondering whether I am on the right track or completely derailed. I've done a little work with PIC's, but don't know whether their use is really necessary for this. And I haven't had to interface them to a computer.

Also, I wouldn't be surprised to learn that something is already available to purchase from one of the hobby online stores that would do a major portion of what I'm trying to do. I would like to keep this project as simple as possible. We have a new baby with us now and my wife will shoot me if I spend an inordinate amount of time on this.

I'm just looking to find out whether anyone knows of a straight-forward way to accomplish this without spending a major portion of the child's college funds.

Thank You for your time,
Frank
 

BMorse

Joined Sep 26, 2009
2,675
You can use a circuit directly coupled to the Serial port of the PC to accumulate the counts and have the PC process the "data" accordingly....

If you are familiar with Visual Basic and the use of the MSComm Control object this would be fairly easy and straight forward....

Here is a simple circuit that can be used to interface to a 5 volt TTL circuit to a serial port of a computer.... every time there is a positive pulse on the optocoupler, the serial port ring indicator will go high... this can be tracked with the MSComm controls OnComm Event....

Make sure to enable DTR in the MSComm controls property to power the output side of the optocoupler...

Serial Port TTL interface.png

B. Morse
 

Thread Starter

frankpc

Joined Jul 25, 2010
41
Thank You B Morse,

Couldn't get much simpler than that!

I have programmed with VB in connection with Excel macros but that is it. Never had to use it to communicate with anything outside of Excel. Also I have not worked with MScomm.

Are than any examples of those types of things here on the Forum?

I was also thinking about using a "1-wire" counter with the DS2423, but again, I have never used 1-wire devices. And if I did do that, I don't know how difficult it would be to gain access to the USB or serial 1-wire port.

Thanks! This gets me going!

Again, thank you for your time.

Frank
 

BMorse

Joined Sep 26, 2009
2,675
You would have to use Visual Basic to actually work with the MsComm control object...

here is some Visual Basic 6 code to get you started if you have access to VB6.... if not let me know and I could possibly work with you in creating an application to log the pulses in a comma delimited text file you could import into excel or something....

View attachment Serial port test.zip

The sample code above will count pulses coming from the serial ports ring indicator line and display them in a textbox on the screen.....
just have to set the MSComm controls port number to the one being used before opening the port...

B. Morse
 

BMorse

Joined Sep 26, 2009
2,675
<snip>

I was also thinking about using a "1-wire" counter with the DS2423, but again, I have never used 1-wire devices. And if I did do that, I don't know how difficult it would be to gain access to the USB or serial 1-wire port.

<snip>
Frank

Well, if you are already using a PC to accumulate the pulses coming from the slotted wheel, I think it would be overkill to add any other external circuitry to do any counting, considering the PC can accept the pulses, accumulate the counts and also process them... so there really is not a need for any other external circuitry..... unless you want to do something else besides just count revolutions??? The PC app can even do all the math work for you to figure out miles traveled, speed, time, etc... and the PC should be able to do all this without you even noticing...

B. Morse
 

windoze killa

Joined Feb 23, 2006
605
I tried to do this once. Spent hundreds on a treadmill. Hooked it al up and it failed miserably. I spent ages trying to workout what was wrong.....

Then BINGO.....

You actually have to hop on the tread mill and do some exercise.

Bugger... another failed project. :D
 

Thread Starter

frankpc

Joined Jul 25, 2010
41
W. K. I understand your frustration. What I've learned is that the more time you spend messing with the circuitry and process to measure the distance traveled and the speed and the other things that B Morse has listed, the less time you have to spend actually running.

Electronics to the rescue again!
 
Last edited:

Thread Starter

frankpc

Joined Jul 25, 2010
41
You would have to use Visual Basic to actually work with the MsComm control object...
B. Morse
Thanks so much for the help B. I am encouraged. I have ordered the slotted opto couplers and I plan to epoxy one to the motor when it arrives. The motor already has "fins" on it for that purpose and it already has a slotted opto coupler for the treadmill's own use. I just didn't want to tie into that one since I have no schematics and there is no warranty on a treadmill that would be very costly to repair if I were to mess it up.

I do have a PC that runs 24/7 and it is used for my other Home Automation stuff. I am hoping to save the raw counts (and times?) to a file on that PC. I also have an ftp program that can periodically upload the text file to a server.... Then, a second computer will download the text file and process it with an app written in PHP and save the results to a mySQL database.

The HUGE difference with this project is that it will pull data in from the serial port and create a file using a DIY application. I haven't written applications that run on their own.

I do have VB 6.0. I will digest what you have provided me. I will have to learn how VB can use MScomm to pull data in and save it to a file. Right now, I don't really understand how VB is told when a pulse is available to be grabbed. The "24/7" PC is also a video server. Do you think the processing required for VB to grab the pulses will take much processing power?

Thanks for your help in leading me to the trough B Morse. I will try not to fall in and drown.

Frank
 

windoze killa

Joined Feb 23, 2006
605
W. K. I understand your frustration. What I've learned is that the more time you spend messing with the circuitry and process to measure the distance traveled and the speed and the other things that B Morse has listed, the less time you have to spend actually running.

Electronics to the rescue again!
Frank, my post was for pure humour value. hence the big cheesy :D
 

BMorse

Joined Sep 26, 2009
2,675
Thanks so much for the help B. I am encouraged. I have ordered the slotted opto couplers and I plan to epoxy one to the motor when it arrives. The motor already has "fins" on it for that purpose and it already has a slotted opto coupler for the treadmill's own use. I just didn't want to tie into that one since I have no schematics and there is no warranty on a treadmill that would be very costly to repair if I were to mess it up.

I do have a PC that runs 24/7 and it is used for my other Home Automation stuff. I am hoping to save the raw counts (and times?) to a file on that PC. I also have an ftp program that can periodically upload the text file to a server.... Then, a second computer will download the text file and process it with an app written in PHP and save the results to a mySQL database.

The HUGE difference with this project is that it will pull data in from the serial port and create a file using a DIY application. I haven't written applications that run on their own.

I do have VB 6.0. I will digest what you have provided me. I will have to learn how VB can use MScomm to pull data in and save it to a file. Right now, I don't really understand how VB is told when a pulse is available to be grabbed. The "24/7" PC is also a video server. Do you think the processing required for VB to grab the pulses will take much processing power?

Thanks for your help in leading me to the trough B Morse. I will try not to fall in and drown.

Frank

The VB code should be pretty straight forward.... and the way the MSComm handles the inputs is through what they refer to as an Event Driven method, if an event occurs such as a Ring input, the MSComm's OnComm event will be triggered.....

After thinking about this a bit last night, I think using the CTS line for an input would be better, since this line can actually be polled to see if it's High or Low, so you will be able to "time" the transitions between pulses to get the pulse width time and possibly use that to calculate RPM's and Speed...

And, No, the Pulse "metering" should not tax the PC's speed too much... You probably won't even notice it running....

B. Morse
 
Last edited:

BMorse

Joined Sep 26, 2009
2,675
Here is an updated circuit including the slotted Photo Interruptor assembly, this one connects to the CTS (Clear To Send) line on the serial Port... although it will have to be powered separately with a 5 volts supply or 3 AA's...

Come to think of it, you may also use the serial port to power the circuit...


Slotted OPTO to Serial Port Int.png


Edit:
Here is an updated circuit which is powered off of the serial port.... this may not work with a laptop serial port since some newer ones only put out -5/+5, so if used with a laptop serial port, some resistor values may have to be changed...
RS232 Self Powered Interface.png


B. Morse
 
Last edited:

Thread Starter

frankpc

Joined Jul 25, 2010
41
Frank, my post was for pure humour value. hence the big cheesy :D

Yes, I understood. And it did enjoy it. My comment was intended to share your humor, perhaps in a drier way. As I started to read it, I knew already where it was going. It's nice to be welcomed to a new board with a joke!
 

Thread Starter

frankpc

Joined Jul 25, 2010
41
so you will be able to "time" the transitions between pulses to get the pulse width time and possibly use that to calculate RPM's and Speed...

And, No, the Pulse "metering" should not tax the PC's speed too much... You probably won't even notice it running....

B. Morse
Thanks again. I re-read your previous posts last night and noticed that you had mentioned the PC not even noticing the extra load. Interesting. Also your idea of timing the pulse width is interesting. I hadn't thought about doing that. I was thinking that for each pulse, I would send a time stamp to the text file. But if I did that, I would lose the pulse width. But of course, processing the timestamps would yield the speed. Also realized that perhaps VB could just update the raw data to the mySQL database. Don't know. And perhaps VB could do the processing, as you suggest, prior to uploading to the mySQL database. I have always tried to minimize the work done by that computer to make way for the video cameras. But if the additional work is minimal, Great!

Had thought about just doing some simple pulse count dividing back at the treadmill... Say send a pulse every 10' rather than 32 pulses per foot (approximately for what the rate will be.) That equates out to 563 pulses per second at 12 mph (treadmill's top speed). And if I attempted to run for 10 seconds at 12 mph, it would be my last run. The project would be complete.

Would 563 Hz including processing be taxing?

Thanks,
Frank
 

Thread Starter

frankpc

Joined Jul 25, 2010
41
Here is an updated circuit which is powered off of the serial port.... this may not work with a laptop serial port since some newer ones only put out -5/+5, so if used with a laptop serial port, some resistor values may have to be changed...
View attachment 21357

B. Morse
Thank you for the work B Morse. The PC will be a full desktop. I'll have to measure the voltage. I assumed it would be +/- 12, but need to confirm that. I do have an oscope, so I will be able to tailor the circuit a bit if need be.

This is an interesting project, whose principles with both hardware and software will be applicable in other areas where monitoring is required.

Thank you for your expertise in that regard.

Frank
 

BMorse

Joined Sep 26, 2009
2,675
Here is an updated project for VB6, using the new self powered circuit connected to the CTS input pin.... you can run the app and do some testing for now to see if things will work for you on the circuit side, then maybe later on you can polish it a bit.....

View attachment Serial Port Test.zip

563Hz shouldn't be too bad, but if you want to, you can add some kind of counter IC to the circuit possibly based around a couple of 4017 IC's or a Divide by n Counter IC such as the MC14018B....


B. Morse
 

BMorse

Joined Sep 26, 2009
2,675
Ok, just for sh!t$ and giggles, I put together a rough draft of a circuit with a couple of counters to act as pulse dividers... the way I have it connected is that every 32 pulses it will output a pulse to the PC (so every foot = 1 pulse) but the circuit can be adjusted easily to get different values for the division rate...

I have not fully tested this circuit so I am not sure about getting enough power from the port to power the whole thing, using the DTR and RTS lines gives the circuit around 10mA, but with the 1K resistors in place this limits the current even more.....

Slotted OPTO to Serial Port Int w Divider.png

B. Morse
 

Thread Starter

frankpc

Joined Jul 25, 2010
41
Ok, just for sh!t$ and giggles, I put together a rough draft of a circuit with a couple of counters to act as pulse dividers...
B. Morse

Thanks B.

I'll look around to see if I might have a couple 4017's. It would be great if the thing could be powered by the rs232 source itself.

If I end up doing the dividing at the treadmill, as you propose, I will have all ready lost the pulse width - Or am I wrong about that? Does the pulse width carry through the counter? If the width is lost, no big deal. But I was thinking, if I'm going to divide, I might as well divide by 100, for example. Or add another 4017 and divide by 1,000(?). If I can keep the belt moving, there would still be a ton of pulses to deal with.

So... When the pulses are coming in for say 2 hours... Does the data get stored in a buffer that is written to a file / uploaded periodically? Do you agree that each pulse would be stored as a Unix 10 digit timestamp and a return? That would provide a resolution of 1 second I think.

Thanks B.

Frank
 

BMorse

Joined Sep 26, 2009
2,675
Thanks B.

I'll look around to see if I might have a couple 4017's. It would be great if the thing could be powered by the rs232 source itself.

If I end up doing the dividing at the treadmill, as you propose, I will have all ready lost the pulse width - Or am I wrong about that? Does the pulse width carry through the counter? If the width is lost, no big deal. But I was thinking, if I'm going to divide, I might as well divide by 100, for example. Or add another 4017 and divide by 1,000(?). If I can keep the belt moving, there would still be a ton of pulses to deal with.

So... When the pulses are coming in for say 2 hours... Does the data get stored in a buffer that is written to a file / uploaded periodically? Do you agree that each pulse would be stored as a Unix 10 digit timestamp and a return? That would provide a resolution of 1 second I think.

Thanks B.

Frank
The pulse width may still carry over but it would be an average for the 32 pulses, so the faster your belt is going the shorter the pulse width would be between pulses...

Yes, you can connect another 4017 to divide by 1000, you would have to modify the circuit a bit and move the output of the first and second IC to the last output (Q9), then the output of the 3rd 4017 at Q9 will be the 1000 pulse divisor output....

You can have the PC side application do whatever you want to the data, it is pretty much up to how much work you want to put into it ;).... But, the best way to do it is just store everything in a buffer in ram, and periodically write data to a file, that way the file functions won't interfere with the processing of data.....

Or have the data stored in variables and have it write the output to a file once the user session is done, then it can be manipulated from there and uploaded anywhere you want....

B. Morse
 

Thread Starter

frankpc

Joined Jul 25, 2010
41
the best way to do it is just store everything in a buffer in ram, and periodically write data to a file, that way the file functions won't interfere with the processing of data.....

Or have the data stored in variables and have it write the output to a file once the user session is done, then it can be manipulated from there and uploaded anywhere you want....

B. Morse
Yes. I wondered whether the writing/processing of the file would interfere with the acquiring of the pulses. You mention writing when the user session is done. If the data could be stored in a VB array for perhaps three hours, that would be nice. (I have no idea how big that is, but I suppose if it ran out of RAM, it would just use the hard drive for temporary storage). Perhaps if no pulses were acquired for say... 5 or 10 seconds, VB would know the session was over and do the processing and/or uploading then.

Hmmm... Just thought of a problem: Sometimes I do take a break due to out of water or when I step on the side of the treadmill and get thrown on my face. Not sure how to "join" sessions. If the RAM will tolerate it, perhaps wait until a 5 minute gap is detected before writing/processing. If the divider circuit in the treadmill was powered via the treadmill AC, perhaps the loss of a DSR(?) signal to the PC would indicate the session was complete. Would there be any reason to take advantage of an arrangement such as that for the sole purpose of informing VB to quit polling for pulses? If VB would still have to poll for the presence of the DSR, maybe there wouldn't be any advantage. On the other hand, it would sure be nice to power that circuit from the PC.

Dividing by 1000 would still yield a pulse every .6 seconds at 12 mph.

Perhaps it's time to quit baitin and start fishin.

Fun Project B! Thanks for the guidance.
Frank
 

Thread Starter

frankpc

Joined Jul 25, 2010
41
I have the parts on order. Been trying to access MySQL from Visual Basic. I can't seem to get that to work. It would be nice to just save the pulse information directly to the MySQL database from VB 6.
 
Status
Not open for further replies.
Top