Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F628A Rotate Left Thru Carry & Loop Around

Status
Not open for further replies.
I just finished restructuring A12-Fix3Color.asm so that it made more sense (to me) and son-of-a-gun if it doesn't resemble your flowchart (lol)...

This is a pretty novel approach that deserves closer study. Darn it... You're distracting me from a couple other projects I really should be working on (a CDP1802 single board computer and a microcontroller based German Enigma machine)...

Cheerful regards, Mike

Code:
        list p=16F628A, st=off
        #include <p16F628A.inc>

 __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT & _LVP_OFF

    errorlevel -302,-311,-202

        cblock  0x20
Color1                          ;
Color2                          ;
Color3                          ;
speed                           ;
        endc

#define bank0   bcf     STATUS,RP0
#define bank1   bsf     STATUS,RP0

;==================================================================
;
rainbow macro   c1,c2,c3        ; three 4-bit color values
        movlw   c1<<4           ;                                 |00
        movwf   Color1          ;                                 |00
        movlw   c2<<4           ;                                 |00
        movwf   Color2          ;                                 |00
        movlw   c3<<4           ;                                 |00
        movwf   Color3          ;                                 |00
        call    frame1          ;                                 |00
        endm

;==================================================================
;
display macro   color,pattern
        movf    color,W         ; color bits in b7..b4            |00
        addlw   pattern/256     ; add column b11..b8 bits         |00
        movwf   PORTA           ;                                 |00
        movlw   pattern%256     ; the column b7..b0 bits          |00
        movwf   PORTB           ;                                 |00
        endm

;******************************************************************
;  main init (reset vector)                                       *
;******************************************************************
        org     0x000
start
        clrf    STATUS          ; bank 0                          |00
        movlw   b'00000111'     ; Set all ports as outputs        |00
        movwf   CMCON           ; Disable comparators             |00
        bank1                   ;                                 |01
        clrf    TRISA           ;                                 |01
        clrf    TRISB           ;                                 |01
        bank0                   ;                                 |00

;******************************************************************
;  main loop                                                      *
;******************************************************************

Sequence
        call    MegaColor       ; ????                            |00
        goto    Sequence        ;                                 |00
;
;  each animation has 24 frames over 12 chan RGB for total of 24
;  color bit resolution (producing vivid colors).  refresh rate
;  of 500 cycles to prevent flickering.
;
MegaColor
        rainbow b'0001',b'0100',b'1000'
        rainbow b'0001',b'0100',b'1000'
        rainbow b'0001',b'0100',b'1000'
        rainbow b'0001',b'1101',b'1001'
        rainbow b'0101',b'0001',b'0101'
        rainbow b'0001',b'0101',b'0001'
        rainbow b'0001',b'0101',b'1001'
        rainbow b'0001',b'0101',b'0100'
        rainbow b'0001',b'0100',b'1000'
        rainbow b'1001',b'1101',b'0100'
        rainbow b'1000',b'1101',b'0001'
        rainbow b'0001',b'1101',b'0100'
        rainbow b'0100',b'1101',b'1000'
        return                  ;                                 |00

frame1
        movlw   500             ;  <-- this ain't gonna work...  oops!
        movwf   speed           ;                                 |00
frloop
        display Color1,b'111000001111'
        display Color1,b'110000000111'
        display Color1,b'100000000011'
        display Color1,b'000000000001'

        display Color3,b'000011111110'
        display Color3,b'000001111100'
        display Color3,b'000000111000'
        display Color3,b'000000010000'

        display Color2,b'111111100000'
        display Color2,b'011111000000'
        display Color2,b'001110000000'
        display Color2,b'000100000000'

        decfsz  speed,F         ; done? yes, skip, else           |00
        goto    frloop          ; branch (repeat frame)           |00
        return

;==================================================================
        end

