-->

Development of a DSP-Controlled On-Line UPS

By
    

This research has developed DSP-based digital control techniques for high-performance single-phase on-line UPS systems. A transformerless common-neutral half-bridge AC-DC-AC converter has been adopted for the main power circuit.  All the control functions for an on-line UPS, which includes power-on start-up control, input stage power factor control, battery charging and boosting control, output stage ac voltage regulation, and shut-down control, were realized by using a single-chip DSP controller, the TMS320F2407A. A multiple rate digital controller generates all the PWM control signals for the power stage by using a set of synchronously detected feedback signals. Software current control scheme with nonlinear pulsewidth compensation has been developed to eliminate the nonlinearity caused by the dead-lock protected PWM converters. A nonlinear digital control scheme with lower switching frequency has been developed for the power factor control of the ac-dc converter. Computer simulation and experimental results have been given to verify the proposed digital control scheme. The constructed DSP-controlled UPS system can achieve fast dynamic response for nonlinear loads and high power factor under various loading conditions. The developed UPS digital control techniques have been applied to a commercialized single-phase 2 kVA double conversion UPS. Excellent performance measurements have been achieved in the designed DSP-controlled UPS. 

        Implementation of a fully digital-controlled UPS provides many advantages, such as more sophisticated control functions can be employed in a UPS system, a software-controlled UPS can be more flexible, advanced robust control schemes can be implemented to accommodate stringent and versatile application requirements. Many research works have been carried out on the closed-loop regulation of PWM inverters using various feedback control schemes to achieve both good dynamic response and low harmonic distortion. Microprocessor-based deadbeat control technique has been applied to the closed-loop regulation of PWM inverters. Deadbeat control has been developed for the voltage regulation of the PWM inverter by employing a minor current loop and a major voltage loop. However, deadbeat control scheme has the disadvantages of highly sensitive to parameter and load variations and requiring large peak-to-average ratio of control signals to achieve deadbeat effect.




With the great advances in microelectronics and VLSI technology, high-performance microprocessor and digital signal processors (DSPs) can be effectively used to realize advanced control schemes [7]. Most instructions of a DSP can be accomplished within one instruction cycle and complicated control algorithms can be executed with fast speed, therefore, more control functions can be realized by using software. Attempts have been made to realize a fully DSP-controlled UPS [8]-[9]. However, only limited functions have been realized using software. In this paper, a single-chip DSP controller, the TMS320F240 from Texas Instruments, has been used to realize all the control functions required in an on-line UPS system. 
        With the availability of 16/32-bit high-performance single-chip DSP, as shown in Fig. 1.3, most of its instructions can be accomplished within one instruction cycle, complicated control algorithms can be realized efficiently. This paper describes the design and implementation of a DSP-embedded fully digital-controlled single-phase on-line uninterruptible power supply (UPS) system. All the control functions for an on-line UPS, which includes power-on start-up control, input stage power factor control, dc-link voltage regulation, battery charging and voltage boosting control, output stage ac voltage regulation, and shut-down control, were realized by using a single-chip DSP controller. 
2. Power Circuit Design
        The selection or development of a circuit topology for a single-phase double-conversion UPS plays a most important role in the design of a high-performance UPS. This is due to that the circuit topology is highly dependent on the overall efficiency, cost, safety regulations, and possible patent conflicts
 2.1 Half-Bridge Common-Neutral AC-DC-AC Converter
        Single-ended, half-bridge, or full-bridge PFC converters are all boost converters, from the point-of-view of control loop design they have the same dynamics. The only difference is the effective voltage applied to the inductor due to a specified PWM duty. From the point-of-view of power circuit design, these three PFC converters have the same utilization factor, which result the processing power ratings are proportional to their number of switches. The half-bridge PFC converter has advantages of common-neutral in UPS applications and a minimal number of power switches is required. However, it also has disadvantages of higher voltage stress and need fast response balance control of the totem-pole capacitor bank. Fig. 2.2 shows the detailed schematics of the power circuit of the common-neutral ac-dc-ac converter and Fig. 2.3 is an illustrated circuit topology for functional description and component rating calculations.  

Figure 2.3  Common-neutral half-bridge ac-dc-ac converter.
Figure 2.2  Schematics of the Common-neutral half-bridge ac-dc-ac converter.
 The inherent bi-directional characteristics of a common-neutral ac-dc-ac converter can be illustrated as shown in Fig. 2.4. The UPS output connected load may be inductive, capacitive, or even nonlinear with reactive characteristics, therefore, in order to a unit power factor input as well as keep a good dynamic response under step load change condition, the dc-link capacitor should provide a sufficient energy storage to maintain a half-cycle voltage fluctuation.

 2.2 PFC Converter 
        Single-ended, half-bridge, or full-bridge PFC converters are all boost converters, from the point-of-view of control loop design they have the same dynamics. The only difference is the effective voltage applied to the inductor due to a specified PWM duty. From the point-of-view of power circuit design, these three PFC converters have the same utilization factor, which result the processing power ratings are proportional to their number of switches. The half-bridge PFC converter has advantages of common-neutral in UPS applications and a minimal number of power switches is required. However, it also has disadvantages of higher voltage stress and need fast response balance control of the totem-pole capacitor bank.   
3. Control Loop Design
        There are many control functions required in a smart UPS system, These may include system monitoring, diagnosis, protection, interface control, and real-time control. The real-time control function plays an important role for the improvement of the UPS control performance. The control functions of a UPS system can be classified four major parts according to their control purposes. These include: front-end power factor correction control, PWM inverter control for sinusoidal output voltage regulation, the dc-dc boost control for dc-link voltage regulation, and the battery charging control. These control functions are described as follows. 
3.1 Power Factor Control 
        Regulations on line current harmonics have made power factor control a basic requirement for power electronic equipment [14]. The main purpose of the PFC converter is to shape the input current to be linear proportional to its input voltage so that it behaves as a resistor. Another purpose of the PFC converter is to regulate its output dc voltage under line and load variations. 
        Conventional PFC control schemes focus on the shaping of the line current in proportional to the voltage and therefore, a current loop controller with wide bandwidth is required. However, in order to minimize the current distortion resulted from the dc-link voltage regulation, a low-pass filter is required to smooth the double line frequency ripples in the dc-link voltage. This results a slow response of the UPS front-stage power converter. The slow response of the PFC converter will result a large voltage drop under a step load change and further deteriorate the UPS output waveform. 
        In order to improve the dynamic response of the PFC boost converter, various feedback control schemes have been analyzed in [15]. Analog notch filter to eliminate measured output voltage ripples can achieve a better dynamic response compared with other approaches. Development of fast response control schemes for the PFC boost converter has become a technical pursuing goal in recent years [16]-[19]. These control techniques break the bandwidth barrier of double line frequency by using sophisticated control techniques in elimination the influences of output voltage ripples. All these control schemes are applied to the PFC boost converter and using analog controller or analog current-loop controller with microprocessor-based voltage-loop controller.
        One major design challenge in synthesizing a digital PFC controller is that we must make a compromise between the line current distortion and a fast response of the dc-link voltage regulation. Fig. 3.1 shows the control structure of a single-phase PFC converter and Fig. 3.2 is the detailed control block diagram. The PFC controller consists of three sub-controllers: an inner current loop controller, an outer voltage loop controller, and an adaptive ripple estimator.
    The inner current loop controller is required to regulate the line current with a high sampling rate, usually from 10 to 20 kHz. The outer voltage loop controller is used to regulate the dc-link voltage and at the same time to generate a current reference for the current loop. A lower sampling rate from 1 to 2 kHz is an appropriate choice for the voltage loop. The adaptive voltage ripple estimator is used to generate a compensated signal to cancel the line ripple voltage occurred in the dc-link. 
                    Figure 3.1  Control structure of a single-phase PFC converter.
