RGB LED chaser, PIC based, improvement from cd4017 circuit

Discussion in 'The Projects Forum' started by takao21203, Apr 26, 2015.

  1. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    I've assembled the prototype now, using a 16F716 I have some of these around from a few years ago.

    Circuit is a matrix, common Anodes which are driven by PORTB, and cathodes for each color also connected , sink is done with 2n7002 mosfets.

    It is programable fully, compared to these CD4017 circuit kits, which are surprisingly popular but a bit boring after some time.

    Subject of examination are how much voltage does this display need,and how many bits resolution i get for each component R,G,B (using a 5 MHz resonator, this PIC needs less than 1mA for itself).
    And of course, how does it actually looks like?
     
    RRITESH KAKKAR likes this.
  2. pwdixon

    Member

    Oct 11, 2012
    488
    56
    Need to see a schematic really but are there any LED resistors?
    Also, can you explain what your question is as it's not dreadfully clear?
     
  3. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    this just to documentate for myself and to publish for the consideration of others.

    Resistors arent needed. i plan to add mcp1640 to run from single battery
     
  4. pwdixon

    Member

    Oct 11, 2012
    488
    56
    Why aren't resistors needed?
     
  5. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    for 3 reasons

    the total current for io port is limited
    multiplex is used
    supply is less than 5 volts

    i have run 2digit led with button cell for 3 days and have done research on the topic
     
  6. pwdixon

    Member

    Oct 11, 2012
    488
    56
    The I/O port is not the issue as the FET is taking the LED load current, you may well be getting away with this as the LEDs are not permanently illuminated (until you get a software fault) and the battery resistance is dropping the battery volts to the level of the LED forward voltage.
     
  7. takao21203

    Thread Starter Distinguished Member

    Apr 28, 2012
    3,577
    463
    no it also works from 5v when the multiplex is off.
    Powering by the pickit3.
    Thats not the point here its just a technique used.

    I got it working today so far, the LEDs cycle through, and change colors.
    Different to a CD4017, here the LEDs cycle back and forth.

    Code (Text):
    1.  
    2. /******************************************************************************/
    3. /* Files to Include                                                           */
    4. /******************************************************************************/
    5.  
    6. #if defined(__XC)
    7.     #include <xc.h>         /* XC8 General Include File */
    8. #elif defined(HI_TECH_C)
    9.     #include <htc.h>        /* HiTech General Include File */
    10. #endif
    11.  
    12. #include <stdint.h>        /* For uint8_t definition */
    13. #include <stdbool.h>       /* For true/false definition */
    14.  
    15. #include "system.h"        /* System funct/params, like osc/peripheral config */
    16. #include "user.h"          /* User funct/params, such as InitApp */
    17.  
    18. /******************************************************************************/
    19. /* User Global Variable Declaration                                           */
    20. /******************************************************************************/
    21.  
    22. /* i.e. uint8_t <variable_name>; */
    23. const unsigned char phase_patt[]={1,2,4};
    24.  
    25. const unsigned char animtbl1[]={0,0,1,2,4,8,16,32,64,128,0,0,128,64,32,16,8,4,2,1};
    26. unsigned char animsteps=sizeof(animtbl1);
    27.  
    28. const unsigned char allred[]={0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,\
    29.                               0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,\
    30.                               0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
    31.  
    32. const unsigned char allgreen[]={0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,\
    33.                            0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,\
    34.                            0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
    35.  
    36. const unsigned char allblue[]={0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,\
    37.                                0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,\
    38.                                0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf};
    39.  
    40. unsigned char flags,porta_buf;
    41.  
    42. unsigned char rgbleds[32];
    43.  
    44. unsigned char phase,refresh_ctr,disp,i;
    45. unsigned char output_buf,shl_val;
    46. unsigned char color_ctr,blink_ctr;
    47.  
    48. unsigned char mask_outputbuf,animidx,moving_ctr;
    49.  
    50. void init_leds(unsigned char*s)
    51. {unsigned char i;
    52.  for(i=0;i<24;i++)
    53.  {
    54.   rgbleds[i]=*(s+i);
    55.  }
    56. }
    57.  
    58. void copyleds_phase()
    59. {unsigned char disp,i;
    60.     disp=phase<<3;
    61.  for(i=0;i<8;i++)
    62.  {
    63.   rgbleds[24+i]=rgbleds[disp+i];
    64.  }
    65.  
    66. }
    67. /******************************************************************************/
    68. /* Main Program                                                               */
    69. /******************************************************************************/
    70. void main(void)
    71. {
    72.     /* Configure the oscillator for the device */
    73.     ConfigureOscillator();
    74.  
    75.     /* Initialize I/O and Peripherals for application */
    76.     InitApp();
    77.  
    78.     PORTB=0b10101010;
    79.     PORTA=0b00000001;
    80.  
    81.  
    82.     color_ctr=0;
    83.     phase=0;
    84.     blink_ctr=0;
    85.     refresh_ctr=0;
    86.  
    87.     animidx=0;
    88.     moving_ctr=0;
    89.  
    90.     init_leds(&allred[0]);
    91.  
    92.     while(1)
    93.     {
    94.     if(flags&0x01)
    95.     {
    96.        flags&=0xfe;
    97.        refresh_ctr++;
    98.        if(refresh_ctr==16)
    99.        {
    100.         refresh_ctr=0;
    101.         copyleds_phase();
    102.         porta_buf=phase_patt[phase];
    103.  
    104.         moving_ctr++;
    105.         if(moving_ctr==0x10)
    106.         {
    107.            moving_ctr=0;
    108.            mask_outputbuf=animtbl1[animidx];
    109.            animidx++;if(animidx>animsteps)animidx=0;
    110.         }
    111.         blink_ctr++;if(blink_ctr==0xff)
    112.         {
    113.            blink_ctr=0;
    114.            color_ctr++;if(color_ctr==3)color_ctr=0;
    115.  
    116.            if(color_ctr==0)    init_leds(&allred[0]);
    117.            if(color_ctr==1)    init_leds(&allgreen[0]);
    118.            if(color_ctr==2)    init_leds(&allblue[0]);
    119.  
    120.            copyleds_phase();
    121.         }
    122.         phase++;if(phase==3)phase=0;
    123.  
    124.        }
    125.        
    126.         shl_val=1;
    127.         for(i=0;i<8;i++)
    128.         {
    129.         if(rgbleds[24+i]>0)
    130.         {
    131.             output_buf|=shl_val;
    132.             rgbleds[24+i]--;
    133.         }else output_buf&=0xff-shl_val;
    134.         shl_val<<=1;
    135.         }
    136.        
    137.     }
    138.  
    139.     PORTA=porta_buf;
    140.     PORTB=output_buf&mask_outputbuf;
    141.         /* TODO <INSERT USER APPLICATION CODE HERE> */
    142.     }
    143.  
    144. }
    Code (Text):
    1.  
    2. void InitApp(void)
    3. {
    4.     /* TODO Initialize User Ports/Peripherals/Project here */
    5.  
    6.     /* Setup analog functionality and port direction */
    7.  
    8.     /* Initialize peripherals */
    9.  
    10.     /* Enable interrupts */
    11.  
    12.     PORTA=0;
    13.     PORTB=0xFF;
    14.     TRISB=0;
    15.     TRISA=0b1000;
    16.  
    17.     ADCON0=0;
    18.     ADCON1=0b111;
    19.     TMR0IE=1;
    20.     GIE=1;
    21.     OPTION_REG=0x80;
    22. }
    23.  
    Schematic is just the LED Anodes on PORTB, the 3 cathode rows on PORTA via MOSFETs.
    Which dont limit current by the way.
     
  8. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,031
    3,803
    Read the OP's post (#4) on this thread - all is explained concerning resistors on LEDs.
    http://forum.allaboutcircuits.com/threads/pic-and-common-anode-7-segment-led.104910/#post-797025
     
Loading...