An AC frequency detection system based on MSP430 single chip microcomputer

Publisher:朱雀Latest update time:2012-01-06 Keywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

Since frequency signals have the advantages of strong anti-interference, easy transmission, and high measurement accuracy, many non-frequency sensor signals are converted into frequency quantities for measurement and processing. Therefore, frequency measurement methods are attracting more and more attention and research.

Frequency measurement is one of the most basic measurements in the field of measurement and control systems. The most commonly used instrument for measuring signal frequency today is the frequency meter. During the measurement process, the frequency meter requires a time base signal as the time base for measuring the signal frequency. The time base signal is generally generated by a local oscillator circuit. Although quartz crystal oscillators are now commonly used, the accuracy of the time base signal cannot be guaranteed. Therefore, the measurement accuracy of the frequency meter becomes a problem. There are two traditional frequency measurement methods [1] : one is the frequency measurement method, which measures the number of repeated changes N of the measured signal within a certain time interval T, and the frequency is obtained; the other method is the period measurement method, which measures the number of standard high-frequency signals f within one cycle of the measured signal, and the measured frequency is obtained.

This paper introduces a width measurement method [2] . With the help of the photoelectric coupling principle, the AC signal is converted into a periodic pulse signal. By capturing the falling edge of the pulse signal and counting it with a timer, the period of the pulse signal can be obtained by the difference between the two counts, and the frequency of the measured AC signal can be calculated.

2 Hardware Circuit Design

The tasks completed by the hardware circuit are:

(1) The design of the analog circuit part is to convert the signal. The AC signal can be converted into a periodic pulse signal through analog devices such as a rectifier bridge and a photocoupler.

(2) The design of the digital circuit part is to detect the signal. The 16-bit timer A inside the MSP430 microcontroller has a pulse capture function, which can detect the duty cycle of the pulse signal.

Figure 1 is its basic structure diagram.

2.1 Design of analog circuit

Figure 2 shows the principle of the analog part. The following mainly describes the working principle of the circuit:

Considering that the AC signal may contain a certain amount of DC signal, and the DC signal will cause the AC waveform to move up or down, this may cause the original AC signal to have no zero point, and there is no question of zero-crossing detection or periodic pulses. Therefore, according to the actual situation of the AC signal, an appropriate capacitor should be set at the outlet of the AC signal to play a DC isolation role.

R1 and R2 are current limiting resistors to protect the voltage regulator, diode, and optocoupler behind them within the rated power consumption range. Since the AC signal source here is a 220V AC sinusoidal signal, the resistance of R1 and R2 should be relatively large and the power should be relatively large. The system uses a 1W resistor.

D1 and D2 are Zener voltage regulators, whose main function is to limit the voltage and protect the rectifier diodes of the rectifier bridge so that their reverse voltage is within the range. The voltage regulator model selected in this system is 1N4736, and its voltage regulation range is far less than the reverse withstand voltage of the rectifier diode. Figure 3 shows the terminal voltage of the voltage regulator (i.e., Vi1-Vi2 in Figure 1) waveform.

D3 is a rectifier bridge, which performs full-wave rectification on the AC power to make the current direction constant. Figure 4 shows the voltage waveform at both ends of the rectifier bridge (i.e., V1-V3 in the figure).

U2 is a photocoupler, which has two functions: signal conversion function, converting the rectified AC signal into a pulse signal; strong and weak current isolation function, which makes the strong current part and the weak current part electrically isolated, so that when the strong current part fails, the weak current circuit behind it, including the single-chip computer system, will not be damaged. The model used in this system is 4N25 , which has good switching characteristics, and its switching time can be adjusted through the base resistance. Figure 5 shows the switching characteristics of its base resistance under a given environment [3] . It can be seen from Figure 5 that when the base resistance R be is about , its comprehensive time index is the best, that is, the switching characteristics are better, so the base resistance (R5) in this system is taken.

The collector-emitter voltage (V5) waveform is shown in Figure 6.

Q1 is a transistor, and its function is to convert the pulse signal of V5 into high and low levels (0-3.3V) that can be recognized by the single-chip microcomputer. Therefore, Q1 must work in the switching state, that is, in the process of constantly switching between the saturation state and the cut-off state. The selection of the resistance values ​​of resistors R6 and R7 in the system is mainly to make the transistor work in the switching state. Figure 7 shows several indicators of Q1 working in the switching state. The current r6[i] on R6 = Ib, the current r7[i] on R7 = Ic, V5 = Vbe, and V6 = Vce.

