The code i posted originally is what ive been using to test how many instruction cycles things take. I have 4 sockets (A to D) on this board each with 6 outputs (1 to 6).
Code:
'Define output pins
pA1 VAR PORTB.1
pA2 VAR PORTB.2
pA3 VAR PORTB.0
'etc...
'Then further down inside the TMR0 interrupt
'Is the vPWMPos equal to 0?
IF vPWMPos=0 THEN
'Turn off any outputs that are less than 255
IF vPWM[0]<255 THEN pA1=0
IF vPWM[1]<255 THEN pA2=0
IF vPWM[2]<255 THEN pA3=0
'etc...
ELSE
'If vPWMPos is less than any of the chanels then turn those chanels on
IF vPWMPos=vPWM[0] THEN pA1=1
IF vPWMPos=vPWM[1] THEN pA2=1
IF vPWMPos=vPWM[2] THEN pA3=1
'etc...
ENDIF
'Decrement the PWM counter
vPWMPos=vPWMPos-1
There doesnt have to be an array involved. I just used that to make other parts of the code a little easier. I could create a bunch of variables named vPWM0, vPWM1 etc instead. The important part is reducing the number of instructions an if statement uses or not using an if statement at all.
Bookmarks