Minute electronic circuit manufactured
Integrated circuit is a minute electronic circuit manufactured from semiconductors fabrics. It is used in every electronics device. Microcontroller is considered as an IC and contains CPU and many functions. Another thing to mention is that Microcontrollers are designed to be programmed by any programming languages which will give the output required.
This diminutive device consists of hundreds of thousands of transistors which can store a lot of applications. On the other hand, there are many Applications that controlled by microcontrollers such as control systems, automobile engine and toys.
Microcontroller can be designed from microprocessor in several aspects. Many components are used with a microprocessor in order to operate. On the other hand, Microcontroller is designed to be all of that in one. Therefore, microcontroller saves time and space needed to construct devices. Furthermore, John Morton states “This technology knows no bounds and complex circuits can be made many times through the use of these microcontrollers, of which the PIC is an excellent example “.
The project's title is controller for creative LED lighting. It aims to the ability to program PIC microcontroller and interact with programming languages. The PIC microcontroller is the heart of the project. Furthermore, it must be programmed in which the circuit and LED corresponded with each other.
What is PIC? PIC (Peripheral Interface Controller) is a miniature computer which consists of CPU. ROM, RAM and I/O circuit all in one chip. PIC family is selected in this project, due to one of the best 8 pins microchip controller. The common features are:
- 8/16 bits
- Sleep mode
- Various crystal or RC oscillator configurations
- General purpose I/O pins
- Watch dog
- RAM data memory
- ADC (Analogue digital Convertor)
- PWM (Pulse Width Modulation)
- 2K word of Flash
- EEPROM (electrically erasable programmable read-only memory)
It contains NanoWatt Technology and supported advanced peripherals. PIC microcontroller can store the information for long term approximately 40 years without power supply.
According to Microchip website”microchip technology Inc is leading provider of the microcontroller and analogue semiconductors, providing low- risk product development, lower system tools and faster time to market to thousands of diverse customer applications worldwide”.
There are many different clock operation frequencies in each PIC and the maximum is 20MHz. The memory (FLASH) is a major feature of the PIC microcontroller. However, program memory organization is the most important aspects to knowledge.
It is possibly to determine the speed of the program by the clock frequency; clock pulse is equal to ¼ cycle.
Example of clock cycle below:
1 cycle = 4 clock cycles
If 4MHz execute in 1 ms
How much time to do 1 clock pulse?
4000000 clock pulse = 1 sec
1 clock pulse = 0.00000025 sec
4 clock cycle pulses = 1 cycle = 4 x 0.00000025 sec
1 cycle = 0.000001 = 1 µsec
Clock sources can be external or internal.
Special Microcontroller Features from datasheet:
Precision Internal Oscillator:
- Factory calibrated to ±1%, typical
- Software selectable frequency range of
8 MHz to 125 kHz
Power-Saving Sleep mode
Wide operating voltage range (2.0V-5.5V)
Industrial and Extended temperature range
Power-on Reset (POR)
Enhanced Low-Current Watchdog Timer (WDT)
High Endurance Flash/EEPROM cell
6 I/O pins with individual direction control:
Analogue Comparator module with:
One analogue comparator
-Programmable on-chip voltage reference
(CVREF) module (% of VDD)
- 10-bit resolution and 4 channels
Timer0: 8-bit timer/counter with 8-bit
- 16-bit timer/counter with prescaler
- External Timer1 Gate (count enable)
- Option to use OSC1 and OSC2 in LP mode as
Timer1 oscillator if INTOSC mode selected
Timer2: 8-bit timer/counter with 8-bit period
register, prescaler and postscaler
Capture, Compare, PWM module:
- 16-bit Capture, max resolution 12.5 ns
- Compare, max resolution 200 ns
- 10-bit PWM, max frequency 20 kHz
Ambient temperature under bias...............................................................................-40° to +125°C
Voltage on VDD with respect to VSS ..................................................................... -0.3V to +6.5V
Voltage on MCLR with respect to Vss .................................................................... -0.3V to +13.5V
Voltage on all other pins with respect to VSS ..................................................... -0.3V to (VDD + 0.3V)
Total power dissipation(1) .......................................................................................... 800 mW
Maximum current out of VSS p.................................................................................... 95 mA
Maximum current ............................................................................................................. 95 mA
Power supply circuit:
Flow Chart of coding: using Edraw software
- Initial and declare the registers and ports
- Loading delay and run the program.
- Red LED on
- decrement of counter by -1
- State wither the counter reached 0 or 1.
- Starts the same program in another LED and keeps repeating till the loop finished
Hardware and software are the main important parts of the project. Unfortunately, hardware was implemented before the software (simulation in PC). This caused some problems especially in testing and result. PIC12F683 does nothing without programming, consequently no result had been made for the first implementation due to no default program was built in.
Two main hardware parts were applied to the power supply circuit.
There are a lot of comments and recommendations regarding power supplies for the project in the internet, some of them cause reliability problems and some do not.
Power supply must not affect the operation of the microcontroller. Subsequent to some research about power supply and how to do a perfect supplier to the PIC microcontroller mostly operate from 5v and requiring 10 to 50 mA. It had been established from the data sheet for the PIC 12F683 electrical specification that voltage on VDD with respect to VSS must be around -0.3v to +6.5v. However, maximum current in to VDD should be 95mA.
As a consequence, three terminal voltage regulator (78L05) is used to make the stable power of 5v and maximum output current = 100mA over the temperature range. Two capacitors are added to the regulator. C1 and C2 are pretty important as they keep the 78K05 stable and they have a tendency to oscillate in certain conditions.
The most significant about power is not causing any problems during development. Multi-Volt (user selectable) 1.5 - 12 DC plug-pack supplier is used to supply the circuit. LED indicator followed the power to indicate the electrical system's status.
A series diode in positive line before the input capacitor is added due to protection when the plug-pack is connected in wrong way.
Voltage regulator followed the diode and outputs to the VDD of the microcontroller.
The circuit was tested before connecting to the PIC microcontroller and gave stable 5.02v on the multi-meter which is acceptable to the PIC microcontroller. However, multi-meter read only the average DC voltage due to the quality.
The oscilloscope is the best electronics test instrument to indicate the exact voltage and waves.
Another power supplies:
- USB cable.
Reasons of not using another power supply:
According to the PMB website “Nothing protects fuse like a semiconductor”. USB power supply is current limited and has a lot of high frequency noise that may cause circuit damage.
Many batteries outputs large fault current and causing damages to the electronics parts and that because of not using a fuse.
According to the PIC12F683 datasheet “The oscillator has a wide variety of the clock sources and selection features that allow it to be used in a wide range of applications while maximizing performance and minimizing power consumption”. Clock source can be configured from external or internal source.
External Clock Modes
Internal Clock Modes
1. EC: External clock
2. LP:32kHz Low Power Crystal
3. XT: Medium gain crystal
4. HS: High gain crystal
5. RC: External Resistor capacitor
Unfortunately, the first clock source circuit was built with 4MHz external resonator without any configurations in the internal clock of the PIc microcontroller. The first test resulted negatively with no output to the LED connected to GP2 pin.
Some research has been done about PWM (Pulse Width Modulation) and how to configure a square wave? Function generator is the easiest way to create square wave.
Second test was negative again due to not knowing the configuration of the PIC
PWM is scheduled for the second semester in the Gantt chart of the project, thus no pulse changes.
Solution to the clock source:
Internal source is used as a clock source and avoiding the external clock for the first circuit. The reason of that does not know the enough information about clock source and how to configure it? Consequently, internal clock can be configured by the software which is MBLAB application by using Assembly language. More about software will be discussed in the software part.
John Morton States” when you buy a PIC Microcontroller, you get a useless lump of silicon with amazing Potential. It will do nothing without- but almost anything with- the program that you write.” There are many Languages for programming the PIC microcontroller:
- Assembly Language
- PIC Basic
- Mikro C
- PIC Puscal
Assembly language is selected in this project due to the easier and faster learning and it had been done last year in Experiment 28 for Microprocessor. It is fully controlled by a Personal computer and has a large capacity along with other programming languages.
It was stated by RWB website that every programming language has their own dialect and syntax. But all the programming languages have the same have the same goal that we as human can read and write the code using our own languages.
Simple figure below explains the tasks of programming form the PIC microcontroller book:
- PIC microcontroller does nothing without a program.
- Begin writing a program using a PC.
- Pretend to program the PIC microcontroller.
- Test the code and the program.
- Use a real PIC microcontroller and program it.
- Test the output of the PIC microcontroller in the circuit.
Hallo Word program was tested using MBLAB application. This program is simply give continues pulses to the red LED connected to the output of the PIC microcontroller. It is used delay (decrement) and timer to control the output.
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)
Delay1 ; Define two 8-bit variables for the
Delay2 ; delay loop: Delay1 and Delay2
org 0 ; Start at flash address 0
bsf STATUS,RP0 ; Select Registers at Bank 1
movwf OSCCON ; Set the internal clock speed to 8 Mhz
clrf TRISIO ; Set all General Purpose I/O to output
clrf ANSEL ; Make all ports as digital I/O
bcf STATUS,RP0 ; Back to Registers at Bank 0
PICSTART Plus programmer is used to download the information (HEX FILE) from the PC to the PIC microcontroller. It is used a serial cable RS 232 to transfer the information.
It is not possible to use USB to Serial convertor cable because there is not available drive for windows 7. However, Window XP and Vista are able to recognise the driver of USB to Serial cable.
It is recommended that serial to serial cable is used for the first time in Desktop PC not Laptop.
The PIC microcontroller is the heart of this project. It has been learned a lot about microcontroller and its features.
Approaching high level of programming can affects the code of the program. Assembly language is easier and faster learning program than other programming languages.
In summary, colour changes in RGB LED require a good program. Full understanding of pulse width modulation will cause a continuous colour changes and dynamic effects.