<added>
insert "radix dec" at the top of program and fix the delay/repeat value (0..255).
Code:
        list p=16F628A, st=off
        #include <p16F628A.inc>

 __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT & _LVP_OFF

    errorlevel -302,-311,-202
    radix dec
 
Last edited:
I just finished restructuring A12-Fix3Color.asm so that it made more sense (to me) and son-of-a-gun if it doesn't resemble your flowchart (lol)...

This is a pretty novel approach that deserves closer study. Darn it... You're distracting me from a couple other projects I really should be working on (a CDP1802 single board computer and a microcontroller based German Enigma machine)...
Now I need a translation of your work.
If I understand your code, then I might be able to help you implement the code for the entire ColorRot. (All 12 frames and transitions between them)
Regards,
Rom

P.S.: You are working on Enigma for real? I love decoding! I see the world in codes.
 
The code is strobing. You need to increase your section count and decrease your frame count. This usally happens when the colors do not have enough time to set before the next refresh comes in. In my code I did Section Count of 50 and Frame Count of 10 and there is no flickering at all. (very steady)

It is showing as rapid fire R,G,B,W. Also your pin12 (A3) is completely turn off and stays off.
 
P.S.: You are working on Enigma for real? I love decoding!
Yes, I'm experimenting with software for a PIC based version of an Enigma machine. No hardware, yet, but it will probably have 26 keys (input), 26 LEDs (output), and four 5x7 displays and some push buttons for rotor and ring settings, and I think it will use a 20-pin PIC, three serial-to-parallel driver ICs of some sort, and eight transistor drivers. Not sure how I will do the plugboard.
I see the world in codes.
I was wondering if your explanations were in code (lol) but I realize you have an exotic design that's just difficult (for me) to understand.

I ordered a handful of inexpensive Chinese RGB LEDs after seeing the Aurora-12 from TheLedArtist some months ago. I guess it's time to stuff some into a solderless breadboard and start playing...

Cheerful regards, Mike
 
I added counts for sections and increased your frame count as well. Frame count= 1000=speed, Section count=5000=speed2
This stabilized the flickering. But the color transitions are off and A3 is still not turning on. Something tells me that perhaps part of your colors are overriding the data arrays. Just a wild guess.

Code:
 frame1
         movlw   1000             ;  <-- this ain't gonna work...  oops!
         movwf   speed           ;                                 |00
frloop
    movlw    5000
    movwf    speed2
S1
         display Color1,b'111000001111'
         display Color1,b'110000000111'
         display Color1,b'100000000011'
         display Color1,b'000000000001'
    decfsz    speed2
    goto    S1
    movlw    5000
    movwf    speed2
S2
         display Color2,b'000011111110'
         display Color2,b'000001111100'
         display Color2,b'000000111000'
         display Color2,b'000000010000'
    decfsz    speed2
    goto    S2
    movlw    5000
    movwf    speed2
S3
         display Color3,b'111111100000'
         display Color3,b'011111000000'
         display Color3,b'001110000000'
         display Color3,b'000100000000'
    decfsz    speed2
    goto    S3
        decfsz  speed,F         ; done? yes, skip, else           |00
        goto    frloop               ; branch (repeat frame)           |00
        return
 
I commented out all other colors in MegaColor except the first set to be: 0001=red, 0100=green, 1000=blue
Here are the pins and output colors under them as they appear.
A3------A2------A1---------A0------------B7--------B6------B5----------B4------------B3---------B2-------------B1-----------B0
Off Pink Magenta Magenta Aqua+Blue White Teal Green+White White Aqua+Blue Purple+White Pure Red
This is what it should be
Pink Magenta Purple Blue Aqua+Blue Aqua Teal Green Green+Yel Yellow Orange Red
 
A couple problems with the code I posted... I forgot to put "radix dec" up at the top, and you can only use values of 0..255 in an 8-bit variable. Sorry!

Also spotted what I think is a mistake in your original A12-Fix3Color.asm program;

Code:
Frame1                            ;Each section modulates R,G,B
        movfw    d'10'            ;Speed Control. Smaller number faster transitions
        movwf    FrameCount

