FSK modulation and demodulation technology based on MSP430

Publisher:创新思绪Latest update time:2016-10-10 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
First of all, what is FSK? FSK (Frequency-Shift keying) is translated into Chinese as frequency shift keying, which uses the frequency change of the carrier to transmit digital information.
FSK can convert frequency information into digital information, which is called FSK demodulation; and converting digital information into frequency information is called FSK modulation. So what can FSK do? FSK has a very "cool" function - it can communicate with the audio port. Whether it is an Android phone or an iOS phone, all can achieve data communication with the phone through FSK modulation and demodulation technology. The Android system is fine, and it can also communicate directly through the USB port, but Apple's iOS has not developed a USB protocol. If you want to communicate directly with Apple products such as iPhones, in addition to spending a lot of time and money to do MFI certification, you can only do it through audio. The "Karaca" that was very popular a while ago took this approach.
Let's start talking about FSK modulation and demodulation technology. Data transmission can be synchronous or asynchronous. For point-to-point connections, asynchronous transmission usually has a start bit and a stop bit. In the figure below, you can see: ASCII code 'K' (0x4B) binary digital information is represented in frequency information.
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
It can be seen that the binary information '0' is represented by f1 in frequency, and the binary information '1' is represented by f2 in frequency. Therefore, to realize FSK information modulation, it is only necessary to generate the frequency of f1 for the binary information '1' in a 1-bit length period, and the frequency of f2 for the binary '0' in a 1-bit length period; and for FSK modulation, judging whether the frequency is f1 or f2 can determine whether it is binary '0' or binary '1'.
Next, let's talk about the idea of ​​FSK modulation and demodulation based on MSP430.
1 FSK modulation
Serial port 0 (USART0) is used as the interface between the user application software and the modem. We configure serial port 0 for asynchronous transmission with a baud rate of 300 bit/s. When data is written into the serial port buffer U0TXBUF, the serial port starts to output the corresponding bit stream (including 1 start bit, 1 stop bit, 8 data bits, and sent in LSb form) on the serial port 0 transmit pin. You can take a look at the FSK modulation module of MSP430:
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
  The serial port 0 output pin is directly connected to the P1.3 pin. The capture/compare module CCR2 of timer A is configured in comparison mode. Timer A is configured as a timing task at the frequency of Timer_A.CLK. Through the cooperation between the timing of timer A and the capture/compare module CCR2, a PWM signal of the corresponding frequency is triggered and output at the P1.7 pin. The half-period of PWM can be calculated by the following formula:FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
  Pin P1.3 is configured as an interrupt input. When P1.3 receives a signal sent by serial port 0, it enters the interrupt service routine of the P1.3 pin. The flowchart of the interrupt program is as follows:
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
By reading the interrupt trigger edge selection bit P1IES3 of P1.3, the interrupt service program can determine whether the interrupt is caused by the falling edge trigger or the rising edge trigger. If the interrupt is caused by the rising edge trigger, it means that the signal received by P1.3 is '1', otherwise the signal received by P1.3 is '0'. Therefore, when P1.3 detects a falling edge, the PWM signal of the frequency f1 corresponding to the signal '0' is output at pin P1.7; when P1.3 detects a rising edge, the PWM signal of the frequency f2 corresponding to the signal '1' is output at pin P1.7. The conversion result is shown in the figure below:
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
The specific implementation code in MSP430:

#pragma vector=PORT1_VECTOR
__interrupt void P1_ISR(void) {
if(UART_COM_PORT_IFG & MODULATOR_DIGITAL_IN) { // isr caused by MODULATOR_DIGITAL_IN ?
if(UART_COM_PORT_IES & MODULATOR_DIGITAL_IN) {// caused by high-low transmission ?
BitFreq = _1850HzBitFreq; // load logical 0 value into modulation register
LED_PORT_OUT &= ~DATA_LED; // LED on
UART_COM_PORT_IES &= ~MODULATOR_DIGITAL_IN;// change pin isr edge sensivity
} else {
BitFreq = _1650HzBitFreq; // load logical 1 value into modulation register
LED_PORT_OUT |= DATA_LED; / / LED off
UART_COM_PORT_IES |= MODULATOR_DIGITAL_IN; // change pin isr edge sensivity
}
UART_COM_PORT_IFG &= ~MODULATOR_DIGITAL_IN; // clear interrupt flag
} else {
UART_COM_PORT_IFG = 0;
}
}

