I cant find a suitable microcontroller for multiple LEDS

spinnaker

Joined Oct 29, 2009
7,830
And I would think that the primary use of CP is to light more than one LED at a given time. Though I suppose straight CP could be used to light a single LED in which case CP alone would not bring with it PWM.

In addition to some complex code, the wiring can be a bit complex too. ;)
 

spinnaker

Joined Oct 29, 2009
7,830
i would want no less than 6 LEDs on at the same time. i think that crosses CP off my list? i will have a look at shift registers, but i just want to confirm one thing: if i later decide to do CP, my idea was to make the turning on each LED its separate class or code block, so that if i want to turn an LED on i would just call that block. that is how i do a similar thing in C++, is this correct practice using MCU?

You can do CP with 6 LEDs. But with only 6 why not just get an MCU with 6 outputs? Or use the shift register method.

In CP, you can turn on any one LED at any time. That is it's purpose. If you turn them all on and all off really fast, as Ernie mentioned. It can make it appear as more than one is on all of the time.


You do not usually use C++ with mcus though there are a couple of C++ compilers. C, Basic or assembler is usually used.
 

shteii01

Joined Feb 19, 2010
4,644
Technically speaking. If you want more PWM pins from Arduino board, you can use digital pins. All you do is turn digital pin on and off. All you have to do is figure out how long you want digital pin to be on and how long you want it to be off.

The problem with this approach is that if you use delay to keep the digital pin on, then the whole program stop and wait for the pin to turn off. There is likely a way around it, but I don't know what it is off hand.
 

Thread Starter

AnasMalas

Joined Nov 27, 2015
66
I have just looked up using shift registers (basically a MCU and a shift register talk with 4 pins in case of 16 LEDs, then the shift register provides individual paths for each LED) and i quite like it. but i could not find anything on if the shift registers can provide PWM to each LED? and would using shift registers mean that i do not need an MCU that has PWM?

aslo quick question: is there any diffrence between 8, 16, 32 etc bit parts? and what is a watch dog and do i need it?
 

spinnaker

Joined Oct 29, 2009
7,830
That is your problem with shift registers. You won't easily be able to do PWM. But why do you need PWM? What are your power requirements? Are you trying to power this project with a battery?

Search around on the Microchip site. I am sure they have a paper that explains all of the various features available on their chips. But for now you really only need to worry about one that has binary outputs and inputs. They do have a really nice kit with tutorials. An MCU already mounted and ready to go. And I think it comes with a programmer. It is a nice way to learn. Need to run but I can look it up later if you don't find it.
 

Thread Starter

AnasMalas

Joined Nov 27, 2015
66
That is your problem with shift registers. You won't easily be able to do PWM. But why do you need PWM? What are your power requirements? Are you trying to power this project with a battery?

Search around on the Microchip site. I am sure they have a paper that explains all of the various features available on their chips. But for now you really only need to worry about one that has binary outputs and inputs. They do have a really nice kit with tutorials. An MCU already mounted and ready to go. And I think it comes with a programmer. It is a nice way to learn. Need to run but I can look it up later if you don't find it.
if you would have read the original post, you would know that each of the pieces would have a cheap 1.5 $ power banks that have a lithium battery and a small circuit board that comes with them. these provide power the second any load i applied on the USB. my plan is to have the circuit on the usb in series with a switch, and the micro usb extended to the back for charging. i need PWM or any method that would allow dimming of the LEDs. for the effect of the LEDs becoming dimmer and brighter as they fade in and out. just for visual purposes to make the gift look more appealing
 

spinnaker

Joined Oct 29, 2009
7,830
if you would have read the original post, you would know that each of the pieces would have a cheap 1.5 $ power banks that have a lithium battery and a small circuit board that comes with them. these provide power the second any load i applied on the USB. my plan is to have the circuit on the usb in series with a switch, and the micro usb extended to the back for charging. i need PWM or any method that would allow dimming of the LEDs. for the effect of the LEDs becoming dimmer and brighter as they fade in and out. just for visual purposes to make the gift look more appealing

Can each LED have the same controllable brightness? If so I have been thinking about it. You could provide a brightness control using a shift register. It would mean one more pin, a transistor and a couple of resistors. Each LED would have its anode tied to a pin on the shift register. The cathodes would be tied together through the transistor to ground. Place PWM on the base of the transistor and you could have PWM on all of the LEDs.
 
Last edited:

MMcLaren

Joined Feb 14, 2010
861
if you would have read the original post...
Welcome to life as it exists on a Forum (grin). If you're not reasonably knowledgeable in the subject you're asking questions about, you're not going to be able to filter the responses you get or you may not recognize a viable solution when you see it.

