ctra and ctrb
Hi, I'm trying to scale 2 of the 3 pins of an rgb led with ctra, and ctrb. I have code that works from the pe kit for ctra in the first 255 to 0 loop which works great except pin 5 (ctrb is always on). The second loop for pin 5 using ctrb results in both pins 4 and 5 on, but no scaling. I was trying to scale them one at a time. I've read the section of the prop manual about counters, but not sure where I'm going wrong. It looks like for the third led I need to open a new cog for more counters. Thanks
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
''LedDutySweep.spin
''Cycle P4 LED from off, gradually brighter, full brightness.
scale = 16_777_216 ' 2³²÷ 256
PUB TestDuty | pin, duty, mode
'Configure counter module.
ctra[30..26] := %00110 ' Set ctra to DUTY mode
ctra[5..0] := 4 ' Set ctra's APIN
frqa := duty * scale ' Set frqa register
ctrb[30..26] := %00110
ctrb[14..9]:=5
frqb := duty * scale
Use counter to take LED from off to gradually brighter, repeating at 2 Hz.
dira[4..5]~~ ' Set P5,4 to output
repeat ' Repeat indefinitely
repeat duty from 255 to 0 ' Sweep duty from 0 to 255
frqa := duty * scale ' Update frqa register
waitcnt(clkfreq/128 + cnt) ' Delay for 1/128th s
repeat duty from 255 to 0
frqb := duty * scale
waitcnt(clkfreq/128 + cnt)

Comments
Do you have the outputs connected directly to the LED? I tested this using a generic red LED and it worked, though the brightness seemed to change rather abruptly in a few places. Using a low-pass filter to create a digital-to-analog converter resulted in a much smoother transition, though the range was also reduced somewhat.
If you have a cog to spare, here's a very simple embedded RGB LED controller. Paste this into your program and then call start_rgb() with your pins.
var long rgbcog long rgbstack[16] long red long green long blue pri start_rgb(rpin, gpin, bpin) if (rgbcog) cogstop(rgbcog - 1) rgbcog := cognew(run_rgb(rpin, gpin, bpin), @rgbstack) + 1 pri run_rgb(rpin, gpin, bpin) | racc, gacc, bacc dira[rpin] := 1 dira[gpin] := 1 dira[bpin] := 1 repeat racc += red ' update accumlator outa[rpin] := (racc > 255) ' move carry to output racc &= $FF ' clear carry gacc += green outa[gpin] := (gacc > 255) gacc &= $FF bacc += blue outa[bpin] := (bacc > 255) bacc &= $FF