Need some help from the Pic gods (PWM measurment)

Status
Not open for further replies.

jrz126

Active Member
I need some help...
Im working on this simulator project for work. I need to measure a percentage on signal that is coming out of this one panel. We have a card on the system that can measure the pulse width but we are waiting on the software for it. and we still have another week or so to go.

My plan is to use a PIC (877A PWM capture mode) to measure the 'percent on' of this signal, convert it to an analog value (Via R-R/2 D/A converter) and put that on one of the 'analog in' signals. Then do some conversions in my plant models to get the percentage on.
(It is a 100 Hz signal btw)

Normally I would research this myself, but Im limited on time. I need to measure this signal asap, this is pretty much the only road block Im facing right now.

Anyone ever use this PWM capture before? I would greatly appreciate anyone's help, since I just started learning PICs just alittle bit ago.

Thanks
 
Have you considered using just a simple resistor and capacitor filter?, you can convert the PWM signal directly to a DC voltage in that way. In fact, it's a common technique for getting an analogue voltage out of a micro-controller!.
 
hmm...I didnt know that I could do that.

I'm researching it right now, but how do I go about determining my time constant? It's a 0-5V signal at 100Hz (I could have the voltage go higher if necessary, it uses a pull up resistor to 5 volts.)
 
jrz126 said:
hmm...I didnt know that I could do that.

I'm researching it right now, but how do I go about determining my time constant? It's a 0-5V signal at 100Hz (I could have the voltage go higher if necessary, it uses a pull up resistor to 5 volts.)

It might seem a strange thing to suggest?, but if you look on the MicroChip website there's an application note about doing just this!, actually for converting the PWM output from a PIC to DC.

Try https://www.electro-tech-online.com/custompdfs/2005/09/00538c.pdf for details.

Perhaps this is a first? - I actually advised AGAINST using a PIC!.
 
Ok, I'm still struggling with this problem. I have a card that will sample the signal and calculate the duty cycle for me, but I have no idea how to use it, and the guy that does is pretty busy to help me.

When i used the RC filter that nigel suggested, I was getting some significant ripple in the output. I dont know if it was because the signal is only running at 100Hz? I was thinking about maybe using a PIC to read in the 100Hz signal and up it to a higher freq. pwm then to the RC filter. Does this sound like it would work?
 

Yes it would, but you could simply use the correct filter values in the first place on the 100Hz signal, a correctly filtered PWM D2A should have very low ripple - did you buffer it's output with a high input impedance opamp?.
 
Nigel Goodwin said:
Yes it would, but you could simply use the correct filter values in the first place on the 100Hz signal, a correctly filtered PWM D2A should have very low ripple - did you buffer it's output with a high input impedance opamp?.

No, I didnt have an op amp available at the time. would a LM324 work?
 

Yes, it should be OK, wire it as a non-inverting buffer.
 
Nigel,

May I ask if the RC Integrator I've used in the past (below) is the same as the filter you're describing? I used this circuit to develop a pretty precise analog voltage in 1024 5.0-mv steps from the PIC 10-bit 5-khz PWM output...

I understand that the PWM frequency determines what value capacitors to use... Is this correct?

Regards, Mike
 

Attachments

  • rc_integrator.jpg
    17.9 KB · Views: 713
Mike said:
Nigel,

May I ask if the RC Integrator I've used in the past (below) is the same as the filter you're describing? I used this circuit to develop a pretty precise analog voltage in 1024 5.0-mv steps from the PIC 10-bit 5-khz PWM output...

Yes it is, although that's a double one, commonly used for varactor tuning, where you need exceedingly low ripple.

I understand that the PWM frequency determines what value capacitors to use... Is this correct?

Along with the resistor values yes, it's basically a low-pass filter.

To answer 'jrz126' as well, the MicroChip link I posted earlier gives the calculations required.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…