No timing issues at all since I set all the loop times and not relying on system PWM. Here is a code I wrote for simple RGB morphing of one channel. Althought I am using 12 RGB on 12 channels. It is technically one channel RGB. The original code shrunk from 30 pages plus to 2 pages.I understand the schematics, but I didn't understand the operations. Although, it looks like you have plenty of time and don't need to worry about efficiency. I think you could run this from the timer interrupt to free up the main loop for other operations.
One Frame is 12 sets of colors across 12 channels RGB. Repeat one frame over and over and you will have one stationary color sets across 12 RGB going from red to green to blue and all transitions between them. In the code I used 24 Frames to move the color across. 12 Frames for RGB1 to RGB12 and 12 transition Frames to smooth it out.No, thanks. If you can't explain how it works, I'm certainly not going to be able to tell by looking at your source.
list p=16F628A
#include <p16F628A.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT & _LVP_OFF
errorlevel -302 ; supress banksel warning messages during assembly
errorlevel -311 ; supress HIGH operator warning messages during assembly
cblock 0x20
copyPORTA ;Declare variables used in the program
copyPORTB
LoopCount
OutCount
Trans1
Trans2
Color1
Color2
Speed
endc
#define bank0 bcf STATUS,RP0
#define bank1 bsf STATUS,RP0
RESET_VECTOR org 0x000
START
movlw b'00000111' ;Set all ports as outputs
movwf CMCON ;Disable comparators
bank1
clrf TRISA
clrf TRISB
bank0
;-----------------------------------------------------------------------------------------------
; Main Program and Subroutines |
;-----------------------------------------------------------------------------------------------
movlw d'10' ;Range Between 1 to 10
movwf Speed ;Transition Speed 1=Fastest
movlw b'00001111' ;Set Initial Start Color Black
movwf Color1
movlw b'11111111'
movwf copyPORTB
;-----------------------------------------------------------------------------------------------
Sequence
call MorphColors
goto Sequence
;-----------------------------------------------------------------------------------------------
MorphColors
call Red
call Yellow
call Green
call Aqua
call Blue
call Magenta
return
;More color transitions can be added here before "return"
;-----------------------------------------------------------------------------------------------
Red
movlw b'00011111'
call PutColor
return
;-----------------------------------------------------------------------------------------------
Yellow
movlw b'01011111'
call PutColor
return
;-----------------------------------------------------------------------------------------------
Green
movlw b'01001111'
call PutColor
return
;-----------------------------------------------------------------------------------------------
Aqua
movlw b'11001111'
call PutColor
return
;-----------------------------------------------------------------------------------------------
Blue
movlw b'10001111'
call PutColor
return
;-----------------------------------------------------------------------------------------------
Magenta
movlw b'10011111'
call PutColor
return
;-----------------------------------------------------------------------------------------------
White
movlw b'11011111'
call PutColor
return
;-----------------------------------------------------------------------------------------------
Black
movlw b'00001111'
call PutColor
return
;-----------------------------------------------------------------------------------------------
PutColor
movwf Color2
call Morph
movfw Color2
movwf Color1
return
;-----------------------------------------------------------------------------------------------
Morph
movlw d'254'
movwf LoopCount
M1
movfw LoopCount
movwf Trans1
sublw d'255'
movwf Trans2
M2
movfw Color2
movwf copyPORTA
call Output
decfsz Trans2,F
goto M2
M3
movfw Color1
movwf copyPORTA
call Output
decfsz Trans1,F
goto M3
decfsz LoopCount
goto M1
Return
;-----------------------------------------------------------------------------------------------
Output
movfw Speed ;Transition Speed
movwf OutCount ;Placing Delay Will Cause Flicker
Out1
movfw copyPORTA
movwf PORTA
movfw copyPORTB
movwf PORTB
decfsz OutCount
goto Out1
return
;-----------------------------------------------------------------------------------------------
end
I can see it sets all 12 bits to 1, then sets two colors, and changes duty from Color1 to Color2. The Output routine doesn't change anything after setting the initial value, practically acts as a delay.
I don't understand what goal the rotation of bits would accomplish. I understand the light will be faded proportional to the amount of 0s in the 12 bits, but exactly the same effect could be accomplished by simply pulsing all LEDs on and off synchroniously, except with better than 1/12 resolution.
Output
movfw Speed ; Transition Speed
movwf OutCount ; Placing Delay Will Cause Flicker
Out1
movfw copyPORTA
movwf PORTA
movfw copyPORTB
movwf PORTB
decfsz OutCount
goto Out1
return
This code will repeat Output funtions let's say 8 times. Meaning I am placing copyPORTB in PORTB and copyPORTA in PORTA 8 times each time I call Output.If you have time, can you describe what this code is supposed to do, please? Thank you...
Oops! Never mind. A couple posts appeared before I posted my question. I'll read those...
Code:Output movfw Speed ; Transition Speed movwf OutCount ; Placing Delay Will Cause Flicker Out1 movfw copyPORTA movwf PORTA movfw copyPORTB movwf PORTB decfsz OutCount goto Out1 return
Mike let me know if you understand colormorph first. I walk you thru colorrot.Hang on. I'm studying your code (and explanation). Don't think I've ever seen this kind of method before...
North that was the intro to walk you thru ColorRot and how it is implemented. Read my next post which explains ColorRot and its implementation and you see why I needed the Rotations.I look at the code in post #28, and I see that PORTB and 4 low bits of PORTA are always one, and A4, A6, and A7 are used to gradually replace one color with the other during the course of subroute called "Morph".
However, I don't see any connection to the previously discussed rotation task. Am I missing something?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?