Shouldn't that be a movlw d'10' instruction?
 
Last edited:
A couple problems with the code I posted... I forgot to put "radix dec" up at the top, and you can only use values of 0..255 in an 8-bit variable. Sorry!
Also spotted what I think is a mistake in your original A12-Fix3Color.asm program;
Code:
Frame1                            ;Each section modulates R,G,B
        movfw    d'10'            ;Speed Control. Smaller number faster transitions
        movwf    FrameCount
Shouldn't that be a movlw d'10' instruction?
Good catch, that is correct. In the original program (ColorRot) since I was dealing with 12 Frames and 12 Sections and they werre long, I had variables Speed and Speed2 for loop counts so that I did not have to go thru the entire code to reset the loop counts for desired effect. Since I used variables instead of numbers then the correct code would have been 'mowfw Speed'. When I tried to simplify the code to just one frame I forgot to change that to (movlw d'10'). With that change colors started flicker and I had to increase Section count to d'100' and Frame count to d'160'. The code in previous post has been re-posted to the correct version now.
 
Mike can you kindly update your code in your last post of A12-Fix3Color. What does radix dec do?
Also I noticed in your code, the very first line, you have list p=16F628, st=off. What is 'st=off' and is it necessary?
I still think you need to refresh your sections so that your 4-lines of rapid fire is repeated and hence colors are set (do not flicker).
 
Last edited:
Mike can you kindly update your code in your last post of A12-Fix3Color. What does radix dec do?
I still think you need to refresh your sections so that your 4-lines of rapid fire is repeated and hence colors are set (do not flicker).

The radix directive sets the default radix for numeric expressions. Basically once you set radix to decimal you don't have to specify decimal number with as .10 or d'10'.

Here's my current A12-Fix3Color.asm source;

Code:
;******************************************************************
;  A12-Fix3Color.asm (Mike's version of Rom's program, 09/29/14)  *
;******************************************************************

        list p=16F628A,st=off
        #include <p16F628A.inc>

 __CONFIG _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT & _LVP_OFF

        errorlevel -302,-311,-202
        radix dec

        cblock  0x20
Color1                          ;
Color2                          ;
Color3                          ;
speed                           ;
repeat                          ;
        endc

#define bank0   bcf     STATUS,RP0
#define bank1   bsf     STATUS,RP0

;==================================================================
;
rainbow macro   c1,c2,c3        ; three 4-bit color values
        movlw   c1<<4           ;                                 |00
        movwf   Color1          ;                                 |00
        movlw   c2<<4           ;                                 |00
        movwf   Color2          ;                                 |00
        movlw   c3<<4           ;                                 |00
        movwf   Color3          ;                                 |00
        call    frame1          ;                                 |00
        endm

;==================================================================
;
display macro   color,pattern
        movf    color,W         ; color bits in b7..b4            |00
        addlw   pattern/256     ; add column b11..b8 bits         |00
        movwf   PORTA           ;                                 |00
        movlw   pattern%256     ; the column b7..b0 bits          |00
        movwf   PORTB           ;                                 |00
        endm

;******************************************************************
;  main init (reset vector)                                       *
;******************************************************************
        org     0x000
start
        clrf    STATUS          ; bank 0                          |00
        movlw   b'00000111'     ; Set all ports as outputs        |00
        movwf   CMCON           ; Disable comparators             |00
        bank1                   ;                                 |01
        clrf    TRISA           ;                                 |01
        clrf    TRISB           ;                                 |01
        bank0                   ;                                 |00

;******************************************************************
;  main loop                                                      *
;******************************************************************
;
;  each animation has 24 frames over 12 chan RGB for total of 24
;  color bit resolution (producing vivid colors).  refresh rate
;  of 500 cycles to prevent flickering.
;

Sequence
        call    MegaColor       ; ????                            |00
        goto    Sequence        ;                                 |00

