That code is completely different from what you originally asked about.
Now you've got Array's involved.
When you get back to the PC, post what you have.
I'll take another look at the "Real" question.
But I still smell spaghetti.
<br>
That code is completely different from what you originally asked about.
Now you've got Array's involved.
When you get back to the PC, post what you have.
I'll take another look at the "Real" question.
But I still smell spaghetti.
<br>
DT
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).
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.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
Soft' PWM for that many outputs is difficult but you might be able to reduce 'overhead' using one of the following assembler methods;
Good luck on your project Sir. Regards, Mike
Code:; ; 6 bit (single port), 256 step, 20 cycles (isochronous) for 16F ; movf led+5,W ; led[5] duty cycle, 0..255 |B0 subwf dcy,W ; C = led[5] >= dcy |B0 rlf shadow,F ; |B0 movf led+4,W ; led[4] duty cycle, 0..255 |B0 subwf dcy,W ; C = led[4] >= dcy |B0 rlf shadow,F ; |B0 movf led+3,W ; led[3] duty cycle, 0..255 |B0 subwf dcy,W ; C = led[3] >= dcy |B0 rlf shadow,F ; |B0 movf led+2,W ; led[2] duty cycle, 0..255 |B0 subwf dcy,W ; C = led[2] >= dcy |B0 rrf shadow,F ; |B0 movf led+1,W ; led[1] duty cycle, 0..255 |B0 subwf dcy,W ; C = led[1] >= dcy |B0 rlf shadow,F ; |B0 movf led+0,W ; led[0] duty cycle, 0..255 |B0 subwf dcy,W ; C = led[0] >= dcy |B0 rlf shadow,F ; |B0 xorlw 0xFF ; for active hi outputs |B0 movwf PORTB ; update LEDs |B0 ; ; bump duty cycle counter ; movlw b'00111111' ; just in case |B0 incf dcy,F ; bump duty cycle counter |B0 skpnz ; end-of-period? no, skip, else |B0 movwf shadow ; reset shadow |B0Code:; ; 6 bit (single port), 256 step, 15 cycles (isochronous) for 18F ; movf dcy,W ; duty cycle counter, 0..255 cpfsgt Led+0 ; if(Led[0] >= dcy) bcf Shadow,0 ; Shadow.0 = 0 cpfsgt Led+1 ; if(Led[1] >= dcy) bcf Shadow,1 ; Shadow.1 = 0 cpfsgt Led+2 ; bcf Shadow,2 ; cpfsgt Led+3 ; bcf Shadow,3 ; cpfsgt Led+4 ; bcf Shadow,4 ; cpfsgt Led+5 ; bcf Shadow,5 ; movff Shadow,LATB ; ; ; bump duty cycle counter ; movlw b'00111111' ; just in case infsnz dcy,F ; if end-of-period movwf Shadow ; reset shadow
Ive been trying to get my head round this ASM code. Mike's ASM seems to do almost exactly what i want but i just want to clarify things as im completely new to ASM.
Is W some kind of temp byte? It appears that ASM compare commands only accept 1 input and that is always compared with W.
Ive read the part in the datasheet about CPFSGT. It says "Compare f with W, skip if f > W". I assume this means skip the following line of code
BCF looks pretty obvious. What is "Shadow" though? Is that a predefined variable of some kind or does it need declaring anywhere?
Yes, W is the Accumulator on which almost all operations are performed.Is W some kind of temp byte? It appears that ASM compare commands only accept 1 input and that is always compared with W.
Yes, shadow is a byte sized variable which holds a copy of the actual bits which turn on/off the leds attached to PORTB. It has to be declared like thisWhat is "Shadow" though? Is that a predefined variable of some kind or does it need declaring anywhere?
Code:shadow: var byte
So "LATB" is the ASM version of PORTB?
Is Shadow just a normal variable then? So i could call it LATBTemp if i wanted?
Is there a reason i would use Shadow instead of performing the operations directly on LATB?
Bookmarks