UPC EETAC Bachelor's Degree in Telecommunications Systems and in Network Engineering EEL

Chapter 3 problems

      - D3.5 -

Designing a LED lamp dimmer (μC - C)

Products

D3.4

D3.6


1. Specifications

Luminaries work with high efficiency LED lamps and the light generated can be dimmed using a control circuit. A typical bulb is 12W, 12V, E27 screw fitting. To modulate the light intensity we can use simple pushbuttons or rotary knots. 

The same project designed using hardware is stated in D2.5.  

Luminaries

Fig. 1. Examples of luminaries, bulbs, dimmer circuits and power drivers.

Let us propose the basic circuit for a dimmer in Fig. 2. Light intensity can be set in eight levels. Clicking button up (UB) light will increase, and clicking button down (DB) light will decrease. The idea behind controlling electrical power applied to a load like a LED bulb is to use digital pulsed width modulated waveforms (PWM). If the switching frequency is high, the eye will not be affected by flickering.

Let us invent a circuit capable of generating a 800 Hz PWM signal (T = 1.25 ms) with duty cycle modulations (D%) of 0, 12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100. 

Dimmer circuit

Fig. 2. Symbol and connection to a power lamp driver.

The lamp power driver can be modelled in Proteus using power MOS transistors. At this initial phase a simple standard LED can be used to monitor the light intensity or brightness generated at the Lamp output.  

 

2. Planning

Let us build the product organising several design phases, and several steps within each phase.

Design phase #1: basic features.

Solve the circuit for the design step #1. Only when it is fully tested working correctly and reported, solve the design step #2.

- Design step #1. Consider an initial circuit with only the up button UB.

Firstly you can imagine how to generate a Johnson counter that goes up every time the external push-button UB_L is clicked. We need to use an external interrupt INTx (x = 0, 1, or 2). You can use 8 external LED to visualise the code, or instead, you can watch the current value of RAM variable in memory.

Secondly, you can generate a new external waveform at output Lamp shifting the current Johnson code. This waveform will have a frequency of 800 Hz. Use an external interrupt as a CLK.

Project location:

C:\CSD\P10\Dim_s1\(files)

Project source files:

Dim.pdsprj, Dim.c

a) Draw the hardware schematic necessary for step #1. UB_L push button, CLK push button or oscillator (800 Hz), Johnson code outputs, reset circuit MCLR_L, and an 8 MHz quartz crystal oscillator, Lamp output. Explain how to configure the inputs and outputs in init_system().

b) Draw the function table and the state diagram indicating state transitions and outputs.

c) Draw the hardware/software diagram indicating the required RAM variables and how the FSM is solved in software.

d) Draw the truth tables and their equivalent flowcharts for state_logic() and output_logic() functions.

e) What is the interrupt service routine ISR() used in this application? Draw its flowchart.

f) Develop and test (debugging) the project capturing the hardware circuit in Proteus and writting the C source code.

 


- Design step #2. Add the down button DB_L.

Inherit the step #1 source hardware and software files into de new location.

Project location:

C:\CSD\P10\Dim_s2\(files)

Project source files:

Dim.pdsprj, Dim.c

a) Draw the hardware schematic necessary for step #2. Add the switch and resistor for input DB_L. Explain how to configure it in init_system(). A new external interrupt will be required.

Explain what is new in sections b), c), d), e), f)

Develop and test the new feature.



Design phase #2: LCD display

Let us add an LCD display as studied in P11 to this application. The idea is to use several ASCII characters to represent lamp illumination information

Project location:

C:\CSD\P11\Dim_LCD\(files)

Project source files:

Dim_LCD.pdsprj, Dim_LCD.c

g) Enhance the schematic from the previous design phase #1 to include an LCD attached to port D as studied in tutorials.

h) Enhance the software and the source file to drive the LCD.

In this design phase you can learn the LCD interface step by step. For instance:

Design step #1. Print ASCII messages on the LCD. For instance "MAX", "Minimum light", etc.


Design step #2. Print numeric information, for example the current duty cycle percentage "Light DC = 87.5%"

Develop and test the new feature.




Design phase #3: Using TMR2 peripheral subsystem.

The 800 Hz external CLK is replaced by the internal 8-bit TMR2 peripheral to generate interrupts (TMR2IF). Discuss the main features of this peripheral and its applications.

Project location:

C:\CSD\P12\Dim_LCD_TMR2\(files)

Project source files:

Dim_LCD_TMR2.pdsprj, Dim_LCD_TMR2.c

 

i) Calculate TMR2 parameters required to generate a CLK of 800 Hz (var_CLK_flag period = 1.25 ms) to run the Lamp output signal so that the external CLK signal can be eliminated. 

j) Add a new switch SP (speed) to be able to select between two different rotation periods: 200 ms and 100 ms.

Develop and test the new feature.