Shop OBEX P1 Docs P2 Docs Learn Events
example code for scaling light intensity for led — Parallax Forums

example code for scaling light intensity for led

mikeamikea Posts: 283
edited 2014-03-11 12:06 in Propeller 1
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

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2014-03-11 11:07
    You'll need a much longer cycle and high time. 256 clock cycles is faster than the execution time of a Spin instruction. 256 * 12.5ns = 3.2 µs. Try 256000 and 150000 to make your cycle time 3.2ms, still well below flicker fusion.
  • mikeamikea Posts: 283
    edited 2014-03-11 12:06
    Thank you Tracy, I can work with it now.
Sign In or Register to comment.