It can be seen from Figure 7 that the transistor works in a saturated state, and in a cut-off state, it has a good switching characteristic.

TA0 directly enters the microcontroller, and R8 is a current limiting resistor to prevent excessive current from entering the microcontroller.

2.2 Design of digital circuit

The main chip used in the system is the low-power single-chip microcomputer MSP430F449 from Texas Instruments . MSP430F449 is a powerful single-chip microcomputer in the MSP430 series. It adopts the von Neumann system, RISC instruction structure, and 16-bit arithmetic unit width. It integrates 60KB of FLASH program memory, 2KB of SRAM data memory, multiple 16-bit timer/capture/comparator, 2 serial ports, 12-bit analog-to-digital converter, JTAG program download, online debugging interface, watchdog timer, etc. 48 I/O multi-function ports, of which P1 and P2 have bit interrupt function. Therefore, this single-chip microcomputer has the characteristics of fast instruction execution speed, powerful functions, simple external circuit, low power consumption, perfect power saving management method, and is positioned for embedded system applications [4] [5] .

In this system, the main functional module of the microcontroller used is the 16-bit timer A. Its internal pulse capture has the following characteristics [6] :

(1) 16-bit counter, 4 working modes;

(2) A variety of optional counter clock sources, including slow clock, fast clock and external clock;

(3) Capture/compare registers with multiple configurable inputs and multiple configurable output units with 8 output modes;

(4) It can not only capture the time when the external event occurs, but also lock the high and low levels when the external event occurs, which brings great convenience to our design;

(5) Serial communication can be supported in hardware.

3 Software Design [7] [8] [9]

The task of software design is mainly to set the initialization of Timer A, and the software is programmed in C language. When Timer A works in capture mode, when the capture condition (trigger mode) is met, the hardware automatically writes the data in the counter TAR into the capture/compare register CCR0. Figure 8 is the system software flow chart.

In this system, the timer uses continuous counting mode and the capture method uses falling edge capture. System initialization includes the selection of system frequency fs (1MHz) and the setting of the control register of Timer A. The registers that need to be set are the control register TACTL and the capture/compare control register CCTL0. The Timer A interrupt function is triggered when a capture occurs. First, the difference between the value in CCR0 and the variable LastCCR0 is calculated. LastCCR0 is the value of register CCR0 recorded at the last capture. The initial value of CCR0 is 0. The loop is triggered five times, and the difference between the five times is saved in the array Timervalue[]. Considering that the signal does not necessarily start from zero when the counter starts counting, the actual calculation should start from the second trigger, so that four pulse periods can be calculated, and then the average pulse period is calculated. The average period is the half period of the measured AC signal, and then its frequency can be obtained. It can be expressed as:

4 Conclusion

This paper proposes a zero-crossing detection circuit, and selects electronic components with corresponding parameters according to actual needs. At the same time, the pulse capture function of the MSP430 microcontroller is used to realize the detection of the frequency of the AC signal. The system has high detection accuracy and strong real-time performance for the frequency of low-frequency AC signals, and has certain practical application value. At the same time, the zero-crossing detection circuit introduced in this paper has a wider application. By using the multi-channel PWM output unit of the capture/comparator inside the Timer A of the MSP430 microcontroller, certain control functions can be realized.

Innovation of this article: This article proposes an AC frequency detection system based on the width measurement method. This system uses zero-crossing detection and the pulse capture function of the MSP430 microcontroller. Compared with previous frequency detection systems, it is more intuitive, more accurate, and more real-time.

References:

[1] Ma Xianguo, Improvement of frequency measurement method, Chinese Journal of Scientific Instrument, 2004.8, 25(4) Supplement: 120-122
[2] Zhao Zhanke, Application of single chip microcomputer in frequency detection of frequency shift signal, Microcomputer Information, 2004, 20(2): 76-77
[3] Toshiba Corporation, Semiconductor Technical Data (4N25)
[4] Hu Dake, Principle and application of MSP430 series ultra-low power 16-bit single chip microcomputer, Beijing University of Aeronautics and Astronautics Press, 2000.6
[5] Wei Xiaolong, MSP430 series single chip microcomputer interface technology and system design examples, Beijing University of Aeronautics and Astronautics Press, 2002.11
[6] Liang Yuan, Application of MSP430 MCU TIMER_A in product design, Proceedings of the 2001 International Academic Exchange Conference on Embedded Systems and MCUs
[7] Zhang Xi, Practical C language programming for MSP430 series MCUs, People's Posts and Telecommunications Press, 2005.9
[8] Liu Liqun, Design of ultra-low power data acquisition device based on MSP430 MCU, Automation Instrumentation, 2005.4, 26(4):30-31
[9] Liu Yuhong, Mixed programming of MSP430 MCU with C language and assembly language, Microcomputer Information, 2003, 19(10):56-57

Keywords:MSP430 Reference address:An AC frequency detection system based on MSP430 single chip microcomputer

Previous article:Design of Inclination Measurement System Based on Single Chip Microcomputer
Next article:Written for the junior students who are just starting to learn microcontrollers

Recommended ReadingLatest update time:2024-11-16 17:48

MSP430 Functional Module Detailed Explanation Series - System Clock
1. Clock source types LFXT1CLK low-frequency clock source - each MSP430 device has XT2CLK high frequency clock source——available in X13X, X14X, X15X, X16X, X43X, X44X, etc. DCOCLK digitally controlled RC oscillator 2. Clock Source Description ACLK auxiliary clock: ACLK is obtained by dividing the LFXT1CLK (low-frequen
[Microcontroller]
Several situations of MSP430 reset
---------------------------------------------------------------------- 1. Watchdog timeout reset The watchdog overflow reset is caused by not feeding the watchdog in time or not turning off the watchdog at the beginning of the program. The watchdog should be shielded during the debugging phase and the watchdog should
[Microcontroller]
MSP430 key interrupt
#include msp430f149.h      typedef unsigned char uchar;   typedef unsigned int uint;   #define then (P1IN & 0X0F)   #define wei_h P5OUT |= BIT5   #define wei_l P5OUT &= BIT5   #define duan_l P6OUT &= ~BIT6   #define duan_h P6OUT |= BIT6      uchar table = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x
[Microcontroller]
MSP430F5438 ADC12 Study Notes
1 Introduction In the past few days, I have practiced the ADC12 function of MSP430. Although the AD function on the chip is relatively simple, I have learned some "tricks". This "tricks" is the difference between MSP430F5438A and MSP430F5438. Here is an example to illustrate the use of the on-chip ADC. First, the func
[Microcontroller]
MSP430F5438 ADC12 Study Notes
MSP430 ADC12 1602 display
#include /*Two channels of data acquisition, one of which is very stable, with one or two jumps, but the other channel jumps a lot. My processing method is: 1. Connect all the extra channels, sort them after acquisition, take the middle one or several middle ones, add them and average them, which is suitable for in
[Microcontroller]
Using MSP430F41 MCU timer to realize signal sampling and PWM control
PWM control is widely used in various control systems, but the adjustment of pulse width is generally implemented by hardware. If a PWM controller is used or a PWM circuit is added to the system , the cost is high, the response speed is slow, and there are compatibility issues between the PWM controller and the system.
[Microcontroller]
Using MSP430F41 MCU timer to realize signal sampling and PWM control
MSP430 IIC bus program
#ifndef _I2C_H  #define _I2C_H  #define SDA_1       P4OUT|=0x02               //SDA = 1  #define SDA_0 P4OUT&=~0x02 //SDA = 0  #define SCL_1 P4OUT|=0x01 //SCL = 1  #define SCL_0 P4OUT&=~0x01 //SCL = 0  #define SDA_IN P4DIR&=~0x02; //I/O port is input  #define SDA_OUT P4DIR|=0x02 //I/0 port is output  #define J_SDA_1_o
[Microcontroller]
MSP430 IO port current source and sink problem
Digital input/output ports have the following features: □  Each input/output bit can be programmed independently. □  Any combination of input and output is allowed. □  All  8  bits of   P1  and  P2  can be set as interrupts. □  The input and output data registers can be operated independently. □  Pull-up or pull-d
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号