Shop OBEX P1 Docs P2 Docs Learn Events
PWM — Parallax Forums

PWM

alnajjar1alnajjar1 Posts: 110
edited 2010-10-30 16:16 in General Discussion
I have been trying to do a simple circuit where I can read the variable value of a photo-resistor and output a proportional voltage 0-12V with a maximum of 2Amps.

My approach, and I got great help from this group, is to use RCTime to read the photo-resistor, then send a PWM to a TIP120 to output the voltage. Both work great. The problem is that the Stamp cannot do anything while it is taking care of RCTime and PWM. Even while completely dedicated to that task, every time it reads the RCTime, the voltage dips slightly.

I have a simple test routine with the attached circuit:

again:
HIGH 0
RCTIME 0, 1, Vx ' measure RC discharge time
PWM 14, Vx, 50 ' PWM at 100/255 duty (~50 ms)
'DEBUG HOME, DEC ? Vx ' display result
GOTO again

Is there an IC that can do the PWM and the BS2 can talk to via IC2 or Serial? I need a smooth and somewhat accurate voltage out but I also need to free up the Stamp to read switches and turn a few other things on and off while it it is getting the voltage out. I thought of dedicating a BS1 to do the PWM and let the BS2 do everything else while outputting values to the BS1 but that seems to be overly complicated.

Any help?

Thanks,

Al
632 x 588 - 56K
PMW.jpg 55.6K

Comments

  • GadgetmanGadgetman Posts: 2,436
    edited 2010-10-30 13:25
    I believe there are seeral controllers that an be used for this.
    (Do a search for a DA-converter)

    Alternatively, a Propeller has the resources to do both, and more, at the same time.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-30 13:50
    The reason the voltage dips so quickly is that the transistor's not-insubstantial base current discharges the cap. The way around this is to buffer the transistor with an op amp, as I suggested in your other thread:

    The capacitor's charge will hold much longer against the op-amp's high impedance input, giving you the time to take another reading.

    -Phil
  • alnajjar1alnajjar1 Posts: 110
    edited 2010-10-30 16:16
    Great! I have the LM358 on order still but though I can try this shortcut.

    Al
Sign In or Register to comment.