code problem
The following will ramp up a led until i added the "repeat while ina[1]==1. I,ve spent a lot of time and i'm still stumped. In the future i want 2 buttons to ramp up/down a dc motor, but i'm stuck here. thanks for any help.-mike
CON
_clkmode = xtal1 + pll16x ' System clock → 80 MHz
_xinfreq = 5_000_000
PUB TestPwm | tC, tHa, t
ctra[30..26] := %00100 ' Configure Counter A to NCO
ctra[5..0] := 4
frqa := 1
dira[4]~~ 'pin for led
dira[1]~
tHa:=1
tC := 10000 ' Set up cycle and high times
t := cnt ' Mark counter time
repeat
repeat while ina[1]==1 'pushbutton held down
phsa := -tHa ' Set up the pulse
++tHa
t += tC ' Calculate next cycle repeat
waitcnt(t) ' Wait for next cycle

Comments
CON _clkmode = xtal1 + pll16x ' System clock → 80 MHz _xinfreq = 5_000_000 UP = 1 'button pins DOWN = 2 SPEED = 1 '1=slow .. ~100=fast PUB TestPwm | tC, tHa, t ctra[30..26] := %00100 ' Configure Counter A to NCO ctra[5..0] := 4 frqa := 1 dira[4]~~ 'pin for led = output tHa:=1 tC := 10000 ' Set up cycle and high times t := cnt ' Mark counter time repeat phsa := -tHa ' Set up the pulse if ina[UP]==1 and tHa < 10000 tHa += SPEED if ina[DOWN]==1 and tHa > 0 tHa -= SPEED t += tC ' Calculate next cycle repeat waitcnt(t) ' Wait for next cycle 'Andy