Figure 3.2  Detailed control block diagram of a digital-controlled half-bridge PFC converter.
3.2 PWM Inverter Control 
        The control loop design for the PWM inverter for ac voltage regulation is most difficult in the synthesis of the digital controller for the UPS. This is due to that the inverter should provide good quality ac voltage, this means low voltage THD, for various kinds of loads. The control architecture of the PWM inverter for ac voltage regulation is shown in Fig. 3.3. It includs four control loops.
  1. Balancing Control Loop (fs=60 Hz): This loop is used to compensate dc-offset due to nonlinear distortion such as unbalanced turn-on and turn-off time, unbalance of the upper and lower common-neutral dc-link voltages, and possible dc-offsets of the feedback sensing circuits. 
  2. RMS Control Loop (fs=60 Hz): This loop is used to compensate RMS voltage errors due to limited voltage loop bandwidth and output voltage THD distortion when connected with nonlinear loads. 
  3. Voltage Control Loop (fs=6 kHz): This loop is used to compensate the instantaneous output voltage to track a sinusoidal 60 Hz reference. The desired closed-loop bandwidth (600 Hz) should be at least ten times of the reference frequency (60 Hz). A 10 times of sampling frequency to BW ratio means the voltage loop sampling frequency should be 6 kHz. 
  4. Current Control Loop (fs=24 kHz): The current loop plays a most important role in the control of a PWM inverter for ac voltage regulation. This loop can decouple the inductor from the LC filter dynamics and eliminate nonlinear distortion due to dead-time of the PWM inverter. 
  5. Figure 3.3  Control architecture of the PWM inverter for ac voltage regulation.
  6. The current loop controller can decouple the nonlinear dynamics resulted by the load. The dynamics of the UPS inverter output filter with its connected load exhibits large load variations. Fig. 3.4 shows the frequency responses of the inverter with resistor load (10% ~100% load). It can be observed that the frequency response exhibits highly resonant characteristics at resonant frequency of the output filter when in light load. In order to achieve good dynamics responses and maintain good stability under large nonlinear load variation conditions, an adaptive variable structure control scheme, as shown in Fig. 3.5,  has been developed for the PWM inverter for robust ac voltage regulation. 

  7. Figure 3.5  Block diagram of the digital adaptive variable structure control scheme for AC voltage regulation.
  8. 3.3 DC-DC Booster Control 
            The booster in a UPS system is used to convert the battery output voltage to a much more high dc-link voltage. The battery booster in the designed UPS system is a common-neutral current-fed flyback converter with a coupled transformer. The PI control scheme has been applied for the inner current loop control of the boost converter. Because the booster output is connected to the dc-link and is activated when the utility is failed, its dynamic response behaves as an important performance index. The current-fed flyback converter is current regulated an inner-loop analog PWM controller and voltage regulated by an outer voltage loop controller using PI control with dc-link voltage feedforward compensation. 
    3.4 Battery Charger Control 
            The battery charger in the designed UPS system is symmetric common-neutral flyback converter. A proportional controller is used for the current regulation and a simple PI controller is used for the voltage regulation. Constant current with battery voltage profile control is adopted as the battery charging scheme. The charging profile is stored in the EEPROM of the UPS controller and can be reloaded when a new set of battery are installed. The software control approach provides great flexibility in implementing various intelligent battery charging and discharging control schemes. 
    3.5 Line Frequency Synchronization Control 
            For a double-conversion UPS, its output voltage must always be synchronized with the line voltage. This design requirement is required because in case of UPS failure or manually switched to maintenance mode the UPS output must be transferred to the line input and the synchronization ensures a smooth voltage transfer. If the line frequency is within the specified output frequency range (±3%), the output voltage should synchronize with the input voltage with zero phase error. However, if the line frequency deviation is larger than ±3% for a specified time interval (such as 10 cycles), the frequency of the UPS output voltage will converge to standard output frequency (such as 60 Hz) with a frequency slew rate of 0.1Hz/cycle. If the line frequency back to specified range, the UPS output should also synchronize with the line frequency with a same frequency slew rate. In any instances, the input current should synchronize with the line voltage and provide a proportional current control for input power factor correction.  
    4. UPS Realization 

      Realization of a practical UPS system involves a lot of sophisticated engineering works. In this research we focused on the realization issues of the digital control of the UPS system using a single-chip DSP controller - the TMS320F2407A. 
    4.1 Hardware Architecture  
      Fig. 4.1 shows the UPS hardware architecture and the control interface. The UPS consists of two major parts: the power conversion unit and the control unit. In order to unify the control interface for the control of various power converters we have defined a power interface bus, the P-bus, for the control interface between the power converter and the DSP-based control unit. We name UPS control engine for the the DSP-based UPS controller. Fig. 4.2 shows the pin definition of the UPS control engine.  
    Figure 4.1  UPS hardware architecture and control interface.
  9. 4.2 Selection of the Control Processor
       The TMS320Lx240xA series of devices are members of the TMS320 family of digital signal processors (DSPs) designed to meet a wide range of digital motor control (DMC) and other embedded control applications. This series is based on the C2xLP 16-bit, fixed-point, low-power DSP CPU, and is complemented with a wide range of on-chip peripherals and on-chip ROM or flash program memory, plus on-chip dual-access RAM (DARAM). A single-chip DSP controller, the TMS320F2407A, as shown in Fig. 4.3, has been adopted as the control core for the UPS engine. The TMS320F2407A has 32k words on-chip flash memory for program codes. This feature allows program update and flexibility for performance enhancement. 
  10. Features: 
    • Sectored Flash for field re-programmability and simplified design 
    • Code compatible platform provides easy migration path 
    • CAN module enables inter-system communication 
    • Up to 16 PWM outputs allow multi-motor/axis control 
    • 6.6us to 500-ns A/D converter enhances system accuracy 
    • 33 to 50nS instruction cycle (30 or 20 MIPS) for processing complex control algorithms 
    • RAM for high-level programming language and high-order system modeling 
    • Fast Serial communication Ports 
                      Fast Interrupts Control unit

Figure 4.3  Block diagram and features of a 40MPIS single-chip DSP controller - TMS320F2407A.
4.3 Development of the UPS Control Engine
        The TMS320F2407A running at 40 MHz with a single 3.3V supply voltage, this makes it a challenge in hardware design for electromagnetic interference reduction. Special design considerations must be carried out in the design of the PCBs for the power and control circuits for EMI control. Fig. 4.4 shows the picture of the designed DSP control card for 2U rack-mount UPS systems. This single-board DSP controller is designed to meet high-performance requirement for power electronic systems. 
Special Features: 
  • Control Processor: TMS320F2407A 40 MHz
  • External RAM: 32k Words
  • 8 channels 12-bits D/A conversion 
  • 16 channels 10-bits A/D conversion 
  • 16 channels for programmed PWM generation 
  • SPI (Serial Peripheral Interface) for multiple-DSP controller 
  • On-board RS-232 and USB interface 
  • FPGA for programmed PWM generation 
Figure 4.4  The DSP-based UPS control engine.
4.4 Development of the Power Board 
        Realization of the power board of an on-line UPS system includes a lot of accumulated experienced engineering works, such as  on the components selection, design options for application models, power circuit PCB layout for EMI reduction, and safety requirements, etc.
