example code for scaling light intensity for led
mikea
Posts: 283
Are there some examples of scaling leds someone can point me to. I'm trying to scale led intensity with pwm and a counter, from 0-255, 255 being the dimmest and 0 being the brightest. I've been changing some code from the pe kit examples but I cant seem to get it right.
CON _clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz _xinfreq = 5_000_000 PUB TestPwm | tc, tHa, t ,measurement ctra[30..26] := %00100 ' Configure Counter A to NCO ctra[5..0] := 16 frqa := 1 phsa:=0 dira[16]~~ tC := 256 ' Set up cycle and high times measurement:= 150 'psuedo measurement for now tHa := 256-measurement t := cnt ' Mark counter time repeat ' Repeat PWM signal phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) ' Wait for next cycle
Comments