Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,286 members, 7,807,968 topics. Date: Thursday, 25 April 2024 at 12:21 AM

Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) - Science/Technology - Nairaland

Nairaland Forum / Science/Technology / Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) (4022 Views)

Embedded Systems Tutorial For Beginners:experiment 5 Intro To 7 Segment Displays / Embedded Systems Tutorial For Beginners:experiment 4 (traffic Light System) / EMBEDDED SYSTEMS Tutorial:#include <module3.h>software And Hardware Tool Needed (2) (3) (4)

(1) (Reply) (Go Down)

Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) by guassian: 7:03pm On Apr 08, 2015
EXPERIMENT 3: MULTIPLE OUTPUTS, LED CHASER AND RGB LED

Tools needed:
Software: Proteus 8 to simulate the software on virtual hardware, CCS compiler version 4.0 and above to write and compile programs, pickit2 IDE to burn your compiled code into your MCU
Hardware: Bread board, RGB LED, jumper wire, pic12f683, pic16f88, BC547 NPN transistor pickit2 programmer, USB cable and power bank or USB charger to create 5v supply. You can get the hardware from a reputable Electronics Component supplying company http://hub360.com.ng/shop-2/hub360-pic-starter-kit/


Overview: The third experiment for this series of tutorial is to learn how to use the microcontroller to control multiple outputs which can then be applied in designing a LED chaser, control of multiple relays, RGB Leds etc. We can control the output port of a microcontroller individually as a pin or collectively as a port(group of pins). Both has advantages and disadvantage. Controlling the output individually as a pin is useful if other output pins in a port is not to be affected or changed. We can only control a pin as a BIT (Binary Digit) i.e. we can send a high and low to the pin or true and false or 1 and 0 which represents 5volts and 0volts respectively.

Controlling as a bit is tedious if we want to change the logic state of a while a whole port, it will require changing the state of the pins one by one which makes the processor takes more time to do the job and it also takes more code space, and the program will become much more complex to alter some values.
However, controlling the output as a port saves time and code space. It output data to the port as a BYTE (8 bit) i. e it doesn’t makes use of true and false only but you can make use of other number representation to control the output. Most low-end and mid-range microcontrollers are 8-bit (it has only 8 wires called bus to pass information internally), so the output port too is 8-bit wide. This implies that a port can only control 8 pins, so a number from 0 to 255 (decimal) can be used to control the whole port. Other number representation is binary which is 00000000 to 11111111 or hexadecimal from 00 to FF. Those are the common and most widely used number representation as far as embedded programming is concerned. Take for example:
To control the pins of port A of a PIC16f88 microcontroller individually we use the CCS C Compiler syntax:
Output_high(pin_a4); // sends logic 1 to the 5th output of port A. numbering starts from 0 to 7
Output_low(pin_a1); // sends logic 0 to the 2nd pin of port A.
To control the whole port A at once, we use the syntax:
Output_a(0b00010000); // set the 5th output of port A as logic 1 and other pins in the port as 0 using binary number system
Output_b(0X55); // the argument is a number in hexadecimal which when converted to binary gives 01010101, turns pin A0,A2,A4,A6 high and others low. The number can also be represented in binary or decimal as the program developer wishes


LED CHASER: have you ever wonder how christmass light and decoration light are done whereby all the light seems to be flashing in a particular sequence and some will be as if they are chasing themselves? Its just simple programming and nothing more. Physically we can see many lights even up to hunderds but to tell you the fact most of these decoration lights are just 4 channels i.e it has only 4 outputs that are duplicated. Eg a 100 light decoration that has 4 outputs that are duplicated 25 times. We are going to create a 4 output 12 LED light chaser. The 4 outputs will be duplicated 3 time i.e led 5 will be connected to led 1, led 6 will be connected to led 2 and so on. Hardware speaking, theses connections can be in parallel or in series. If 220Vac is to be used directly to power the LEDs and the LEDs are much lets say 200, then they should be connected series and a resistor should be connected also and a triac opt coupler should be used. For 200 LEDs using 4 channels, there will be 50 LEDs per channel and connecting them in series considering average of 3volts led breakdown voltage gives 150volts which is ok for a typical Nigerian electricity flunctuation or brownout. A resistor is connected in series to the LEDs to dissipate the excess power when the input voltage is more than 150volts. The leds can be a single color or multicolor depending on the choice of the designer. The resistor value can be calculated by using kirchoffs law(check internet or books given in previous tutorials for (LED resistor head voltage calculation).
How ever, if low voltage is used, then the LEDs may be connected in parallel and what we might just need is 5volts DC power and a transistor to switch. When connecting LEDs in parallel, they should be of the same color because different color of LEDs has different forward voltage. The series and parallel circuit is given below.
THE REST OF THE ARTICLE IS IN THE DOC FILE ATTACHED TO THIS POST.


THE RGB LED:
Colored displays are formed by combining one or more of the three primary colors which is Red Green and Blue. Let me take you back to fine art in our primary school and junior secondary school days and light spectrum in the senior secondary school physics. We were taught that combination of primary colors forms secondary colors for example, red + blue = purple green + red = yellow etc. little did we know that we are going to need that knowledge even in electronics to create display light for decorations, indications and graphic displays. A standard TV color screen displays about 16 million colors and it will surprise you to know that all these 16 million are derived from 3 primary colors Red Green and Blue.

There are various colors of LED commonly available which are red, blue, green, yellow, white. Other colors can be derived by combining two or more led colors or better still using RGB LED. RGB LED is a 3-in-1 combination on Red blue and Green LED in one package. It usually has 4 pins which one is for each LED and the forth is for common. It can be a common anode or a common cathode. Common anode in the sense that the negative terminal of all the leds comes out separately and the positive terminal of all is internally connected together and comes out as one, and the common cathode is vise-versa.

To create different colors we have to switch on some leds individually or collectively according to the above color circle. We can create just only 7 colors by switching on and off the leds but more colors can be created by varying the brightness of these colors. For the sake of the beginners, we r going to restrict ourselves to this 7 colors until we start talking about pulse width modulation techniques which is use to create variable led brightness.

THE REST OF THE ARTICLE IS IN THE DOC FILE GIVEN AT THE END OF THIS POST WHICH CONTAINS IMAGES TO HELP YOU UNDERSTAND BETTER


THE SOURCE FILE, HEX FILE AND PROTEUS FILE OF THIS EXPERIMENT IS ATTACHED TO THIS POST.

Re: Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) by guassian: 10:11pm On Apr 09, 2015
https://www.nairaland.com/2219715/embedded-systems-tutorial-beginners-include