;******************************************************************
;  subroutines                                                    *
;******************************************************************

MegaColor
        rainbow b'0001',b'0100',b'1000'
        rainbow b'0001',b'0100',b'1000'
        rainbow b'0001',b'0100',b'1000'
        rainbow b'0001',b'1101',b'1001'
        rainbow b'0101',b'0001',b'0101'
        rainbow b'0001',b'0101',b'0001'
        rainbow b'0001',b'0101',b'1001'
        rainbow b'0001',b'0101',b'0100'
        rainbow b'0001',b'0100',b'1000'
        rainbow b'1001',b'1101',b'0100'
        rainbow b'1000',b'1101',b'0001'
        rainbow b'0001',b'1101',b'0100'
        rainbow b'0100',b'1101',b'1000'
        return                  ;                                 |00

;******************************************************************
;
frame1
        movlw   160             ;                                 |00
        movwf   speed           ;                                 |00
frloop
        movlw   100             ;                                 |00
        movwf   repeat          ;                                 |00
s1
        display Color1,b'111000001111' 
        display Color1,b'110000000111' 
        display Color1,b'100000000011' 
        display Color1,b'000000000001' 
        decfsz  repeat,F        ;                                 |00
        goto    s1              ;                                 |00
        movlw   100             ;                                 |00
        movwf   repeat          ;                                 |00
s2
        display Color3,b'000011111110' 
        display Color3,b'000001111100' 
        display Color3,b'000000111000' 
        display Color3,b'000000010000' 
        decfsz  repeat,F        ;                                 |00
        goto    s2              ;                                 |00
        movlw   100             ;                                 |00
        movwf   repeat          ;                                 |00
s3
        display Color2,b'111111100000' 
        display Color2,b'011111000000' 
        display Color2,b'001110000000' 
        display Color2,b'000100000000' 
        decfsz  repeat,F        ;                                 |00
        goto    s3              ;                                 |00

        decfsz  speed,F         ; done? yes, skip, else           |00
        goto    frloop          ; branch (repeat frame)           |00
        return

;==================================================================
        end
 
I modified your last code with added radix. I added the loops for sections. Then added d'180' for your frame count, and 100 for section count and that did the trick to get rid of flicker and to light up A3.
Now your output is identical to mine.
I spent some time on your code to understand display macro and it is rather clever and in minimum steps required.

Code:
        list p=16F628A, st=off
         #include <p16F628A.inc>
 
  __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT & _LVP_OFF
 
     errorlevel -302,-311,-200
     radix   dec
 
         cblock  0x20
Color1                          ;
Color2                          ;
Color3                          ;
speed                           ;
speed2
         endc
 
#define bank0   bcf     STATUS,RP0
#define bank1   bsf     STATUS,RP0
 
;==================================================================
;
rainbow macro   c1,c2,c3        ; three 4-bit color values
         movlw   c1<<4           ;                                 |00
         movwf   Color1          ;                                 |00
         movlw   c2<<4           ;                                 |00
         movwf   Color2          ;                                 |00
         movlw   c3<<4           ;                                 |00
         movwf   Color3          ;                                 |00
         call    frame1          ;                                 |00
         endm
 
;==================================================================
;
display macro   color,pattern
         movf    color,W         ; color bits in b7..b4            |00
         addlw   pattern/256     ; add column b11..b8 bits         |00
         movwf   PORTA           ;                                 |00
         movlw   pattern%256     ; the column b7..b0 bits          |00
         movwf   PORTB           ;                                 |00
         endm
 
;******************************************************************
;  main init (reset vector)                                       *
;******************************************************************
         org     0x000
start
         clrf    STATUS          ; bank 0                          |00
         movlw   b'00000111'     ; Set all ports as outputs        |00
         movwf   CMCON           ; Disable comparators             |00
         bank1                   ;                                 |01
         clrf    TRISA           ;                                 |01
         clrf    TRISB           ;                                 |01
         bank0                   ;                                 |00
 