4.5 System Integration 
        Fig. 4.5 shows the DSP-controlled UPS under development. The developed DSP control techniques have been realized into a commercialized 2kVA UPS to shows the feasibility of employing modern digital control techniques by using an advanced digital signal processor. A systematic top-down design procedure has been developed in the design of the a series of high-performance cost-effective UPS systems for rack-mount server applications.   
4.6 Real-Time Control Firmware Design  
        The control of a power processing system is essential a real-time control problem. Many real-time control tasks can only be tested after the complete hardware has been constructed. It is time consuming for inexperienced engineers in developing these control, communication, and interface software for a commercialized UPS system. Fig. 4.7 shows the system software architecture of an on-line UPS. The control software are classified into three categories: real-time interrupted control routines, periodic background sequential control routines, and aperiodical background interface control routines. Fig. 4.8 illustrate the operating mode and interrupt mechanism of the DSP-based UPS controller and Fig. 4.9 shows the main flow chart of the system software. The interrupt-driven mechanism is activated by a real-time timer. An innovative asynchronous control scheme has been developed for the digital current loop control to achieve both good dynamic response and low electro-magnetic interference (EMI) with low PWM switching frequency.  
6. Conclusions 
  This research has completed the design and implementation of a DSP-embedded fully digital-controlled single-phase on-line uninterruptible power supply (UPS) system. The applications of high-performance DSP in complicated power electronic systems will find great potential in synthesis of sophisticated control algorithms and PWM switching schemes. This paper has applied a single-chip DSP controller, the TMS320F2407A, in realizing all the required control functions for a single-phase on-line UPS. Experimental results show the designed 2 kVA UPS can reach very good dynamic responses both in utility interface and output voltage regulation.
    Some practical important research issues include: 
  • Detection scheme of the PWM switching current under large switching noise condition  
  • Sophisticated control functions for ac voltage regulation with low THD and low switching frequency
  • Auto-tuning of the control parameters for optimal performance 
  • Fast dynamic response of the PFC converter with good power factor 
  • Good voltage regulation with nonlinear unbalanced load 
  • Achieve AC mode efficiency beyond 92% 
  • Reduction of EMI filters by using randomized PWM techniques in PFC converter 
  • Optimization of the major power device parameters 