This is the link for the previous tutorials.

If you dont understand anything, those hesitate to ask questions
Re: Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) by guassian: 8:09am On Apr 14, 2015
The next experiment which is a traffic light system is posted here https://www.nairaland.com/2255112/embedded-systems-tutorial-beginners-experiment#32700514
Re: Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) by Savotech: 8:40am On May 01, 2015
If i get u right, u said i can get 16 million colors from 1 rgb led, how possible is that.
Re: Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) by guassian: 9:26pm On May 16, 2015
Savotech:
If i get u right, u said i can get 16 million colors from 1 rgb led, how possible is that.

Yea u read me right...

Using Pulse width modulation to vary the brightness of a particular color u get the grey scale of that color. And the amount of color u can get is determined by the bit resolution of the PWM.

For example if a 8 bit PWM is used, that means we can get 2^8 (255) scale per color, let say red. Now using Red Green and Blue simulteneously using 8 bit PWM each, we get 255 x 255 x 255 colors which is in order of about 16 millions.

Hope u understand, if u r not still clear please let me know.
Re: Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) by Electronzeez(m): 12:55am On Oct 05, 2015
@Gaussian the good work you have done here is of no limit .The very first time I am seeing someone with knowledge who is virtually ready to share it at no cost .

I will simply want you to refer me to any e book or link that teaches strictly embedded system coding. I am currently brushing through my c++ note,many distraction has kept me away from finishing with my c class . Is there any e book that discuss c embedded coding alone ? BecAuse knowing how to write in c is one , being able to apply it to embedded system is another.
Thanks .
Re: Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) by Savotech: 1:57am On Oct 05, 2015
Electronzeez:
@Gaussian the good work you have done here is of no limit .The very first time I am seeing someone with knowledge who is virtually ready to share it at no cost .

I will simply want you to refer me to any e book or link that teaches strictly embedded system coding. I am currently brushing through my c++ note,many distraction has kept me away from finishing with my c class . Is there any e book that discuss c embedded coding alone ? BecAuse knowing how to write in c is one , being able to apply it to embedded system is another.
Thanks .

There is a whole lots of ebooks on embedded Systems programming online. There are some that talks about programming generally and some will emphasise on a particular microcontroller using a particular compiler. So when you are reading, have that in mind. You can go to www.pdfsearchengine.org then type embedded Systems programming in C, or microcontroller programming using C, etc. It will bring thousands of pdf books and writeupswhich u can download

1 Like

Re: Embedded Systems Tutorial For Beginners:experiment 3( Led Chaser And Rgb Led) by Electronzeez(m): 7:39pm On Oct 05, 2015
Savotech:


There is a whole lots of ebooks on embedded Systems programming online. There are some that talks about programming generally and some will emphasise on a particular microcontroller using a particular compiler. So when you are reading, have that in mind. You can go to www.pdfsearchengine.org then type embedded Systems programming in C, or microcontroller programming using C, etc. It will bring thousands of pdf books and writeupswhich u can download

Thanks savotech , I downloaded some from the link you proffer , I would be going through them plus the one I got from google.

(1) (Reply)

Mate1 Registration, Login Free Online Dating Site,on Www.mate1.com / Picture Of Making Of The World's First Camera, But Who Took The Pics?..lol / USSD Code To Check Nin On MTN, Glo, Airtel And 9mobile And Online

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.