;******************************************************************
;  main loop                                                      *
;******************************************************************
 
Sequence
         call    MegaColor       ; ????                            |00
         goto    Sequence        ;                                 |00
;
;  each animation has 24 frames over 12 chan RGB for total of 24
;  color bit resolution (producing vivid colors).  refresh rate
;  of 500 cycles to prevent flickering.
;
MegaColor
         rainbow b'0001',b'0100',b'1000'
         rainbow b'0001',b'0100',b'1000'
         rainbow b'0001',b'0100',b'1000'
         rainbow b'0001',b'1101',b'1001'
         rainbow b'0101',b'0001',b'0101'
         rainbow b'0001',b'0101',b'0001'
         rainbow b'0001',b'0101',b'1001'
         rainbow b'0001',b'0101',b'0100'
         rainbow b'0001',b'0100',b'1000'
         rainbow b'1001',b'1101',b'0100'
         rainbow b'1000',b'1101',b'0001'
         rainbow b'0001',b'1101',b'0100'
         rainbow b'0100',b'1101',b'1000'
         return                  ;                                 |00
 
frame1
         movlw   d'180'             ;  <-- this ain't gonna work...  oops!
         movwf   speed           ;                                 |00
frloop
    movlw    d'100'
    movwf    speed2
S1
         display Color1,b'111000001111'
         display Color1,b'110000000111'
         display Color1,b'100000000011'
         display Color1,b'000000000001'
    decfsz    speed2
    goto    S1
;
    movlw    d'100'
    movwf    speed2
S2
         display Color3,b'000011111110'
         display Color3,b'000001111100'
         display Color3,b'000000111000'
         display Color3,b'000000010000'
    decfsz    speed2
    goto    S2
;
    movlw    d'100'
    movwf    speed2
S3
         display Color2,b'111111100000'
         display Color2,b'011111000000'
         display Color2,b'001110000000'
         display Color2,b'000100000000'
    decfsz    speed2
    goto    S3
;
         decfsz  speed,F         ; done? yes, skip, else           |00
         goto    frloop          ; branch (repeat frame)           |00
         return
 
;==================================================================
         end
 
Hey Rom,

I spotted what I think may be a problem. Just not sure how it affects overall operation.

It seems you want to light certain LEDs using a certain color for 1, 2, 3, or 4 intervals. I would think those intervals should be the same length but they're not. There's actually quite a bit of "jitter" for the last interval in each "section" due to the loop instructions for each section and between sections. Worse, there is a two cycle lag between updating PORTA and PORTB. This becomes a problem when moving from one section to the next section because the 'old' PORTB pattern bits will display the 'new' color for two cycles until PORTB is updated with 'new' pattern bits. Again, I'm not sure how this affects color generation.

Now I'm looking at modifying the code to use Bit Angle Modulation (BAM) which should eliminate "jitter" and provide more precise color control. I believe Pete (geko) did something like this in one of his LED products.

Code:
frame1
        movlw   160             ;                                 |00
        movwf   speed           ;                                 |00
frloop
        bamdisp 100, color1, 3,2,1,0,0,0,0,0,1,2,3,4
        bamdisp 100, color3, 0,0,0,0,1,2,3,4,3,2,1,0
        bamdisp 100, color2, 1,2,3,4,3,2,1,0,0,0,0,0

        decfsz  speed,F         ; done? yes, skip, else           |00
        goto    frloop          ; branch (repeat frame)           |00
        return
There's actually seven brightness levels with 3-bit BAM (eight levels if you include black) so I can use gamma corrected duty cycle values of 0-7.
 