Fore more & Credits Goes goHere 

    Development of a DSP-Controlled On-Line UPS

    By
        

    This research has developed DSP-based digital control techniques for high-performance single-phase on-line UPS systems. A transformerless common-neutral half-bridge AC-DC-AC converter has been adopted for the main power circuit.  All the control functions for an on-line UPS, which includes power-on start-up control, input stage power factor control, battery charging and boosting control, output stage ac voltage regulation, and shut-down control, were realized by using a single-chip DSP controller, the TMS320F2407A. A multiple rate digital controller generates all the PWM control signals for the power stage by using a set of synchronously detected feedback signals. Software current control scheme with nonlinear pulsewidth compensation has been developed to eliminate the nonlinearity caused by the dead-lock protected PWM converters. A nonlinear digital control scheme with lower switching frequency has been developed for the power factor control of the ac-dc converter. Computer simulation and experimental results have been given to verify the proposed digital control scheme. The constructed DSP-controlled UPS system can achieve fast dynamic response for nonlinear loads and high power factor under various loading conditions. The developed UPS digital control techniques have been applied to a commercialized single-phase 2 kVA double conversion UPS. Excellent performance measurements have been achieved in the designed DSP-controlled UPS. 

            Implementation of a fully digital-controlled UPS provides many advantages, such as more sophisticated control functions can be employed in a UPS system, a software-controlled UPS can be more flexible, advanced robust control schemes can be implemented to accommodate stringent and versatile application requirements. Many research works have been carried out on the closed-loop regulation of PWM inverters using various feedback control schemes to achieve both good dynamic response and low harmonic distortion. Microprocessor-based deadbeat control technique has been applied to the closed-loop regulation of PWM inverters. Deadbeat control has been developed for the voltage regulation of the PWM inverter by employing a minor current loop and a major voltage loop. However, deadbeat control scheme has the disadvantages of highly sensitive to parameter and load variations and requiring large peak-to-average ratio of control signals to achieve deadbeat effect.




    With the great advances in microelectronics and VLSI technology, high-performance microprocessor and digital signal processors (DSPs) can be effectively used to realize advanced control schemes [7]. Most instructions of a DSP can be accomplished within one instruction cycle and complicated control algorithms can be executed with fast speed, therefore, more control functions can be realized by using software. Attempts have been made to realize a fully DSP-controlled UPS [8]-[9]. However, only limited functions have been realized using software. In this paper, a single-chip DSP controller, the TMS320F240 from Texas Instruments, has been used to realize all the control functions required in an on-line UPS system. 
            With the availability of 16/32-bit high-performance single-chip DSP, as shown in Fig. 1.3, most of its instructions can be accomplished within one instruction cycle, complicated control algorithms can be realized efficiently. This paper describes the design and implementation of a DSP-embedded fully digital-controlled single-phase on-line uninterruptible power supply (UPS) system. All the control functions for an on-line UPS, which includes power-on start-up control, input stage power factor control, dc-link voltage regulation, battery charging and voltage boosting control, output stage ac voltage regulation, and shut-down control, were realized by using a single-chip DSP controller. 
    2. Power Circuit Design
            The selection or development of a circuit topology for a single-phase double-conversion UPS plays a most important role in the design of a high-performance UPS. This is due to that the circuit topology is highly dependent on the overall efficiency, cost, safety regulations, and possible patent conflicts
     2.1 Half-Bridge Common-Neutral AC-DC-AC Converter
            Single-ended, half-bridge, or full-bridge PFC converters are all boost converters, from the point-of-view of control loop design they have the same dynamics. The only difference is the effective voltage applied to the inductor due to a specified PWM duty. From the point-of-view of power circuit design, these three PFC converters have the same utilization factor, which result the processing power ratings are proportional to their number of switches. The half-bridge PFC converter has advantages of common-neutral in UPS applications and a minimal number of power switches is required. However, it also has disadvantages of higher voltage stress and need fast response balance control of the totem-pole capacitor bank. Fig. 2.2 shows the detailed schematics of the power circuit of the common-neutral ac-dc-ac converter and Fig. 2.3 is an illustrated circuit topology for functional description and component rating calculations.  

    Figure 2.3  Common-neutral half-bridge ac-dc-ac converter.
    Figure 2.2  Schematics of the Common-neutral half-bridge ac-dc-ac converter.
     The inherent bi-directional characteristics of a common-neutral ac-dc-ac converter can be illustrated as shown in Fig. 2.4. The UPS output connected load may be inductive, capacitive, or even nonlinear with reactive characteristics, therefore, in order to a unit power factor input as well as keep a good dynamic response under step load change condition, the dc-link capacitor should provide a sufficient energy storage to maintain a half-cycle voltage fluctuation.

     2.2 PFC Converter 
            Single-ended, half-bridge, or full-bridge PFC converters are all boost converters, from the point-of-view of control loop design they have the same dynamics. The only difference is the effective voltage applied to the inductor due to a specified PWM duty. From the point-of-view of power circuit design, these three PFC converters have the same utilization factor, which result the processing power ratings are proportional to their number of switches. The half-bridge PFC converter has advantages of common-neutral in UPS applications and a minimal number of power switches is required. However, it also has disadvantages of higher voltage stress and need fast response balance control of the totem-pole capacitor bank.   
    3. Control Loop Design
            There are many control functions required in a smart UPS system, These may include system monitoring, diagnosis, protection, interface control, and real-time control. The real-time control function plays an important role for the improvement of the UPS control performance. The control functions of a UPS system can be classified four major parts according to their control purposes. These include: front-end power factor correction control, PWM inverter control for sinusoidal output voltage regulation, the dc-dc boost control for dc-link voltage regulation, and the battery charging control. These control functions are described as follows. 
    3.1 Power Factor Control 
            Regulations on line current harmonics have made power factor control a basic requirement for power electronic equipment [14]. The main purpose of the PFC converter is to shape the input current to be linear proportional to its input voltage so that it behaves as a resistor. Another purpose of the PFC converter is to regulate its output dc voltage under line and load variations. 
            Conventional PFC control schemes focus on the shaping of the line current in proportional to the voltage and therefore, a current loop controller with wide bandwidth is required. However, in order to minimize the current distortion resulted from the dc-link voltage regulation, a low-pass filter is required to smooth the double line frequency ripples in the dc-link voltage. This results a slow response of the UPS front-stage power converter. The slow response of the PFC converter will result a large voltage drop under a step load change and further deteriorate the UPS output waveform. 
            In order to improve the dynamic response of the PFC boost converter, various feedback control schemes have been analyzed in [15]. Analog notch filter to eliminate measured output voltage ripples can achieve a better dynamic response compared with other approaches. Development of fast response control schemes for the PFC boost converter has become a technical pursuing goal in recent years [16]-[19]. These control techniques break the bandwidth barrier of double line frequency by using sophisticated control techniques in elimination the influences of output voltage ripples. All these control schemes are applied to the PFC boost converter and using analog controller or analog current-loop controller with microprocessor-based voltage-loop controller.
            One major design challenge in synthesizing a digital PFC controller is that we must make a compromise between the line current distortion and a fast response of the dc-link voltage regulation. Fig. 3.1 shows the control structure of a single-phase PFC converter and Fig. 3.2 is the detailed control block diagram. The PFC controller consists of three sub-controllers: an inner current loop controller, an outer voltage loop controller, and an adaptive ripple estimator.
        The inner current loop controller is required to regulate the line current with a high sampling rate, usually from 10 to 20 kHz. The outer voltage loop controller is used to regulate the dc-link voltage and at the same time to generate a current reference for the current loop. A lower sampling rate from 1 to 2 kHz is an appropriate choice for the voltage loop. The adaptive voltage ripple estimator is used to generate a compensated signal to cancel the line ripple voltage occurred in the dc-link. 
                        Figure 3.1  Control structure of a single-phase PFC converter.
    Figure 3.2  Detailed control block diagram of a digital-controlled half-bridge PFC converter.
    3.2 PWM Inverter Control 
            The control loop design for the PWM inverter for ac voltage regulation is most difficult in the synthesis of the digital controller for the UPS. This is due to that the inverter should provide good quality ac voltage, this means low voltage THD, for various kinds of loads. The control architecture of the PWM inverter for ac voltage regulation is shown in Fig. 3.3. It includs four control loops.
    1. Balancing Control Loop (fs=60 Hz): This loop is used to compensate dc-offset due to nonlinear distortion such as unbalanced turn-on and turn-off time, unbalance of the upper and lower common-neutral dc-link voltages, and possible dc-offsets of the feedback sensing circuits. 
    2. RMS Control Loop (fs=60 Hz): This loop is used to compensate RMS voltage errors due to limited voltage loop bandwidth and output voltage THD distortion when connected with nonlinear loads. 
    3. Voltage Control Loop (fs=6 kHz): This loop is used to compensate the instantaneous output voltage to track a sinusoidal 60 Hz reference. The desired closed-loop bandwidth (600 Hz) should be at least ten times of the reference frequency (60 Hz). A 10 times of sampling frequency to BW ratio means the voltage loop sampling frequency should be 6 kHz. 
    4. Current Control Loop (fs=24 kHz): The current loop plays a most important role in the control of a PWM inverter for ac voltage regulation. This loop can decouple the inductor from the LC filter dynamics and eliminate nonlinear distortion due to dead-time of the PWM inverter. 
    5. Figure 3.3  Control architecture of the PWM inverter for ac voltage regulation.
    6. The current loop controller can decouple the nonlinear dynamics resulted by the load. The dynamics of the UPS inverter output filter with its connected load exhibits large load variations. Fig. 3.4 shows the frequency responses of the inverter with resistor load (10% ~100% load). It can be observed that the frequency response exhibits highly resonant characteristics at resonant frequency of the output filter when in light load. In order to achieve good dynamics responses and maintain good stability under large nonlinear load variation conditions, an adaptive variable structure control scheme, as shown in Fig. 3.5,  has been developed for the PWM inverter for robust ac voltage regulation. 

    7. Figure 3.5  Block diagram of the digital adaptive variable structure control scheme for AC voltage regulation.
    8. 3.3 DC-DC Booster Control 
              The booster in a UPS system is used to convert the battery output voltage to a much more high dc-link voltage. The battery booster in the designed UPS system is a common-neutral current-fed flyback converter with a coupled transformer. The PI control scheme has been applied for the inner current loop control of the boost converter. Because the booster output is connected to the dc-link and is activated when the utility is failed, its dynamic response behaves as an important performance index. The current-fed flyback converter is current regulated an inner-loop analog PWM controller and voltage regulated by an outer voltage loop controller using PI control with dc-link voltage feedforward compensation. 
      3.4 Battery Charger Control 
              The battery charger in the designed UPS system is symmetric common-neutral flyback converter. A proportional controller is used for the current regulation and a simple PI controller is used for the voltage regulation. Constant current with battery voltage profile control is adopted as the battery charging scheme. The charging profile is stored in the EEPROM of the UPS controller and can be reloaded when a new set of battery are installed. The software control approach provides great flexibility in implementing various intelligent battery charging and discharging control schemes. 
      3.5 Line Frequency Synchronization Control 
              For a double-conversion UPS, its output voltage must always be synchronized with the line voltage. This design requirement is required because in case of UPS failure or manually switched to maintenance mode the UPS output must be transferred to the line input and the synchronization ensures a smooth voltage transfer. If the line frequency is within the specified output frequency range (±3%), the output voltage should synchronize with the input voltage with zero phase error. However, if the line frequency deviation is larger than ±3% for a specified time interval (such as 10 cycles), the frequency of the UPS output voltage will converge to standard output frequency (such as 60 Hz) with a frequency slew rate of 0.1Hz/cycle. If the line frequency back to specified range, the UPS output should also synchronize with the line frequency with a same frequency slew rate. In any instances, the input current should synchronize with the line voltage and provide a proportional current control for input power factor correction.  
      4. UPS Realization 

        Realization of a practical UPS system involves a lot of sophisticated engineering works. In this research we focused on the realization issues of the digital control of the UPS system using a single-chip DSP controller - the TMS320F2407A. 
      4.1 Hardware Architecture  
        Fig. 4.1 shows the UPS hardware architecture and the control interface. The UPS consists of two major parts: the power conversion unit and the control unit. In order to unify the control interface for the control of various power converters we have defined a power interface bus, the P-bus, for the control interface between the power converter and the DSP-based control unit. We name UPS control engine for the the DSP-based UPS controller. Fig. 4.2 shows the pin definition of the UPS control engine.  
      Figure 4.1  UPS hardware architecture and control interface.
    9. 4.2 Selection of the Control Processor
         The TMS320Lx240xA series of devices are members of the TMS320 family of digital signal processors (DSPs) designed to meet a wide range of digital motor control (DMC) and other embedded control applications. This series is based on the C2xLP 16-bit, fixed-point, low-power DSP CPU, and is complemented with a wide range of on-chip peripherals and on-chip ROM or flash program memory, plus on-chip dual-access RAM (DARAM). A single-chip DSP controller, the TMS320F2407A, as shown in Fig. 4.3, has been adopted as the control core for the UPS engine. The TMS320F2407A has 32k words on-chip flash memory for program codes. This feature allows program update and flexibility for performance enhancement. 
    10. Features: 
      • Sectored Flash for field re-programmability and simplified design 
      • Code compatible platform provides easy migration path 
      • CAN module enables inter-system communication 
      • Up to 16 PWM outputs allow multi-motor/axis control 
      • 6.6us to 500-ns A/D converter enhances system accuracy 
      • 33 to 50nS instruction cycle (30 or 20 MIPS) for processing complex control algorithms 
      • RAM for high-level programming language and high-order system modeling 
      • Fast Serial communication Ports 
                          Fast Interrupts Control unit

    Figure 4.3  Block diagram and features of a 40MPIS single-chip DSP controller - TMS320F2407A.
    4.3 Development of the UPS Control Engine
            The TMS320F2407A running at 40 MHz with a single 3.3V supply voltage, this makes it a challenge in hardware design for electromagnetic interference reduction. Special design considerations must be carried out in the design of the PCBs for the power and control circuits for EMI control. Fig. 4.4 shows the picture of the designed DSP control card for 2U rack-mount UPS systems. This single-board DSP controller is designed to meet high-performance requirement for power electronic systems. 
    Special Features: 
    • Control Processor: TMS320F2407A 40 MHz
    • External RAM: 32k Words
    • 8 channels 12-bits D/A conversion 
    • 16 channels 10-bits A/D conversion 
    • 16 channels for programmed PWM generation 
    • SPI (Serial Peripheral Interface) for multiple-DSP controller 
    • On-board RS-232 and USB interface 
    • FPGA for programmed PWM generation 
    Figure 4.4  The DSP-based UPS control engine.
    4.4 Development of the Power Board 
            Realization of the power board of an on-line UPS system includes a lot of accumulated experienced engineering works, such as  on the components selection, design options for application models, power circuit PCB layout for EMI reduction, and safety requirements, etc.
    4.5 System Integration 
            Fig. 4.5 shows the DSP-controlled UPS under development. The developed DSP control techniques have been realized into a commercialized 2kVA UPS to shows the feasibility of employing modern digital control techniques by using an advanced digital signal processor. A systematic top-down design procedure has been developed in the design of the a series of high-performance cost-effective UPS systems for rack-mount server applications.   
    4.6 Real-Time Control Firmware Design  
            The control of a power processing system is essential a real-time control problem. Many real-time control tasks can only be tested after the complete hardware has been constructed. It is time consuming for inexperienced engineers in developing these control, communication, and interface software for a commercialized UPS system. Fig. 4.7 shows the system software architecture of an on-line UPS. The control software are classified into three categories: real-time interrupted control routines, periodic background sequential control routines, and aperiodical background interface control routines. Fig. 4.8 illustrate the operating mode and interrupt mechanism of the DSP-based UPS controller and Fig. 4.9 shows the main flow chart of the system software. The interrupt-driven mechanism is activated by a real-time timer. An innovative asynchronous control scheme has been developed for the digital current loop control to achieve both good dynamic response and low electro-magnetic interference (EMI) with low PWM switching frequency.  
    6. Conclusions 
      This research has completed the design and implementation of a DSP-embedded fully digital-controlled single-phase on-line uninterruptible power supply (UPS) system. The applications of high-performance DSP in complicated power electronic systems will find great potential in synthesis of sophisticated control algorithms and PWM switching schemes. This paper has applied a single-chip DSP controller, the TMS320F2407A, in realizing all the required control functions for a single-phase on-line UPS. Experimental results show the designed 2 kVA UPS can reach very good dynamic responses both in utility interface and output voltage regulation.
        Some practical important research issues include: 
    • Detection scheme of the PWM switching current under large switching noise condition  
    • Sophisticated control functions for ac voltage regulation with low THD and low switching frequency
    • Auto-tuning of the control parameters for optimal performance 
    • Fast dynamic response of the PFC converter with good power factor 
    • Good voltage regulation with nonlinear unbalanced load 
    • Achieve AC mode efficiency beyond 92% 
    • Reduction of EMI filters by using randomized PWM techniques in PFC converter 
    • Optimization of the major power device parameters 
    Fore more & Credits Goes goHere 

    Switched-Mode Power Supply (SMPS) and Transformer Design.

    By
    1 Introduction
    PowerEsim is electronic circuit simulation software for online switched-mode power supply (SMPS) and transformer design. It can carry out loss analysis at component and circuit level, simulation of board temperature, design verification, failure rate analysis and generate relevant reports.No need to install .
    [ads-post]




    Some of the features are given below .


    1.1 A New CAD tool on the Internet for Switching Power Supplies

    PowerEsim is an online CAD tool for switching power supplies. This new concept eliminates the process of complicated licensing and software installation. Design service is readily available anytime, anywhere. It is very easy to use through any generic Web browser so that no training is required.

    • Flyback AC/DC Converter
    • Simple Flyback RCD Converter
    • Simple Flyback ZCD
    • Flyback Primary Feedback Charger (NPN)
    • Flyback Primary Feedback Charger (NMOS)
    • Emitter Driven Flyback AC-DC Converter
    • Emitter Driven Charger
    • RCC Flyback AC/DC Converter
    • Flyback PWM+S AC/DC Converter
    • Flyback PWM+S ZRCD Converter
    • Active Clamp AC-DC Converter
    • Active Clamp DC-DC Converter
    • PFC DCM Converter
    • PFC CCM AC/DC Converter
    • Interleaved PFC CCM AC-DC Converter
    • Interleaved PFC DCM AC-DC Converter
    • Full Bridge AC-DC Converter
    • Full Bridge DC-DC Converter
    • Half Bridge AC-DC Converter
    • Half Bridge DC-DC Converter
    • Asym. Half Bridge AC-DC Converter
    • Asym. Half Bridge DC-DC Converter
    • Phase Bridge AC-DC Converter
    • Phase Bridge DC-DC Converter
    • Push Pull AC-DC Converter
    • Push Pull DC-DC Converter
    • 2 Switch Forward AC-DC Converter
    • 2 Switch Forward DC-DC Converter
    • Boost DC-DC Converter
    • Buck DC-DC Converter
    • Buck Boost DC-DC Converter
    • Buck Sync DC-DC Converter
    • Buck PNP Converter
    • Simple Forward AC-DC Converter
    • Simple Forward DC-DC Converter
    • Resonate Reset Foward AC-DC Converter
    • Resonate Reset Foward DC-DC Converter
    • Lossless Snubber Forward AC-DC Converter
    • Lossless Snubber Forward DC-DC Converter
    • Generic Converter
    • LLC AC-DC Converter
    • LLC DC-DC Converter
    • LLC+SR AC/DC Converter
    • VRM 1 Phase DC-DC Converter
    • Dual Vin Sync-Buck Converter
    • Pri. FB LED Bulb Driver
    • LED Driver with PFC
    • DC 1 Lamp Ballast HB Circuit
    • DC 2 Lamp Ballast HB Circuit
    • Interleaved 2W Forward DC-DC Converter
    • RCD Forward AC/DC converter
    • DC-AC H Bridge Inverter
    • DC-AC Half Bridge Inverter
    • NN31000A DC/DC Converter
    • Emitter Driven Flyback Converter
    PowerEsim's huge component database contains thousands of items available in the market. The complete Bill of Materials is available only at a click of a mouse. Reports are ready and no more effort is needed to produce tedious documents.
    Various modules are supported including
    • Loss Analysis
    • Thermal Analysis
    • Data Vertification DVT Analysis
    • Life & MTBF Analysis
    • Input Harmonic Analysis
    • Monte Carlo Analysis
    • Waveform Analysis
    Various builders are also provided including
    • Magnetic Builder
    • Component Builder
    • BOM Builder
    • Report Builder
    • For more Click Here

    Switched-Mode Power Supply (SMPS) and Transformer Design.

    By
    1 Introduction
    PowerEsim is electronic circuit simulation software for online switched-mode power supply (SMPS) and transformer design. It can carry out loss analysis at component and circuit level, simulation of board temperature, design verification, failure rate analysis and generate relevant reports.No need to install .
    [ads-post]




    Some of the features are given below .


    1.1 A New CAD tool on the Internet for Switching Power Supplies

    PowerEsim is an online CAD tool for switching power supplies. This new concept eliminates the process of complicated licensing and software installation. Design service is readily available anytime, anywhere. It is very easy to use through any generic Web browser so that no training is required.

    • Flyback AC/DC Converter
    • Simple Flyback RCD Converter
    • Simple Flyback ZCD
    • Flyback Primary Feedback Charger (NPN)
    • Flyback Primary Feedback Charger (NMOS)
    • Emitter Driven Flyback AC-DC Converter
    • Emitter Driven Charger
    • RCC Flyback AC/DC Converter
    • Flyback PWM+S AC/DC Converter
    • Flyback PWM+S ZRCD Converter
    • Active Clamp AC-DC Converter
    • Active Clamp DC-DC Converter
    • PFC DCM Converter
    • PFC CCM AC/DC Converter
    • Interleaved PFC CCM AC-DC Converter
    • Interleaved PFC DCM AC-DC Converter
    • Full Bridge AC-DC Converter
    • Full Bridge DC-DC Converter
    • Half Bridge AC-DC Converter
    • Half Bridge DC-DC Converter
    • Asym. Half Bridge AC-DC Converter
    • Asym. Half Bridge DC-DC Converter
    • Phase Bridge AC-DC Converter
    • Phase Bridge DC-DC Converter
    • Push Pull AC-DC Converter
    • Push Pull DC-DC Converter
    • 2 Switch Forward AC-DC Converter
    • 2 Switch Forward DC-DC Converter
    • Boost DC-DC Converter
    • Buck DC-DC Converter
    • Buck Boost DC-DC Converter
    • Buck Sync DC-DC Converter
    • Buck PNP Converter
    • Simple Forward AC-DC Converter
    • Simple Forward DC-DC Converter
    • Resonate Reset Foward AC-DC Converter
    • Resonate Reset Foward DC-DC Converter
    • Lossless Snubber Forward AC-DC Converter
    • Lossless Snubber Forward DC-DC Converter
    • Generic Converter
    • LLC AC-DC Converter
    • LLC DC-DC Converter
    • LLC+SR AC/DC Converter
    • VRM 1 Phase DC-DC Converter
    • Dual Vin Sync-Buck Converter
    • Pri. FB LED Bulb Driver
    • LED Driver with PFC
    • DC 1 Lamp Ballast HB Circuit
    • DC 2 Lamp Ballast HB Circuit
    • Interleaved 2W Forward DC-DC Converter
    • RCD Forward AC/DC converter
    • DC-AC H Bridge Inverter
    • DC-AC Half Bridge Inverter
    • NN31000A DC/DC Converter
    • Emitter Driven Flyback Converter
    PowerEsim's huge component database contains thousands of items available in the market. The complete Bill of Materials is available only at a click of a mouse. Reports are ready and no more effort is needed to produce tedious documents.
    Various modules are supported including
    • Loss Analysis
    • Thermal Analysis
    • Data Vertification DVT Analysis
    • Life & MTBF Analysis
    • Input Harmonic Analysis
    • Monte Carlo Analysis
    • Waveform Analysis
    Various builders are also provided including
    • Magnetic Builder
    • Component Builder
    • BOM Builder
    • Report Builder
    • For more Click Here

    DS1307_Tutorials

    By
       The real time clock chip, DS1307, can be connected to the Arduino and used in a wide range of projects that require the processor to know the time and date.  Using this device is easy if you have a basic understanding of the Wire.h library functions and I2C communication protocol.  In this document we will discuss the basic operation of the device, how to set the date and time and how to read the information.  This document also includes several Arduino programs that can be referenced to get started with the RTC.
    [ads-post]


    RTC overview
    The DS1307 chip is a simple device integrated circuit that counts clock pulses.  The chip requires a 32.768 kHz oscillator commonly known as a watch crystal.  You will remember the binary number 0x7FFF is 32768. This means that a 15 bit counter would count from 0 up to its maximum value an role over to 0 again in exactly 1 second, if clocked at this frequency.  The chip includes a built in processor which includes the counter and several registers that keep track of the day, the date and the time.  The device also has additional memory for storage.

    The design is intended to use very little power, less than 0.5µA and it runs on 5 volts, but if the supply voltage drops to 3, the oscillator will continue to operate and keep accurate time.  The device is intended to have a CR1220 back up battery to support continued operation when the power has been unplugged.

    The DS1307 interfaces with the outside world using the I2C protocol, making it easy to program and read with the Arduino I2C internal peripheral.  The Arduino I2C port uses analog pin A4 and A5 as the data and clock lines.  The Arduino TwoWire class is loaded with the Wire.h include which activates the I2C peripheral and includes the routines that are used in this product description.


    RTC registers
    Registers are 8 bit (1 byte) memory locations that can store values. The RTC uses the I2C interface to write and read bytes from these registers.  The DS1307 has 0x37 (64) of these registers, however only the first 8 are important to the operation of the device.

    Understanding and using BCD and ASCII
    The register data is stored in BCD (Binary Coded Decimal) format.  This means that each digit of a number is given 4 bytes (1 nibble).  Each of these nibbles is allowed to use values 0 to 9 or 0000 to 1001.  This means that when we write a number in hex, we can read the number as a decimal number.

    The BCD number 0011 0100 is understood to be 34 in decimal. BCD is seldom used, but this device make use of it.  To format the data correctly one must make use of the ">>" shift right and "<<" shift left operators to create numbers that will properly represent the information.  Also, it is necessary to be familiar with AND "&" and the OR "|" functions.  In addition, it is often more useful to think in of numbers in terms of hex and binary than in decimal.

    Consider the first register which contains the current seconds.  Suppose the current time is 7:44:26 - 7 AM, 44 minutes and 26 seconds.  To set this time correctly, the appropriate values must be written to the correct registers.  Register 00 contains the seconds value.  It needs to set to be the binary number 0010 0110 or hex 0x26.  The program must convert the decimal number 26 into the hex number 0x26.

    Bit Manipulations in Hours
    We can immediately write the minutes and seconds numbers to the registers.  The hour byte needs a little work.  From the data sheet for the DS1307 we read "The DS1307 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12-hour or 24-hour mode-select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with logic high being PM. In the 24-hour mode, bit 5 is the second 10-hour bit (20 to 23 hours). The hours value must be re-entered whenever the 12/24-hour mode bit is changed."

    If we want to be in 12 hour mode, bit we need to set bits 5 and 6 - 5 specifies AM or PM - 6 defines the mode and must be 1 if we are in 12 hour mode.  5 must be set if we are entering a PM hour.  In 24 hour mode 6 is 0, and 5 is already either 0 or 1 if the hour is greater than 19.  That means we are already set to do 24 hour mode, but if we wish to change to 12 hour mode, we need to make some changes.

    We need to change the way data is entered - that's simple enough, but we also need to know how to set or clear bits.  To do this we must understand some simple bit manipulation routines.  We can use the bitSet(Nmbr, bit) and bitClear(Nmbr, bit) functions that are built into the Arduino IDE.  However, this is an excellent opportunity to explore some new and very interesting bit manipulations.

    First the AND and OR functions. When we want to AND two numbers we use the "&" symbol.  The OR function uses "|".  When we AND two numbers together, each bit in the first number is anded with the same bit in the second number - The rule is:
       1 & 1 = 1, 1 & 0 = 0, 0 & 0 = 0, 0 & 1 = 0.

    Consider the two binary numbers B011011001 & B01101011 = B011010001.  Notice how when there is a 0 in either number the result has a 0 in that place - to get a 1 you must have a 1 in that place in the first number AND the second number.

    The OR function follows a different rule:
    1 & 1 = 1, 1 & 0 = 1, 0 & 0 = 0, 0 & 1 = 1.

    In this case a 1 in either the first number OR the second number will give a 1 as a result.

    B011011001 | B01101011 = B011011011

    To turn on a particular bit in a number, we use a "mask".  This is a particular binary string that is all 0s except for a 1 in the place where we want to change make sure there is a 1 in the answer.  In our problem, we want to turn on bit 6 in the hour register to set the operation to 12 hour mode.

    We would use the mask B01000000.  This number OR with Hrs will give us a number that has a 1 in the 12/24 select bit.  Note the "B" in front of the binary number - The easiest way to define a mask is to write it in Binary.  Just as "0x" in front of a hex number will tell the compiler the digit that follow are hex digits, the "B" in front of a series of 1s and 0s will tell the compiler that what follows is binary.

    Hrs | B01000000 would give us the correct result. A 0 in the mask leaves the Hrs unchanged, but a 1 forces the result to have a 1 in that position.

    To turn this bit off, we could use an and mask B10111111 an AND this with Hrs to put us in 24 hour mode.

    Hrs & B10111111.  A "1" in the mask leaves the Hrs unchanged, but a 0 forces the result to have a 0 in that position.

    *********************************************************************************

    Most of the people doubts about How to select the Hour in 12 or 24 mode , giving a sample example as follows

    Hours = 0x40 | Hours;  
    Just masking with 0x40

    Thats it ,Here the 6 the bit position set as High so RTC selected 12 Hours mode

    More details from here
    http://www.edaboard.com/thread341519.html

    DS1307_Tutorials

    By
       The real time clock chip, DS1307, can be connected to the Arduino and used in a wide range of projects that require the processor to know the time and date.  Using this device is easy if you have a basic understanding of the Wire.h library functions and I2C communication protocol.  In this document we will discuss the basic operation of the device, how to set the date and time and how to read the information.  This document also includes several Arduino programs that can be referenced to get started with the RTC.
    [ads-post]


    RTC overview
    The DS1307 chip is a simple device integrated circuit that counts clock pulses.  The chip requires a 32.768 kHz oscillator commonly known as a watch crystal.  You will remember the binary number 0x7FFF is 32768. This means that a 15 bit counter would count from 0 up to its maximum value an role over to 0 again in exactly 1 second, if clocked at this frequency.  The chip includes a built in processor which includes the counter and several registers that keep track of the day, the date and the time.  The device also has additional memory for storage.

    The design is intended to use very little power, less than 0.5µA and it runs on 5 volts, but if the supply voltage drops to 3, the oscillator will continue to operate and keep accurate time.  The device is intended to have a CR1220 back up battery to support continued operation when the power has been unplugged.

    The DS1307 interfaces with the outside world using the I2C protocol, making it easy to program and read with the Arduino I2C internal peripheral.  The Arduino I2C port uses analog pin A4 and A5 as the data and clock lines.  The Arduino TwoWire class is loaded with the Wire.h include which activates the I2C peripheral and includes the routines that are used in this product description.


    RTC registers
    Registers are 8 bit (1 byte) memory locations that can store values. The RTC uses the I2C interface to write and read bytes from these registers.  The DS1307 has 0x37 (64) of these registers, however only the first 8 are important to the operation of the device.

    Understanding and using BCD and ASCII
    The register data is stored in BCD (Binary Coded Decimal) format.  This means that each digit of a number is given 4 bytes (1 nibble).  Each of these nibbles is allowed to use values 0 to 9 or 0000 to 1001.  This means that when we write a number in hex, we can read the number as a decimal number.

    The BCD number 0011 0100 is understood to be 34 in decimal. BCD is seldom used, but this device make use of it.  To format the data correctly one must make use of the ">>" shift right and "<<" shift left operators to create numbers that will properly represent the information.  Also, it is necessary to be familiar with AND "&" and the OR "|" functions.  In addition, it is often more useful to think in of numbers in terms of hex and binary than in decimal.

    Consider the first register which contains the current seconds.  Suppose the current time is 7:44:26 - 7 AM, 44 minutes and 26 seconds.  To set this time correctly, the appropriate values must be written to the correct registers.  Register 00 contains the seconds value.  It needs to set to be the binary number 0010 0110 or hex 0x26.  The program must convert the decimal number 26 into the hex number 0x26.

    Bit Manipulations in Hours
    We can immediately write the minutes and seconds numbers to the registers.  The hour byte needs a little work.  From the data sheet for the DS1307 we read "The DS1307 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12-hour or 24-hour mode-select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with logic high being PM. In the 24-hour mode, bit 5 is the second 10-hour bit (20 to 23 hours). The hours value must be re-entered whenever the 12/24-hour mode bit is changed."

    If we want to be in 12 hour mode, bit we need to set bits 5 and 6 - 5 specifies AM or PM - 6 defines the mode and must be 1 if we are in 12 hour mode.  5 must be set if we are entering a PM hour.  In 24 hour mode 6 is 0, and 5 is already either 0 or 1 if the hour is greater than 19.  That means we are already set to do 24 hour mode, but if we wish to change to 12 hour mode, we need to make some changes.

    We need to change the way data is entered - that's simple enough, but we also need to know how to set or clear bits.  To do this we must understand some simple bit manipulation routines.  We can use the bitSet(Nmbr, bit) and bitClear(Nmbr, bit) functions that are built into the Arduino IDE.  However, this is an excellent opportunity to explore some new and very interesting bit manipulations.

    First the AND and OR functions. When we want to AND two numbers we use the "&" symbol.  The OR function uses "|".  When we AND two numbers together, each bit in the first number is anded with the same bit in the second number - The rule is:
       1 & 1 = 1, 1 & 0 = 0, 0 & 0 = 0, 0 & 1 = 0.

    Consider the two binary numbers B011011001 & B01101011 = B011010001.  Notice how when there is a 0 in either number the result has a 0 in that place - to get a 1 you must have a 1 in that place in the first number AND the second number.

    The OR function follows a different rule:
    1 & 1 = 1, 1 & 0 = 1, 0 & 0 = 0, 0 & 1 = 1.

    In this case a 1 in either the first number OR the second number will give a 1 as a result.

    B011011001 | B01101011 = B011011011

    To turn on a particular bit in a number, we use a "mask".  This is a particular binary string that is all 0s except for a 1 in the place where we want to change make sure there is a 1 in the answer.  In our problem, we want to turn on bit 6 in the hour register to set the operation to 12 hour mode.

    We would use the mask B01000000.  This number OR with Hrs will give us a number that has a 1 in the 12/24 select bit.  Note the "B" in front of the binary number - The easiest way to define a mask is to write it in Binary.  Just as "0x" in front of a hex number will tell the compiler the digit that follow are hex digits, the "B" in front of a series of 1s and 0s will tell the compiler that what follows is binary.

    Hrs | B01000000 would give us the correct result. A 0 in the mask leaves the Hrs unchanged, but a 1 forces the result to have a 1 in that position.

    To turn this bit off, we could use an and mask B10111111 an AND this with Hrs to put us in 24 hour mode.

    Hrs & B10111111.  A "1" in the mask leaves the Hrs unchanged, but a 0 forces the result to have a 0 in that position.

    *********************************************************************************

    Most of the people doubts about How to select the Hour in 12 or 24 mode , giving a sample example as follows

    Hours = 0x40 | Hours;  
    Just masking with 0x40

    Thats it ,Here the 6 the bit position set as High so RTC selected 12 Hours mode

    More details from here
    http://www.edaboard.com/thread341519.html

    ATmega Based MENU Building -LCD 16x2 -with 4 Button

    By
    A menu system Not fully completed only for learning the full code and proteus are available below to download for learning purpose thanking you 

    /*
    * push_button__lcdMenu.c
    *
    * Created: 7/30/2017 11:48:27 AM
    * Author: Krishna
    */

    #include
    #include "lcd.h"
    #include "delay.h"
    #include "button_key.h"
    # define F_CPU 1000000UL



    struct menu s1= {0}; //s1.menu_up-key =1;


    int main(void)
    { int a;
    struct menu s1= {0}; //s1.menu_up-key =1;
    const char *menu_display[10];
    menu_display[0] = " Select Menu";
    menu_display[1] = " Set Time";
    menu_display[2] = " Set Date";
    menu_display[3] = " Set Alaram";
    menu_display[4] = " Set Alaram ";
    //sub menu
    menu_display[5] = " Enter Time ";
    menu_display[6] = " Enter Date ";
    menu_display[7] = " Enter Alarm ";
    menu_display[8] = " Enter Alarm";
    LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7);
    LCD_Init(2,16);
    LCD_GoToLine(0);

    DELAY_ms(100);
    //LCD_Clear();
    while(1)
    {

    // key_display( key_value);
    menu_key_display (s1,menu_display);


    LCD_Clear();
    for(a=0; a<5 a="" d="" lcd_printf="" pre="" s1.time="">
    /*
    * button_key.c
    *
    * Created: 7/30/2017 12:02:39 PM
    * Author: Krishna
    */ #include
    #include "delay.h"
    #include "button_key.h"
    #include "lcd.h"

    void menu_key_display(struct menu s1,const char *menu_display[]);
    void UP_Down_Keyvalue(struct menu s1,int i,int j);

    /* Function Key Value For get key */
    int Key_pressed(void)
    {
    while(1){
    if (LEFT_S) { while(LEFT_S);return 1; }
    if (RIGHT_S){ while(RIGHT_S);return 2; }
    if (UP_S) { while(UP_S); return 3; }
    if (DOWN_S) { while(DOWN_S);return 4 ; }
    if (OK_S) { while(OK_S);return 5 ; }
    }
    }


    /* Function Key Value For Up Key & Enter*/

    void menu_key_display(struct menu s1,const char *menu_display[])
    {
    int ch;
    int a;
    int menu_position =0;
    LCD_DisplayString(menu_display[menu_position]);
    do{

    repat:
    ch = Key_pressed();
    if(ch==1||ch==2)
    {
    if(ch==2)
    { if(ch==2)
    { if(s1.menu_side_key==4)
    s1.menu_side_key = 0;
    LCD_Clear();
    LCD_GoToLine(0);
    LCD_DisplayString(*((++s1.menu_side_key)+menu_display));
    menu_position=1;

    }
    }
    else if(ch==1)
    {
    if(ch==1)
    {if(s1.menu_side_key==1 ||s1.menu_side_key==0)
    {
    s1.menu_side_key=5;
    }
    LCD_Clear();
    LCD_DisplayString(*((--s1.menu_side_key)+menu_display));
    menu_position=1;
    }
    }
    }

    if(menu_position==0)
    goto repat;
    }while(ch!=5);

    a = s1.menu_side_key;
    switch(a)
    {
    case 1: // set time
    {
    LCD_Clear();
    LCD_GoToLine(0);
    LCD_DisplayString(menu_display[5]);
    LCD_GoToLine(1);
    LCD_DisplayString(" HH:MM:SS:PM/AM");
    UP_Down_Keyvalue(s1,2,4);
    break;
    }
    case 2: // Set date
    {
    LCD_Clear();
    LCD_GoToLine(0);
    LCD_DisplayString(menu_display[6]);
    LCD_GoToLine(1);
    LCD_DisplayString(" DD:MM:YY");
    UP_Down_Keyvalue(s1,2,3);
    break;
    }

    case 3: // set alarm
    {
    LCD_Clear();
    LCD_GoToLine(0);
    LCD_DisplayString(menu_display[7]);
    LCD_GoToLine(1);
    LCD_DisplayString(" HH:MM:SS:AM/PM");
    UP_Down_Keyvalue(s1,2,4);
    break;
    }
    case 4: // set alarm
    {
    LCD_Clear();
    LCD_GoToLine(0);
    LCD_DisplayString(menu_display[8]);
    LCD_GoToLine(1);
    LCD_DisplayString(" HH:MM:SS:PM/AM");
    UP_Down_Keyvalue(s1,2,4);
    break;
    }
    }

    while(Key_pressed()!=5);


    }




    /* Function Key Value For UP_Down Key */
    void UP_Down_Keyvalue(struct menu s1,int i,int j)
    {

    int ch,lower,upper;
    do{
    if(j==4)
    {
    if(i==2)upper=1;
    if(i==3)upper=9;
    if(i==5)upper=5;
    if(i==8)upper =5;
    if(i==9)upper =9;
    }
    if(UP_S)
    {
    while(UP_S);
    if(s1.menu_up_key==upper)
    s1.menu_up_key = lower-1;
    LCD_GoToXY(1,i);
    LCD_Printf("%d",++s1.menu_up_key);
    s1.time[i-2]=s1.menu_up_key;
    }
    else if(DOWN_S) // down

    { while(DOWN_S);
    if (s1.menu_up_key==lower)
    s1.menu_up_key = upper+1;
    LCD_GoToXY(1,i);
    LCD_Printf("%d",--s1.menu_up_key);
    s1.time[i-2]=s1.menu_up_key;
    }
    if(RIGHT_S)

    { while(RIGHT_S);
    s1.menu_up_key=0;
    if(i==9) goto exit1;
    if(i==3||i==6)
    ++i;
    i++;
    }
    exit1:
    if (LEFT_S)
    { while(LEFT_S);
    s1.menu_up_key=0;
    if(i==2) goto exit2;
    if(i==5||i==8)
    --i;
    i--;

    }
    exit2:continue;


    } while (ch!=5); // if Okay key exit loop

    }






    https://youtu.be/bNwrHuY4Kxk

    More Posts

    gElectron. Powered by Blogger.

    Contributors

    16x2 LCD Interfacing with STM32,STM32F103C6

     16x2 LCD  Interfacing with STM32,STM32F103C6 lcd_init(); LCD_LINE1; lcd_String(" GeElectron"); LCD_LINE2; lc...

    Contact Form

    Name

    Email *

    Message *

    Contact us

    Name

    Email *

    Message *

    Follow Us

    https://www.facebook.com/gElectron-393939667321867/ FBbox/https://www.facebook.com/IVYthemes

    Comments

    [blogger]

    MKRdezign

    Test

    Latest

    [recent][newsticker]

    Technology

    Top Ads

    RECENT COMMENTS

    Subscribe Via Email

    Subscribe to our newsletter to get the latest updates to your inbox. ;-)


    Your email address is safe with us!

    RECENT COMMENTS