The automatic temperature control phototherapy system is a medical physiotherapy instrument. Its principle is to use a single-chip microcomputer to control the thyristor to control the laser output device under high voltage for physiotherapy. While the laser output device is working, it performs real-time temperature detection on it, and uses the detected temperature condition to determine the conduction state of the thyristor, so as to achieve the purpose of changing the output power of the laser output device and obtain the best therapeutic effect.
According to the above characteristics, this paper selects the single bus digital temperature sensor DS18B20 for temperature acquisition and introduces the program code using DS18B20. In order to make the output power of the thyristor change continuously and evenly, this paper designs a programming method that uses external interrupts and timer interrupts to realize the thyristor phase shift triggering, which meets the needs of uniform and sensitive changes in the intensity of the therapeutic light.
2 Introduction to the Thermostatic Light Therapy System
2.1 System Structure Introduction
This system consists of 5 parts: CPU processing unit, keyboard input unit, LCD display unit, temperature measurement unit, and thyristor controlled laser output unit.
The CPU processing unit runs the system program to schedule all tasks. The keyboard is used to input system setting parameters and control state mode selection. The LCD provides a good operation interface for the system. The temperature measurement unit is responsible for real-time detection of the temperature of the laser output device. The thyristor control output unit controls the output of the laser output device according to the set parameters and the detected temperature. This article will introduce the software and hardware design of the temperature measurement unit and the thyristor control unit in detail.
2.2 System program flow introduction
The program flow of this medical system is as follows: the system first initializes the data, which mainly includes the setting of timer and external interrupt. After the initialization is completed, the external interrupt is turned on. Then the system collects temperature and determines the timer timing parameters according to the collected temperature and the system setting parameters. The timing parameters directly determine the size of the conduction angle when the phase-shift triggers the thyristor. Then the system collects temperature again, selects the timer timing parameters, and cycles in sequence.
During the system cycle, the system can be manually changed by pressing buttons. The operating parameters directly affect the selection of the timer parameters that control the conduction angle of the thyristor. The main flow chart of the system is shown in Figure 1 (a). When the system is executed in a cycle, the external zero-crossing pulse signal will cause the system to enter the external interrupt service program, thereby controlling the conduction of the thyristor.
Figure 1: System program flow chart
3. Introduction to the temperature measurement unit
Thermocouples or platinum resistors require amplifier circuits and A/D conversion to realize temperature signal acquisition. In order to simplify the system hardware design, a single-bus digital temperature sensor DS18B20 produced by DALLAS was selected.
The "one-line" bus interface provided by DS18B20 only needs one port for communication; the temperature measurement range is -55~+125℃, and the accuracy is ±0.5℃ within the range of -10~+85℃; the temperature is read out in 9~12-bit digital quantities with a resolution of 0.0625℃, which meets the requirements of this medical phototherapy system; at the same time, DS18B20 uses an ultra-small μSOP package, which is very small and can be directly applied to the front end of the laser. Since the "one-line" bus interface provided by DS18B20 only needs one port to communicate with the CPU, in terms of hardware, a port P2.0 of the microcontroller AT89C52 is connected to the DQ pin of DS18B20.
3.1 DS18B20 working principle and procedure
Before reading and writing DS18B20, the CPU first sends a reset pulse, a low-level signal with a minimum pulse width of 480μs; then the CPU releases the single bus and puts it in a receiving state. The single bus is pulled to a high level through a pull-up resistor. When DS18B20 detects the rising edge of the I/0 terminal, it waits for 15-60μs and then sends a response pulse (a low-level signal of 60-240μs) to the main CPU. The initialization subroutine is:
bit init_18b20(void);
{ bit presence; //Used to save the response signal of DS18b20 to CPU
DQ = 0; //Reset pulse low level
delay_20us(25); // Delay 500us
DQ = 1; //Reset pulse high level
delay_20us(4); //delay 80us
presence = DQ; //Save the status of DQ
delay_20us(20); //delay 400us
return (presence); //Return the status of DQ }
When the main CPU pulls the I/O line from high level to low level and keeps it for more than 1μs, it is regarded as the beginning of a read cycle. The output data of DS18B20 is valid within 15μs after the falling edge of the read timing. During this period, the main CPU should release the I/O line and put it in the read state to read the output data of DS18B20. After 15μs, the read timing ends and the I/O line becomes high level through the pull-up resistor. It usually takes at least 60μs to read one bit of data, and there must be at least 1μs recovery period between two bits of data. The subroutine for reading the temperature byte is: [page]
byte read_byte(void)
{byte i; //Variable used for loop self-increment
byte value = 0; //temporary variable used for shift operation
for (i=8;i>0;i--)
{value》》=1;
DQ = 0;
NOP_1uS; //Delay 1us No operation macro No operation macro
DQ = 1;
NOP_1uS; NOP_1uS; NOP_1uS;
if (DQ) value |= 0x80;
delay_20us(3); // delay 60us
}return(value); //Return the corresponding byte }
When the CPU pulls the I/O line from high level to low level, it is regarded as the beginning of a write cycle. There are two types of write timing: write 1 timing and write 0 timing. Write 1 or write 0 must be maintained for at least 60μs, and there is at least 1μs recovery period between two write cycles. DS18B20 samples within 15-60μs after the I/O line becomes low level.
If the I/O line is high, it is considered that a 1 is written; otherwise, it is considered that a 0 is written. When the main CPU starts writing a 1 cycle, it must pull the I/O line to a low level, then release it, and pull the I/O line to a high level within 15μs. When the main CPU starts writing a 0, it also pulls the I/O line to a low level and keeps it for 60us. The subroutine for writing bytes is:
void write_byte(char val) // "val" is used to pass the byte that needs to be written
{unsigned char i; // variable used for loop self-increment
for (i=8; i>0; i--)
{DQ = 0; NOP_1uS; NOP_1uS;
DQ = val&0x01;
delay_20us(5); //delay time 100us
DQ = 1;val=val/2; //Shift right one bit
}delay_20us(5); //delay time 100us }
Each access to the DS18B20 begins with initializing the device, followed by issuing ROM commands and function commands. Initializing the device causes the host to receive a response signal. The ROM command is associated with the unique 64-bit ROM code of each slave device, allowing the host to specify the operation of a slave device when multiple slave devices are connected to the 1-Wire bus. These commands also allow the host to detect how many slave devices are on the bus and their device types, or whether any device is in an alarm state.
This system is a single-point system with only one temperature sensor. By using the SKIP ROM command, the host does not have to send a 64-bit serial number, thus saving a lot of time. After the ROM command, the host can issue a specified function command (temperature conversion, read register, etc.) to complete the operation. The program for reading temperature in this system is:
unsigned int Read_Temperature(void)
{ unsigned char a, b; // variables used to store temperature data
if (init_18b20() == 0)
{write_byte(0xCC); //Send Skip ROM instruction
write_byte(0x44); //Send temperature conversion instruction
delay_20us(1);
if (init_18b20() == 0)
{write_byte(0xCC); //Send Skip ROM instruction
write_byte(0xBE); //Send the command to read the temporary register
a=read_byte(); //Read the lower eight bits of temperature data
b=read_byte(); //Read the high eight bits of temperature data
temperature=((b*256+a)/16); //Calculate the decimal temperature value
}}return(temperature);}[page]
4. SCR control output unit
4.1 Hardware Design of Thyristor Control Unit
Figure 2: Schematic diagram of thyristor control output unit
This system uses the MOC3021 photoelectric isolation circuit to trigger the thyristor. The AT89C52 uses the P21 pin to connect to the 2nd pin of the MOC3021. Figure 2 (a) is the schematic diagram of the trigger circuit. The MOC3021 is a bidirectional thyristor output type photocoupler, which is used to isolate the microcontroller system from the external bidirectional thyristor.
4.2 Zero-crossing detection circuit design
The zero-crossing detection circuit is used to capture the zero-point signal of the alternating voltage. In order to start the timer at the zero-crossing point, the thyristor is triggered when the timing time is reached. The zero-crossing detection circuit is shown in Figure 2 (b). Two TIL117s are connected to the 18V AC power. The two TIL117s turn on the transistor T when the voltage reaches 0.3V in the positive and negative cycles of the AC power, respectively, so that the collector of the transistor T generates a pulse signal near the zero point of the AC power.
4.3 Design of SCR phase-shift trigger program
The zero-crossing detection circuit generates two zero-crossing voltage pulse signals in each cycle of the alternating voltage, causing the AT89C52 to generate an external interrupt. The timer timing is started in the interrupt service program. The timer timing time is less than the interval between the two zero-crossing pulse signals, that is, 10ms, so that the timer interrupt can work before the next external interrupt comes.
In the timer interrupt service program, the thyristor is triggered and a new time constant of the timer is loaded. Wait for the external interrupt triggered by the next zero-crossing pulse signal to start a new cycle of thyristor triggering. The program flow chart is shown in Figure 1 (b).
The falling edge generated by the zero-crossing detection circuit is used as an external interrupt signal. In the interrupt program, it is determined whether to start the timer according to the power output of the system at this time. If the power output is non-zero, the timer is started for timing.
void guicontrol(void)interrupt 2
{ if (power! = 0) //Judge whether the load power output is zero, if not zero, enter
{DT=1; //Turn off the thyristor output, DT is the P21 pin of AT89C52
TR0=1; //Start timer } }
When the timer interrupt occurs, the timer is stopped, and the new timing time constant that changes in real time according to the detected temperature and the power setting of the system in the main control flow of the program is loaded into the interrupt function to trigger the thyristor to conduct. The thyristor conduction time will last until the end of each half cycle of the load current.
void time0 (void) interrupt 1
{ TR0=0; //Stop the timer
TH0=timehigh; //Load new timer timing constant
TL0=timelow;
DT=0; //Trigger the thyristor to turn on, DT is the P21 pin of AT89C52
TF0=0; //Clear the timer overflow flag }
5 Conclusion
This article describes the design principle of temperature measurement and control in medical systems. The single bus digital sensor DS18B20 is selected as the temperature sensor to simplify the circuit. A programming method for realizing thyristor phase shift triggering is designed, and the specific application circuit and software design are given. The adopted design scheme makes the hardware of the medical system simple and practical, and the reliability is increased.
Previous article:Design of temperature measurement system based on single chip microcomputer and PC serial port communication
Next article:Classroom lighting energy-saving control system based on STC89C51
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to speed up the IO port flipping speed
- The National Day holiday is over, why are holidays always so short?
- [TI recommended course] #[High Precision Laboratory] Interface: RS-485#
- 【TI recommended course】# TINA-TI training course#
- What is the difference between Tx and INTX in the attached picture?
- Amplifier Circuit
- MCU、DSP、GPU、MPU、CPU、DPU、FPGA、ASIC、SOC、ECU、NPU、TPU、VPU、APU、BPU、...
- Which model should be used to replace transistor 8550, 8050, IN4148 when simulating in MULTISIM?
- E-book "The Beauty of Mathematics" 2nd Edition
- Analysis of ZigBee Terminal Direct Join Method