Last edited:
Hey Rom,
It seems you want to light certain LEDs using a certain color for 1, 2, 3, or 4 intervals. I would think those intervals should be the same length but they're not. There's actually quite a bit of "jitter" for the last interval in each "section" due to the loop instructions for each section and between sections. Worse, there is a two cycle lag between updating PORTA and PORTB. This becomes a problem when moving from one section to the next section because the 'old' PORTB pattern bits will display the 'new' color for two cycles until PORTB is updated with 'new' pattern bits. Again, I'm not sure how this affects color generation.
QUOTE]
Mike: Regarding color spread across 12 channels, my outputs are even. I had to fine-tune my resistors a bit for RGB color balance. (even at that I cannot compensate for difference in manufacturing bins). At 180 cycle for Frame and 100 for Sections, I do not see any jitters at all. If you see any jitters, then increase your frame count. Regarding lag, I believe you are reffering to adding color and then pushing out to PORTA vs. just pushing bits to PORTB (correct?). The difference is so little that it would not matter going from one entire frame to the next. A guess at this point. I have to see the entire program cycle thru in its entirety.

Warm Regards,
Rom
 
I just thought of something interesting that might simplify the whole prgram. We already created the wave form for 3 triangles. Why can't we just rotate colors superimposed on those triangles. Grab our bits from frame1, grab 3 input primary colors "Morph" them from first color to second, second to third, third to first in however many steps to set the colors. I am thinking 36 steps. This eliminates the need for multiple macros for 12 diffent frames and also goes straight to morphing from one frame to the next. I will work on it a bit and post results.
Sequence
call MegaColor
call frame1
goto Sequence
;------------------------
rainbow macro c1,c2,c3 ......... endm
frame1
do section bits macro calls display
return
;----------------------
display macro pattern
movlw pattern%256
movwf copyPORTB
movlw pattern/256
movwf copyPORTA
Morph color1,color2,color3
endm
;----------------------
Morph macro color1,color2,color3
Modulate Color1 to Color2
call Output
Modulate Color2 to Color3
call Output
Modulate Color3 to Color1
call Output
endm
;----------------------
Output
addfw copyPORTA
movwf PORTA
movwl copyPORTB
movwf PORTB
return
 
Do you have video of your circuit in operation, please? I'm not getting very smooth color changes (using a single RGB LED) so far...
 
Do you have video of your circuit in operation, please? I'm not getting very smooth color changes (using a single RGB LED) so far...
I took videos of fix3color and color rot. My camera is not fancy and does not have a high refresh rate. Hence when you video tape any lit subject, it will compensate for brightness (blurs it) and also shows flashing since LED flash do not match camera frame rate. That said if you have an email, you are welcome to them.
Warm Regards,
Rom
 
Updated Hardware Copper and Silk Screen. One sided copper with 18-pin ZIF socket. Board size 3.3 inches in diameter. With voltage regulator onboard, power supply can be upto 15VDC. Board maximum power consumption with all RGB on in white color and all transistors fired at the same time is approximately 1W. Cost of running the board 24/365 is less than $1.25 per year!
 

Attachments

  • A12 MINI ROUND COPPER.pdf
    25.2 KB · Views: 189
  • A12 RGB ROUND ZIF SILK.pdf
    38.5 KB · Views: 263
Quick question. What is the easiest and shortest way to test if W is zero?
Example:
movfw VarA ;content of VarA is read into W
If W=0 then goto Done1 ;if w=0 then go to Done
Prog1 ;If W>0 then continue with Prog1
do something
Done

Found the answer:
iorlw 0x00
btfsc STATUS,Z ;test z if set or zero
goto _DoSomething ;w is not zero, goto a label and do something
Done ;w=0 we are done
 
Last edited:
I am working on modifying the code for ColorRot with a lot of improvements. It is going to take a while for my next posting.
I have discovered additional patterns within the code that I will be taking advantage of. Additionally I will be converting a lot of my loops into macros.
Best of all I will be raising the color depth to 8 bit per primary colors for total of 24 color bit resolution. Remember keeping the resolution low enough will increase the duty cycle and make the LED's brighter. I will post my findings or if I run into any issues. Monday 10/6/2014
Regards,
Rom
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top