The MC9S12DG128 (hereinafter referred to as DG128) used in this Smart Car Invitational is an enhanced 16-bit microcontroller in the S12 series of microcontrollers launched by Freescale. It has rich on-chip resources and interface modules including SPI, SCI, IIC, A/D, PWM, etc. It has a wide range of uses in the field of automotive electronics applications. DG128 also has strong functions in Flash storage control and encryption, and encryption and decryption can be used in conjunction with third-party software.
The DG128 microcontroller uses an enhanced 16-bit HCS12 CPU, and the on-chip bus clock can reach up to 25MHz; on-chip resources include 8K RAM, 128K Flash, 2K EEPROM; SCI, SPI, PWM serial interface modules; the pulse width modulation module (PWM) can be set to 4 8-bit or 2 16-bit, and the logic clock selection frequency is wide. It includes two 8-channel 10-bit precision A/D converters, a controller area network module (CAN), an enhanced capture timer and supports background debugging mode. DG128 has two package forms: 112-pin and 80-pin. The 80-pin packaged microcontroller does not lead out a port for expansion, but only leads out an 8-channel A/D interface.
Common interface modules and external applications
PWM (Pulse Width Modulate) module: PWM pulse width modulation wave is a waveform that can be controlled by a program to control the waveform duty cycle, period, and phase. It is widely used in motor drive, D/A conversion and other occasions. The motor driver chip used in this Grand Prix is MC33886, and its input signal is a PWM signal. MC33886 controls the direction and speed of the motor according to the period and duty cycle of the PWM signal. The servos used in the Grand Prix are also controlled by PWM. When the period of the PWM signal is greater than a certain threshold value, the servo can be driven to work. By maintaining the period and adjusting the PWM duty cycle, the direction of rotation of the servo can be adjusted. In the absence of specific parameters of the motor and servo, a PWM output program with adjustable period and duty cycle can be written for testing.
A/D (Analog/Digital) module: The A/D analog-to-digital conversion module can be divided into three parts: IP bus interface, conversion mode control/register list, and custom analog quantity. The IP bus interface is responsible for connecting the module to the bus to achieve the purpose of the A/D module and general I/O. The conversion mode control register list contains all the registers that control the module. The custom analog quantity is responsible for realizing the conversion from analog quantity to digital quantity. In order to synchronize the A/D conversion with the external signal, the A/D has an external trigger conversion channel, and the user can select the trigger mode (edge trigger, level trigger).
The A/D module is equipped with a clock division mechanism. Users need to note that the maximum conversion clock of the A/D module is 2MHz, and the minimum conversion clock is 500KHz. Users need to check the internal bus clock of their own chips, and must make the conversion clock after division between the two, otherwise the correct conversion result may not be obtained. Users can set the conversion result to be signed or unsigned. For example, when Vrh is 5.12v and Vrl is 0v, the input is 5.12V, the 8-bit signed result is -$7F, and the unsigned result is $FF. The A/D module allows sequential conversion to be set, and the maximum sequential conversion sequence length is 8.
The A/D module may be used in the Grand Prix car model's recognition of the track. There are many implementation schemes for the front-end data acquisition system of the recognition circuit, such as infrared light-emitting diodes or CMOS cameras for data acquisition.
Codewarrior software usage
Codewarrior 3.1 for HCS12 is the recommended compiler software for the competition. "CodeWarrior for S12" is a software package for embedded application development of microcontrollers with HC12 or S12 as CPU. It includes integrated development environment IDE, processor expert library, full chip simulation, visual parameter display tool, project manager, C cross compiler, assembler, linker and debugger. In Codewarrior software, assembly language or C language, as well as mixed programming of the two languages can be used.
After the project is created, the loading address needs to be defined. The default.prm file is used to define the loading address of the target code. The user should modify this file according to the memory allocation of the microcontroller. The .prm file automatically generated by CodeWarrior defaults the RAM of DG128 to:
RAM = READ_WRITE 0x0400 TO 0x1FFF;
This default range must be modified because there is 1K of I/O register space and 2K of EEPROM space in this space. Using the default definition will lose 1K RAM and 2K EEPROM.
We modify the RAM space in the monitoring program:
RAM = READ_WRITE 0x2000 TO 0x3FFF;
Of course, you can also modify it to:
RAM = READ_WRITE 0x1000 TO 0x2FFF.
Users are advised to adopt our definition.
Additionally, we use:
STACKTOP replaces STACKSIZE
Because STACKSIZE 0x100 leaves 0x100 space at the low end of RAM, and STACKTOP 0x3F00 can define SP to the high end of RAM. However, if this definition method is used, the definition needs to be modified to: RAM = READ_WRITE 0x2000 TO 0x3EFF when defining RAM in the previous step. In addition, the function in Start12.c in the project file needs to be:
void __interrupt 0 _Startup(void) Medium
#ifdef _HCS12_SERIALMON
.......
.......
#endif
Comment out the two macro commands, making the initialization statements for the EEPROM and RAM start position control registers valid. In this way, the program can run normally after downloading.
Download the user program using the monitoring program:
The main function of the monitor program is to debug the application system hardware and underlying software. It is also called the debug program and is the most basic debugging tool. The DG128 has 128K Flash and 8K RAM, while the monitor program source code occupies less than 3K FLASH and 23 bytes RAM. This does not have a big impact on the space of the user program. The asynchronous serial port is used for communication services with the PC. The monitor program can use it, and of course the application program can also use it.
Downloading user programs to on-chip resources is a basic function of the monitoring program. The code of the DG128-based monitoring program developed by the Freescale MCU & DSP Application Research and Development Center of Tsinghua University is less than 4KB, and the starting address is $F000. It moves the interrupt vector table of $FF80 to EF80, and the order remains unchanged. Users can use the interrupt vector table at $EF80. This interrupt vector table has the same order as the interrupt vector table in the MC9S12DG128 manual, except that it is moved from $FF80 to $EF80. When the monitoring program starts, if the serial port does not receive data within 4 seconds, it will check whether $EFFE-$EFFF (user reset vector table) is FFFF. If not, it means that there is a user program in FLASH, and the program automatically switches to the user program pointed to by $EFFE-$EFFF. If the serial port receives data within 4 seconds after the program starts or $EFFE-$EFFF is $FFFF, the DEBUG monitoring program is entered. In this monitoring program, the F command downloads the program to FLASH, and can recognize S19 files in S1 or S2 format. After pressing the "F" key, the MCU on the development board waits to receive the data file from the serial port. Then select "Send" → "Send Text File", find the *.S19 file to be downloaded, and press "Open (O)". In this way, the file is downloaded to the FLASH. Note that the file type should be "All Files". When the prompt appears again, it means that the program has been downloaded.
Start running the program from the address of the PC register. You can use the Ctrl+P command to modify the PC pointer to the starting address of the program to be run. If it is an assembled code, you can start executing from the download address; but if it is a code compiled by C language, you need to add the address after 29 before executing it. This is because the project starts from START12.C and then executes the user's main.c. This is the internal regulation of CodeWarrior. Users only need to know it. The entry address of the user program is the code address defined by the user in the default.prm file plus 29. Then type the "G" command. At this time, the user program can be executed. If the user program cannot jump out of the main loop, press the reset button when you need to stop the user program.
Previous article:Realization of communication between touch screen and single chip microcomputer
Next article:Temperature controller based on 8-bit single chip microcomputer
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Practical Development of Automotive FlexRay Bus System (Written by Wu Baoxin, Guo Yonghong, Cao Yi, Zhao Dongyang, etc.)
- Typical Application Examples of LabWindowsCVI Data Acquisition and Serial Communication (with CD) (Example Detailed Explanation Series) (Li Jiangquan)
- ATmega16 MCU C language programming classic example (Chen Zhongping)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Microcontroller selection
- Made a tool to use serial port IAP to realize batch online upgrade program
- Things that electronic hardware engineers need to know
- MSP430 watchdog usage notes && how to use the watchdog monitoring program to run away in low power mode
- EEWORLD University ---- Automotive/Industrial Millimeter Wave Radar Sensors
- First day of work in 2021
- TL335x-EVM development board processor, FLASH, RAM, FRAM
- DSP2812 CMD detailed configuration example
- 【ESP32-Korvo Review】 01 Unboxing Experience
- PCB circuit board heat dissipation tips