PWM output on a -08M

lr

New Member
I found the "max" command useful to prevent overflow with the b0, and naturally "min" command.
Stu
 

hippy

Ex-Staff (retired)
Thanks Hippy, all 3 work wonderfully, but surprisingly the first listing is the best in terms of least flicker at the absolute dregs of illumination.
Another trick to try is to add "SETFREQ M8" at the start of the program, that may also help.

It would be interesting to see if it's flicker inherent in the hardware-software combo or a result of unstable pot readings re-activating PWMOUT too frequently. If you replace the READADC 4,b0 with b0=x where x is a number when flicker occurs, does flicker stop ? If so it's probably unstable pot readings and re-activating PWMOUT.

A simple cap on the ADC won't necessarily stabilise ADC completely as there will always be a point where any voltage read by READADC can jitter +/-1 as that's the nature of hardware but it is possible to filter that with software.
 

radiogareth

Senior Member
Thanks to all the suggestions, it is really not a problem now and the final nail was setting the speed to M8 - It works fine like that.

The next idea (prompted this afternoon by a pupil asking if he could use touch control) was to try something I used back in 1998 (ish). Using a 4M7 resistor as the input pin pull-up and a couple of touch pads as the push to make switch (your finger). Bingo! It works. Now to rewrite the code to dim up/down on the (touch) pushbuttons :)

The only thing missing is wake up from sleep on port change, but I'd have to revert to mpasm to do that, and I can't remember how!!

Gareth
 

radiogareth

Senior Member
Final code as follows, with bottom end shut off as suggested, at least until it changes again ;-)

setfreq m8
Do
ReadAdc 4, b0
If b0 <> b1 Then
b1 = b0 min 2
if b1=2 then
b1=0
end if
PwmOut 2, 63, b1
End If
Loop
 

radiogareth

Senior Member
Over the weekend I've been thinking how I can add to the functionality of this little project. Many years ago I had a mains powered touch dimmer that responded to the duration of the touch to either turn off, turn on, (change state) dim up or dim down (change direction). It also remembered where you 'left' it brilliance wise.

Anyone any ideas for implementing this on input 3 alone, with a single push button? It's the change direction bit I'm stuck on, and the dim up/down, and remember last level - OK, everything!!

Thanks

Gareth
 

eclectic

Moderator
Over the weekend I've been thinking how I can add to the functionality of this little project. Many years ago I had a mains powered touch dimmer that responded to the duration of the touch to either turn off, turn on, (change state) dim up or dim down (change direction). It also remembered where you 'left' it brilliance wise.

Anyone any ideas for implementing this on input 3 alone, with a single push button? It's the change direction bit I'm stuck on, and the dim up/down, and remember last level - OK, everything!!

Thanks

Gareth
Don't waste your time. :)

Get an 18M2 and start again. :)

e
 

radiogareth

Senior Member
The hardware is fine, it's implementing the store function and actually planning the code structure I have yet to even think about - other work keeps getting in the way.

One day though, one day....

Gareth
 
Top