LED timing dimmer design based on DS1302 and Attiny13

1 Introduction

With the development of the economy, energy saving and emission reduction and low carbon economy have become the hotspots of global concern. In the field of lighting, LED as the fourth generation of lighting source, stand out with its many advantages such as high efficiency, energy saving and long life. In recent years, LED applications have increased in the field of road lighting. In streetlight applications, most cities have almost no roads after zero, and it is obviously unnecessary to maintain high brightness on low traffic. Therefore, it is especially important to adjust the brightness of street lamps, which is also very important for energy saving and emission reduction.

At present, in the LED street lamp control, timing control is mainly used. In this way, the timer automatic setting and the time-division PWM dimming control are realized for the LED street lamp according to the fixed time set by the timer, which not only saves labor cost but also achieves the purpose of energy saving and emission reduction. The current timer schemes on the market are mixed, and most of them become worse as the usage time increases. Good latitude and longitude timers are expensive and are not suitable for large-scale use on streetlights.

This article designed an LED timer based on the DS1302 and Attiny13 to improve these issues. This paper mainly introduces the hardware and software design of the timer and the hardware and software design of the time programming module for communication with the host computer.

2 overall system composition

The structure of the whole timer system is shown in Figure 1. It mainly includes the host computer (PC), the real-time clock programming module connected to the PC through the serial port, the timer connected to the programming module through the SPI port, and the LED with PWM dimming driver. Street light.

Figure 1 LED street light timing control system structure

The user writes the time to the time programming module by operating the program on the PC interface, and saves it. Then the user operates the time programming module to write the time to the DS1302 in the timer through the SPI interface, thus completing the timer setting. Attiny13 in the timer continuously reads the time of the DS1302, timing action, and sends a PWM signal to control the LED driver to realize timing control.

This design focuses on the hardware and software design of the timer and time programming module.

3 timer hardware and software design

3. 1 timer hardware design

The timer is mainly composed of a real-time clock part and an MCU circuit. The chip used in the real-time clock part is the DS1302. The DS1302 is a high-performance, low-power, low-power real-time clock chip with RAM from DALLAS, USA. It can time the year, month, day, week, hour, minute and second, and can be used for monthly The number of days and the number of days in the leap year are automatically adjusted. The clock can be either a 24-hour clock or a 12-hour clock. The DS1302 consumes very little power and maintains less than 1mW of data and clock information. It can operate for up to 10 years with a secondary 3V lithium battery without mains.

The MCU uses the AVR series 8-bit microcontroller Attiny13. Attiny13 is a high performance, low power 8-bit AVR microprocessor with a simple structure, few pins, and low cost. It is suitable for high-volume use in street lighting control systems to save costs.

As shown in Figure 2, the entire timing module is powered by the same 48V DC as the external LED driver. The voltage regulator circuit consisting of a Zener diode and a capacitor stabilizes the voltage at 4.7V. As the main power supply of the DS1302 and the power supply of the Attiny13, the DS1302 The backup power supply is powered by a 3V lithium coin cell battery.

The real-time clock chip DS1302 provides timing pulses with a 32.768kHz crystal oscillator for time-and-minute seconds. Synchronous communication with the MCU through the SPI three-wire interface is the CE pin, the SCLK serial clock pin, and the Iî“”O serial data pin 3 lines.

Figure 2 Schematic diagram of the timer circuit

Attiny13 is the MCU of the timer with its simple function and low price. It uses three IO ports to read the DS1302 time. The internal Tî“”C0 is a general-purpose 8-bit timer/counter module with two independent output compare units and supports PWM functionality. It provides accurate execution timing and waveform generation, and generates a PWM signal on PB0 for dimming.

3. 2 timer software design

The software design is mainly written on the Attiny13 microcontroller, written and debugged in the AVR Studio 4 environment. The flow chart is shown in Figure 3. The program workflow is as follows:

1) Macro definitions, such as custom timing dimming time and dimming duty cycle;

2) Port initialization, including input and output configuration of IO port, watchdog configuration and timer Timer0 configured for fast PWM mode;

3) For the DS1302 initialization function, define a 1-byte read-write function and a time-division-second read/write function;

4) The main function, cyclically call the DS1302 time reading function to obtain the real-time time on the DS1302, determine whether to switch the lamp, adjust the dimming duty cycle, and realize the timing control.

Figure 3 timer program flow chart

In the program, the user can modify the program according to the actual situation, add different duty cycles and different dimming time nodes, and realize flexible timing control independently.

4 time programming module hardware and software design

Considering the actual use, the timers are used in batches in the LED streetlight system. In order to ensure the synchronization of the dimming, the initial time of each timer must be different in the actual production process, but it must be kept in real time. Consistent.

The function implemented by the whole module is to save the current time of the PC to the programming module and realize the walking time, display it on the LCD screen, and press the button to send the current dynamic time to the timer and feed it back to the LCD screen.

4. 1 time programming module hardware design

The structure diagram of the time programming module is shown in Figure 4.

Figure 4 time programming module structure diagram

The core MCU is an 8-bit AVR microcontroller Atmega16, the Atmega16 communicates via a serial port and a PC, and the DS1302 is connected via a 3-wire SPI. By operating the interface on the PC, the user can assign the current time of the PC to the internal DS1302 through the Atmega16 and save it in it. The user can see the internal DS1302 time through the LCD screen. At this point, the programming module has saved the real time to it.

Then the user only needs to operate the time programming module to realize the function. By pressing the button, the user can send the current time to the timer and display the timer time on the LCD. This ensures that the time synchronization between each timer is consistent with the system time of the PC.