With an A/D input > 0V you will always have a pulseout "period" > 0. Grounding the A/D input should stop the output pulse.
With an A/D input > 0V you will always have a pulseout "period" > 0. Grounding the A/D input should stop the output pulse.
I think you missunderstood something, the 12f675 hasnīt got a Hardware PWM, so I want to emulate it in Software! And my Problem is that I could not put the output permanently on, between 0 an 100% der must be pulses, but on 0% the output should have ground signal (thats working) and on 100% the output should have high signal, and thats the problem, it isnīt a countinously line it should be!
If you can change your PIC, use the 12F683. It have an internal PWM module.Code:loop: ADCIN 3, adval ' Read channel 3 to adval if adval<250 then i = 256 - adval I = i * 10 Pulsout LED,adval ' Puls is 2,56 ms Pauseus i 'cycle = 5,12ms = 195 Hz else high led endif Goto loop ' Do it forever
Last edited by mister_e; - 27th November 2005 at 19:58.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
If you *REALLY* need smooth PWM out of your chip, it is possible.
One approach would be to set up a hardware timer to give you a constant period (say 100uSec), and then use an interleave-type A/D routine. You could do the conversions (and the math) on consecutive timer rollovers.
Using this technique you could get 8 bits of resolution and 0 to 100% duty cycle at 40Hz. Not great, but possibly usable.
Charles Linquist
Hi,
(OK, just an idea here - worth a try)
With the AD result set to 8 bits your result will vary from 0 to 255. Try changing the line:
toCode:i = 256 - adval
and see what happends. Even at full scale (adval=255) your i variable will be 10 if you subtract adval from 256. You will probably still get short glitches but hopefully you will end up closer to what you want.Code:i = 255 - adval
/Henrik Olsson.
Bookmarks