For the record, you CAN light more than one LED at a time in a Charlieplexed matrix (a common misconception). A Charlieplexed matrix is driven in very much the same manner as a traditional multiplexed matrix. You use column driver transistors to drive the LED columns and you drive the matrix rows to light the LEDs in a particular column. A Charlieplexed matrix differs from a traditional multiplexed matrix in that it uses the same I/O pins to drive both the columns and the rows except for the positions in the matrix where the column is equal to the row. You should probably add "multiplexed displays" to your research list then "Charlieplexed displays" may make more sense. The circuit shown in post #13 is a 4x5 Charlieplexed matrix with four LEDs per column. You light up to four LEDs at a time in each column as you sequence through each column to refresh the entire display. The picture of the circuit board in post #13 shows all twenty LEDs lighted at the same time with different brightness levels using BAM (Bit Angle Modulation) which is the same thing as Binary Code Modulation. With the proper programming you could light, fade, or blink any of the LEDs at various rates at the same time.

I agree with ErnieM that you may not be ready to tackle a solution that includes a multiplexed or Charlieplexed display at this early point in your research.

Good luck with your studies.

Cheerful regards, Mike

 
Last edited:

MMcLaren

Joined Feb 14, 2010
861
CharliePlexing does give you your PWM.
Please forgive me but could I impose on you to explain how it does that, please?
Keeping in mind I do NOT recommend this for our new friend here...

Charlieplexing (cp from now on) lets you turn one light on in an array. Should you wish more than one light on a time you need to constantly refresh each light on in turn quickly so persistence of vision fools your eye into seeing them all on at once.

That implies some fast routine just to update the display. If you then make the display N times faster you have the ability to PWM the display into N brightness levels.
Sorry, Ernie... That question was directed at Spinnaker's rather broad unqualified statement..
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
Add pickit 1 too your research list and you can learn this in half the time.
I happen own that thing. It was quite a useful tool back in the 90's when I got it.

Today it is quite obsolete and not suitable for anyone on a limited budget.
 

be80be

Joined Jul 5, 2008
2,072
That's good you have one the point is not to buy one there are 1000's of code in C to to use the led's and how it works coding is never obsolete. Just because there a newer chip what can be learned with it's code for the leds that they Charlieplexed Is a very good tool to learn by. And I really don't see telling some one things are obsolete just because of opinion. Fact is that the code for this was posted wrote by a very good programmer and is still on sale today. It's in Hi-tech C which can be easily ported to the xC 8 in mplab X . Not only that the Microchips tip and tricks goes into details how to do this. Page 6 http://ww1.microchip.com/downloads/en/DeviceDoc/01146B.pdf

Code:
/*
;Software License Agreement                                        
;                                                                   
;The software supplied herewith by Microchip Technology            
;Incorporated (the "Company") is intended and supplied to you, the 
;Company’s customer, for use solely and exclusively on Microchip   
;products. The software is owned by the Company and/or its supplier,
;and is protected under applicable copyright laws. All rights are  
;reserved. Any use in violation of the foregoing restrictions may  
;subject the user to criminal sanctions under applicable laws, as  
;well as to civil liability for the breach of the terms and        
;conditions of this license.                                       
;                                                                   
;THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, 
;WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED 
;TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A      
;PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, 
;IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR        
;CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.      
;****************************************************************************
;PICkit(tm) 1 Tutorial #3
;Interrupts
;
;Filename:        ledint.c
;Author:        Mike Rylee
;Date:          1.14.03
;Version:        1.00 (8 LED Version)
;Description:    This is a C written program designed to show the user
;                an interrupt driven LED State Machine.
;                   Also, the program shows an interrupt on pin change to change the
;                speed at which the leds are flashing.
;
;                This program uses the intlib.obj library file.  The library
;               contains the led display & push button debounce functions The
;               source code for the library can be found in the intlib.c file                      
;****************************************************************************
;Revision History
;
;****************************************************************************
;How To Flash LED's   
;****************************************************************************
;To Flash LED's simply write the 8-bit value into the variable ledregister
;in main()
;
;i.e.  ledregister = 0xFF  Flash 8 LED's D7-D0  (D7 is most significant bit)
;                                                (D0 is least significant bit)
;To Change The rate at which the LED's flash push button SW1
;****************************************************************************
*/

#include "ledint.h"

//***************************************************************************
//Main() - Main Routine
//***************************************************************************
void main()
{
    Init();                              //Initialize 12F629 Microcontroller
    while(1)                             //Loop Forever
    {   
        ledregister=0xFF;                 //Flash 8 LED's
    }
}

