Well, the basics are there (as you well know)...
And the 48 channels...I'll post some differences:
18F8722 vs. 16F628A
40Mhz vs. 20Mhz
Timer 0 prescale is 1:2 instead of 1:1, thereby keeping the same 76Hz Freq of PWM...
...got 512 cycles to work with instead of 256. 48 channels in 512 cycles = 10 cycles per channel with even some extra leftover.
Code is practically the same, except:
PWM 0-7 on PortB (along with PGC/PGD/PGM, LVP disabled)
PWM 8-15 on PortD (serial comm's on PortC, along with a couple of buttons)
PWM 16-23 on PortE
PWM 24-31 on PortF
PWM 32-39 on PortH
PWM 40-47 on PortJ
The rest of the pins are either used for buttons, indicators, or whatever, the usual crap.
At first I had a heck of a time finding enough cycles to run everything thru the interrupt loop and not miss any interrupts, that's when I figured out to keep all of the PWM channels in blocks of 8, byte writes to each port instead of bit writes saved just enough time to make it work reliably and leave a bit of time leftover to actually have a MAINLOOP to do other things. There's a few other shortcuts in the interrupt loop, such as checking the high bit of each DCR instead of checking the whole thing when doing the comparisons. That's one of the places where the PWM jitters a bit (I never said it was a ROCK SOLID 48 channels!). If too many of the channels have to take the jump where it sets or resets the pin, the PWM for all of them hiccups a bit. Worst case scenario is when all DCRs for each channel are exactly the same, they all have to take the jump to reset the pins. But if they're spread out, it's not bad at all. I can even trace it on the 'scope and only get a couple of us of jitter.
THERE! Now everybody knows all of my secrets!
You know, come to think of it...this might be one of those things just would go good with that little 'code optimization' exercise that went on awhile back.
Get an '8722 to use every available pin for software driven PWM'ing of LEDs, while using the serial port for control at high speed, and still have solid PWM.
Bookmarks