2 FSK demodulation
After the operational amplifier amplifies the signal, the received frequency signal is transmitted to the comparator through pin P2.3. Comparator A compares the received signal with the internal reference voltage Vcc/2. The frequency of the received signal can be calculated through the capture/compare 1Timer_A.CCR1 module of timer A. The following is the flowchart of the CCR1 capture interrupt service program.
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
 The interrupt service program calculates the time between two adjacent rising edges or two adjacent falling edges, that is, calculates the period value of the signal, and then compares it with the period value of 'MARK' (980Hz, '1' signal) and 'SPACE' (1180Hz, '0' signal) (of course within a certain error range) to determine whether the received signal should be a '0' signal or a '1' signal. The period value can be calculated according to the following formula:
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
 The following table gives the error range of frequency mismatch:
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
 MSP430 related code:

pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A1(void) {

static signed int Prev_negEgdeCapture = 0;
static signed int Prev_posEgdeCapture = 0;
static unsigned char EdgeCounter = 0;
signed int CCR1_Capture;
signed int Capture_Diff;

switch(TAIV) {
// CCR1 interrupt handler
case 2:
CCR1_Capture = TACCR1;
if(ModemStatusReg & POSITIVE_EDGE) {
Capture_Diff = CCR1_Capture - Prev_posEgdeCapture;
Prev_posEgdeCapture = CCR1_Capture;
ModemStatusReg &= ~POSITIVE_EDGE;
} else {
Capture_Diff = CCR1_Capture - v_negEgdeCapture;
Prev_negEgdeCapture = CCR1_Capture;
ModemStatusReg |= POSITIVE_EDGE;
}

if(Capture_Diff > RX_FREQ_CHN1_SPACE-CHN1_MARGIN && Capture_Diff < RX_FREQ_CHN1_SPACE+CHN1_MARGIN) {
if(HandshakeStateMachine == DetectOnes)
EdgeCounter = 0;
// 0 detected
zeros++;
ModemStatusReg |= OFF_HOOK;
} else if(Capture_Diff > RX_FREQ_CHN1_MARK-CHN1_MARGIN && Capture_Diff < RX_FREQ_CHN1_MARK+CHN1_MARGIN) {
// handle detection of binary ones during negotiation handshake
if(HandshakeStateMachine == DetectOnes) { // are we performing the negotiation handshake?
EdgeCounter++; // increment counter
if(EdgeCounter == DetectTime_Chn1) { // sufficient edges detected?
HandshakeStateMachine = OnesDetected; // change to next negotiation handshake state
}
}
// 1 detected
ones++;
ModemStatusReg |= OFF_HOOK;
}
if( zeros>=6 && ModemStateMachine == DataMode && !(ModemStatusReg & STARTBIT)) {
ModemStatusReg |= STARTBIT; // startbit detected
BitCounter = 0;
zeros = 0; // reset counters
ones = 0;
UART_COM_PORT_OUT &= ~DEMODULATOR_DIGITAL_OUT; // show startbit to UART
LED_PORT_OUT &= ~DATA_LED;
TACCTL0 = CCIE;
TACCR0 = CCR1_Capture + BAUDRATE;
}
break;
}
}
In the code, as long as 6 'SPACE' ('0' signal) are detected, it means that the start bit of the data has been received. At this time, the capture/compare block of the timer Timer_A.CCR0 is set to the comparison mode, and the data is received through the pin P2.3. As soon as the data is received, the timer interrupt with a timing of 1/300s is triggered. In this interrupt function, the high and low levels of the pin P1.2 are set according to whether the 'SPACE' signal or the 'MAKR' signal is received. The specific program flow chart is as follows:
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
The code implemented by MSP430 is as follows:

#pragma vector=TIMERA0_VECTOR
__interrupt void TA_CCR0_ISR(void) {

static unsigned int HandshakeCounter = 0;

// DataMode
if((ModemStatusReg & STARTBIT) && ModemStateMachine == DataMode) {
BitCounter++;
if(BitCounter == 9) { // processed one byte ?
TACCTL0 = 0; // stop bit detection trigger
ModemStatusReg &= ~STARTBIT;
UART_COM_PORT_OUT |= DEMODULATOR_DIGITAL_OUT; // show stopbit to UART
LED_PORT_OUT |= DATA_LED; // LED off
} else {
if(ones >= zeros) {
UART_COM_PORT_OUT |= DEMODULATOR_DIGITAL_OUT; // show 1 to UART
LED_PORT_OUT |= DATA_LED; // LED off
} else {
UART_COM_PORT_OUT &= ~DEMODULATOR_DIGITAL_OUT;// show 0 to UART
LED_PORT_OUT &= ~DATA_LED; // LED on
}
}
zeros = 0;
ones = 0;
}

.......

}

