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.

can you reliably read in PWM with an A/D converter?

Status
Not open for further replies.

dazzlepecs

New Member
I wish to read in the angle from a magnetic compass device


It has a PWM output ( **broken link removed** if anyone is interested)

Could i simply feed this into an A/D converter for a semi-reliable voltage, voltage being proportional to the angle?? I am not sure if the A/D converter is SA or whatever other methods



thanks for any help
 
Last edited:
I dont think an ADC can read a PWM, it's just Hi-Lo with varying width. The ADC can read voltage steps at certain resolution. If your using MCU, some micro has IOC (input capture, output compare) which can read PWM signals. I don't know if there are stand-alone devices for this.
 
You could read the average analog value of the PWM output through a low-pass filter, but since the angle is represented by a varying high pulse width and a fixed low pulse width, the analog value will be a non-linear function of angle and there will be errors in the angle readout, particularly at low angle values.

But converting the signal to analog and then back to digital doesn't make any sense since the signal is already available in a convenient digital form. Simply read the value in registers 1, or 2&3 in the module, through the IC2 interface with a microprocessor. These registers contain digital words representing the angle.
 
I dont think an ADC can read a PWM, it's just Hi-Lo with varying width. The ADC can read voltage steps at certain resolution. If your using MCU, some micro has IOC (input capture, output compare) which can read PWM signals. I don't know if there are stand-alone devices for this.

Im using a USB experiment board and it doesnt have that functionality

If it's a PWM output, just measure the width of the pulses - use the CCP module.

Its for uni and i dont have any more budget lol.. Im not too familiar with them either unfortunately

You could read the average analog value of the PWM output through a low-pass filter, but since the angle is represented by a varying high pulse width and a fixed low pulse width, the analog value will be a non-linear function of angle and there will be errors in the angle readout, particularly at low angle values.

But converting the signal to analog and then back to digital doesn't make any sense since the signal is already available in a convenient digital form. Simply read the value in registers 1, or 2&3 in the module, through the IC2 interface with a microprocessor. These registers contain digital words representing the angle.

How big are the errors? To be honest even if its quite off i can make do, its really just for demonstrative purposes for a sketchy sonar sweep.. I have a pulse-counter on the USB board perhaps i can use that.. Anything cheap N nasty to figure out what way a robot is pointing





thanks all for tips!
 
Last edited:
How big are the errors? To be honest even if its quite off i can make do, its really just for demonstrative purposes for a sketchy sonar sweep.. I have a pulse-counter on the USB board perhaps i can use that.. Anything cheap N nasty to figure out what way a robot is pointing
The error is about ±20% from a best straight line.

A more accurate way would be to measure the pulse count or period, if you can. The frequency varies from 15.15pps (66ms period) at 0 degrees to 9.80pps (102ms period) at 359.9 degrees.
 
The PWM output is only at 50/60 Hz and so converting to a DC voltage will be slow and error prone. Reading it in on a pin should be very simple at that speed and easily timed in software. Alternatively, that module has I2C, why not just use that?

Mike.
 
The error is about ±20% from a best straight line.

A more accurate way would be to measure the pulse count or period, if you can. The frequency varies from 15.15pps (66ms period) at 0 degrees to 9.80pps (102ms period) at 359.9 degrees.

I have a pulsecounter on the USB experiment board, i guess i could check it after 102ms and count them


The PWM output is only at 50/60 Hz and so converting to a DC voltage will be slow and error prone. Reading it in on a pin should be very simple at that speed and easily timed in software. Alternatively, that module has I2C, why not just use that?

Mike.


i dont really know how to go about that with this USB board im working with (k8055).. And calling the inputs/outputs is very slow on that device, the pulse-counter is the fastest thing ive got



I keep hearing about Ic2, i have never heard of them till now :eek: i would love to learn about them but i dont have much time left with this project to incorporate something new

thanks both for tips!
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top