//***************************************************************************
//Init - Initialization Routine
//***************************************************************************
void Init()
{
    /* Comment out if using simulator, ICD2, or ICE2000
    #asm                                  //Load Factory Calibration Value Into OSCCAL
        call 0x3FF
        bsf    _STATUS,5                                    
        movwf _OSCCAL                       
    #endasm
    */
    InitLED();                             //Initialize LED variables
    ANSEL = 0;                             //12F675 Only
    TRISIO = 0xFF;                       //Set All I/O's As Inputs
    GPIO = CLEAR;                        //Clear GPIO
    VRCON = CLEAR;                       //Turn Off Voltage Reference Peripheral
    CMCON = 0x07;                        //Turn Off Comparator Peripheral
    TMR0 = CLEAR;                        //Clear Timer0
    OPTION = FASTFLASHING;               //Set Timer0 Prescaler To Fast Flash LED's
    IOCB3 = SET;                         //GP3 Interrupt On Pin Changed Enabled
    GPIE = SET;                          //Interrupt On Pin Change Enabled
    T0IE = SET;                          //Timer0 Overflow Interrupt Enabled
    T0IF = CLEAR;                        //Clear Timer0 Overflow Interrupt Flag
    GPIF = CLEAR;                        //Clear Interrupt On Pin Change Flag
    GIE = SET;                           //Enable All Interrupts
    return;
}

//***************************************************************************
//Functions
//***************************************************************************

//***************************************************************************
//Isr() - Interrupt Service Routine
//      - Timer0 Overflow & GP3 Pin Change Are Used
//***************************************************************************
void interrupt Isr()
{
    if ( (T0IE & T0IF) == SET)        //If A Timer0 Interrupt, Then
    {
        Display();                      //Update LED Array
        T0IF = CLEAR;                 //Clear Timer0 Interrupt Flag
    }
   
    else if ( (GPIE & GPIF) == SET)      //If A GP3 Pin-Change Interrupt
    {
        if (Debounce() == TRUE)       //Debounce Pushbutton
            OPTION ^= SLOWFLASHING;   //If Pushbutton Status Is Closed, Then
                                        //Toggle Timer0 Prescaler (Changes LED Flashing Speed)
        GPIF = CLEAR;                 //Clear Interrupt On Pin Change Flag
    }
    else if ( (INTE & INTF) == SET)   //If A GP2/INT External Intrrupt
    {
       
    }
    else if ( PEIE == SET)              //If Peripheral Interrupts Enabled, Check Peripheral
    {                                 //Interrupts
   
        if ( (EEIE & EEIF) == SET)      //If A EEPROM Interrupt
        {
           
        }
        else if ( (ADIE & ADIF) == SET) //If A A/D Converter Interrupt
        {
           
        }
       
        else if ( (CMIE & CMIF) == SET) //If A Comparator Interrupt
        {
           
        }
        else if ( (TMR1IE & TMR1IF) == SET) //If A Timer1 Interrupt
        {
           
        }
    }   
    return;
}
The Link is to all the lessons and it would be a great place for the OP to start and learn the skills needed to reach his goal.
http://ww1.microchip.com/downloads/en/DeviceDoc/PICkit1 Lessons.zip
 

be80be

Joined Jul 5, 2008
2,072
And contrary to belief No you don't need a pickit1. All you need is a hand full of leds any pic chip with a handful of pins a 12f 8 pin to a 16 F 20 pin chip and programmer pickit 2 or better pickit 3 and some 150 ohm resistors and 1 10 k and bread board to get started learning and some jumper wire. I use 18f1220 it's a nice chip and I can use swordfish basic with it. But that's just me C is looking back a better option because it's used with AVR and PIC chip chips so you don't have to relearn as much I started using it for the TI chips Mike told me about sometime back.
 

spinnaker

Joined Oct 29, 2009
7,830
I happen own that thing. It was quite a useful tool back in the 90's when I got it.

Today it is quite obsolete and not suitable for anyone on a limited budget.
Do they even make the 1 anymore? I think the 2 can still be bought but does not support the latest chips. But the two is really nice for someone starting out as it has a logic analyzer that would be nice to play with.
 

be80be

Joined Jul 5, 2008
2,072
Why do I have to be called a ASS I din't call anyone names I said opinion. And it don't matter if you Use Mplad 8.92 or MplabX 3 whatever
they both use xc8 and xc8 is h-tech C and is easy to use older C code with very little changes.
And all I did was point out a way to learn and I'm being a Ass ok .
I'm with Mike
Welcome to life as it exists on a Forum (grin)
 

spinnaker

Joined Oct 29, 2009
7,830
Why do I have to be called a ASS I din't call anyone names I said opinion. And it don't matter if you Use Mplad 8.92 or MplabX 3 whatever
they both use xc8 and xc8 is h-tech C and is easy to use older C code with very little changes.
And all I did was point out a way to learn and I'm being a Ass ok .
I'm with Mike
Read my post again. I was not referring to you. It just happened to land under your post but was quoted. Nothing wrong with your post IMHO.
 
Top