Pin P1.2 successfully converts the original frequency signal into a binary digital signal, and then directly connects pin P1.2 to the receiving pin of serial port 0, so that we can directly read the received data in the serial port buffer. The graph after signal conversion is as follows:
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
 The FSK demodulation process can be represented by the following diagram:
FSK modulation and demodulation technology based on MSP430 - ziye334 - ziye334's blog
Summarize
The above mainly talks about the idea of ​​implementing FSK modulation and demodulation with code, but if you want to make a product, you still need to work hard. For example, if you want to make a product similar to "Karaca", in addition to writing FSK modulation and demodulation code on the microcontroller side, you also need to write related software on the mobile phone side. Generally speaking, this requires at least two people, one to program the relevant part of the microcontroller, and the other to program the mobile phone software, because there are very few experts who are proficient in both.
Keywords:MSP430 Reference address:FSK modulation and demodulation technology based on MSP430

Previous article:Design of low power portable thermometer based on MSP430
Next article:MSP430 PWM

Recommended ReadingLatest update time:2024-11-16 18:01

Design of reversing radar based on TI MSP430
  With the increasing requirements for the intelligence of automobile assisted driving systems and the networking development of automobile electronic systems, new reversing radars should be able to continuously measure and display the distance to obstacles, and have communication functions to send data to the vehicle
[Microcontroller]
Design of reversing radar based on TI MSP430
MSP430F5438 study notes TA1 overflow interrupt plus compare match interrupt
// Clock defaults   // FLL clock FLL select XT1   // Auxiliary clock ACLK selects XT1 32768Hz   // Main system clock MCLK selects DCOCLKDIV 8000000Hz   // Subsystem clock SMCLK selects DCOCLKDIV 8000000Hz   //TA1 selects ACLK, the maximum count value is 65535   //Compare the match value to 32768   // CCR0 interrupt P4
[Microcontroller]
msp430 working notes 3
2. Application design of MSP430G2553 (I) Design of frequency meter   1. The frequency meter can be realized by the following methods: frequency measurement method, period measurement method, and equal-precision frequency measurement method. Generally, the period measurement method is more accurate for low frequencie
[Microcontroller]
Application of MSP430 in power measurement, control and protection products
     MSP430F149 (hereinafter referred to as "F149") is an ultra-low power Flash 16-bit RISC instruction set microcontroller launched by Texas Instruments (TI). F149 has rich internal hardware resources and is an industrial-grade chip with extremely high cost performance. In application, F149 does not need to be expand
[Microcontroller]
Application of MSP430 in power measurement, control and protection products
Design of MSP430 Mixed Voltage and Logic System
1. Introduction In recent years, the continuous progress and development of semiconductor manufacturing technology has provided power and guarantee for the widespread application of portable electronic products. Portable devices require the use of devices with small size, low power consumption and low battery co
[Microcontroller]
Design of MSP430 Mixed Voltage and Logic System
MSP430F2131 reads and writes DS1991
0|-->LED // // A. Dannenberg // Texas Instruments , Inc // January 2006 // Built with IAR Embedded Workbench Version : 3.40A //*************************************************************************** #include "msp430x20x1.h" #define TM_OUT(level) P2OUT = ((unsigned int)level) ? (P2IN|BIT4) : (P
[Microcontroller]
MSP430F5438 study notes basic io
1. Familiar with the clock system of MSP430 2. Operate GPIO // Clock defaults   // FLL clock FLL select XT1   // Auxiliary clock ACLK selects XT1 32768Hz   // Main system clock MCLK selection DCOCLKDIV 1048576Hz   // Subsystem clock SMCLK selection DCOCLKDIV 1048576Hz   // If XT1 fails to start, ACLK automati
[Microcontroller]
How to Make a Line Following Robot Using the MSP430 Launchpad
Line follower is one of the popular robotics projects among students and beginners because of its simplicity. It follows a line, either black or white, depending on how you program your microcontroller. Here, we have used the launchpad to make a line following robot, which follows the black line. Required Mater
[robot]
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号