Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Measuring Voltage signal with C++

Status
Not open for further replies.

Fearful Ferret

New Member
I've got a photo interrupter circuit which switches its output between 0V and 5V based on whether an object is between the arms of the photo interrupter. The signal I'm expecting will be about a 30-80 Hz square wave with 5-10% duty cycle. I need to measure this signal in real-time using C++; specifically, I need to be able to associate each rising edge with a timestamp. I'd rather avoid having to buy an AD converter and just use a port that I can interface with in C++. I've thought about using the sound card's AD converter using a mic port, but I'm not sure if it'll work with such a low frequency signal and I'm not sure how to access the audio information. It's been a while since I've used C++, so try to be specific with help in that regard.

Thanks in advance!
 
C++ is a programming language. It will do whatever you tell it to. It sounds like you are more concerned (at this stage of the project) about the hardware interface. Personally I would do this with a PIC, running assembly language. With a high level language you will loose timing accuracy. If you use assembly, you will be able to determine exactly what your time interval is.

Set up a timer in the PIC to start counting on the rising edge of the input signal and stop on the falling edge. Then just read the timer value out of the micro at teh end of it. With 80Hz input and a 5% duty cycle, this is an ON time of 625us. Even with a 32kHz crystal, this will give you 20 counts. If you increase the clock speed, you will get better accuracy, but will need a larger register in the micro.

That is the way I would go
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top