Look, no Arduino (2) - trying out a novelty LED with PIC16F54

Discussion in 'Embedded Systems and Microcontrollers' started by takao21203, Jun 24, 2014.

  1. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    People often say this device is so much stone age and it probably is.

    However, I still have these chips around, and why not use them sometimes?

    This time I wanted to try out a novelty LED, a new kind of rectangular bargraph LED. They arrived today!

    So I wired out a small 16F54 PCB, solder in the holes so I could not insert a 7seg display anymore. Chip still working. I figured out it's quite comfortable to surface mount fly wires on PCB pads.

    Compared to a DIL chip, I have the ICSP labelled, and it's smaller too.

    This time I use a 32 KHz crystal, which gives 8 KHz cycle frequency.

    And I wrote a LED flashlight in C language- it turns on for a while, flashes all the LEDs quickly, then turns off again (to save on the battery).

    Power supply is from one AAA battery, using a MCP1640 dc/dc booster IC. I had one assembly around for 2 years, with capacitors and resistors mounted on the SMD adapter (I know it's bad, have larger SOT23 adapters here).

    All it needs is a 10uH RF Inductor! And it produces 2.7 volts. No resistors needed at all. The circuit does not turn on immediately, due to low voltage, or whatever the reason. But in the end, it did.

    The C code is not good, there is a workaround for a strange bug, I just had an idea for a workaround, and did that, instead of searching for the bug.

    Code ( (Unknown Language)):
    2. unsigned const char patt_tbl_B[]={0,0,2,4,8,16,32,1,0,0,0,0};
    3. unsigned const char patt_tbl_A[]={0,0,0,0,0, 0, 0,0,1,2,4,8};
    5. void main(void)
    6. {unsigned int tmr_chain1,tmr_chain2,tmr_chain3;
    7. unsigned char chain1,patt_tbl_idx,chain2,chain3;
    9.     TRISA=0;
    10.     TRISB=0;
    12.     tmr_chain1=0;
    13.     tmr_chain2=0;
    14.     patt_tbl_idx=0;
    15.     chain1=0;
    16.     chain2=0;
    17.     chain3=0;
    19.     PORTA=0;
    20.     PORTB=0;
    21.     OPTION =0x08;
    23.     while(1)
    24.     {
    25.     // 8 KHz / 128 = 64 Hz
    26.     if(TMR0>0x40)
    27.     {
    28.      tmr_chain1++;
    29.          TMR0=0;
    31.      if(chain1==1)tmr_chain2++;else tmr_chain2=0;
    32.      if(chain2==1)tmr_chain3++;else tmr_chain3=0;
    33.     }
    35.     if(tmr_chain1==200)
    36.     {
    37.        tmr_chain1=0;
    38.        if(chain1==1)chain1=0;else
    39.        {
    40.            chain1=1;
    41.            patt_tbl_idx=0;
    42.        }
    43.     }
    45.     if(chain1==1)
    46.     {
    47.      if(tmr_chain2==10)
    48.      {
    49.         tmr_chain2=0;
    50.         patt_tbl_idx++;if(patt_tbl_idx==12)
    51.         {
    52.         patt_tbl_idx=0;
    53.         chain1=0;
    54.         chain2=0;
    55.         }
    56.         if(chain2==1)chain2=0;else chain2=1;
    57.      }
    59.      if(chain2==1)
    60.      {
    61.          if(tmr_chain3==3)
    62.          {tmr_chain3=0;chain2=0;}
    63.      }
    64.     }
    66.     if((chain1==1)&&(chain2==1))
    67.     {
    68.         PORTB=patt_tbl_B[patt_tbl_idx];
    69.         PORTA=patt_tbl_A[patt_tbl_idx];
    70.     }else
    71.     {
    72.         PORTB=0;
    73.         PORTA=0;
    74.     }
    75.     }
    76. }
    About 40% from the FLASH is used.
  2. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    There is a small issue, the circuit does not always turn on immediately.

    I have two ceramic caps, one at the dc/dc converter, one at the ICSP row header. Both 4.7uF. 4.3k MCLR resistor.

    Loading caps for the 32KHz crystal are 27 pF, maybe too high at 2.7 volts? The PIC 16F54 should be fine with as little as 2.0 volts.

    Eventually I will swap with a 500 KHz resonator, and see if it improves.

    Last not least I also want to test a 1000uH or 1500uH coil, and see how long the battery lasts with that.

    The LEDs (only one of them) are only "ON" about 1/10 of the time.

    I also had the LED chain running with 4.65 volts, no overcurrent message, no damage.

    My guess is, the PIC internal resistance on a LED is effectively higher, compared to being grounded. Might have something to do with the MOSFET Thresholds? Because 60 mA would detoriate a LED, somehow.

    When the battery becomes depleted, I run some tests with fresh batteries, maybe I can get 3 weeks or so out of a Zinc Carbon AAA, and more from an Alkaline?

    Maybe, build 50 of them, and test battery brands.
  3. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    Also tapping the hot side from the coil for the clock signal could be an option, only needs one 10K resistor.

    The converter by the way does turn on immediately, measured with a DMM, 2.7 volts, but the LEDs sometimes don't come on for quite a long while.