Multi-channel analog acquisition and PWM output method for VCU test
By using the UPDATE event of the embedded microcontroller and the basic timer in the VCU test to trigger DMA1 to generate a PWM signal, and setting the ADC sampling as an external trigger, the problem of excessive occupation of MCU performance in the existing technology is solved, and multi-channel Efficient integration of PWM output and analog acquisition.
Patent Information
- Application Number
- CN202410892063.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-10-29
AI Technical Summary
In the VCU test, it is difficult to implement as many PWM output channels and analog acquisition channels as possible on the same measurement board at the same time with existing technology, resulting in excessive occupation of MCU performance and the inability to use timers to trigger ADC sampling and PWM output at the same time.
Use an embedded microcontroller as the main controller, trigger DMA1 to generate a PWM signal through the UPDATE event of the basic timer, set the ADC sampling to be triggered by an external signal, configure the basic timer to automatically reload, and use DMA1 and DMA2 to implement ADC sampling and data storage, retaining advanced timers and general timers for PWM output.
It realizes 6 channels of PWM output and 16 channels of analog signal acquisition, making full use of MCU resources, avoiding additional consumption of MCU performance, and only performs data processing after the specified amount of data is completed.
Smart Images

Figure CN118859901A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of electrical parameter measurement, and in particular to a multi-channel analog acquisition and PWM output method for VCU testing. Background Art
[0002] When testing the automotive control unit VCU, it is necessary to apply a pulse width modulation (PWM) signal externally to simulate the working state of the external sensor, and it is also necessary to test the output voltage value of some functional pins of the VCU. In addition, the number of PWM signals required by different VCUs and the number of pins required to measure voltage are inconsistent. In order to facilitate testing and maximize the use of hardware resources, the two functions are implemented on the same measurement board, using STM32F103RCT6 as the main controller. Figure 2 It is understood that the main controller has two advanced timers TIM1 and TIM8, four general timers TIM2, TIM3, TIM4, TIM5, and two basic timers TIM6 and TIM7. In addition, the MCU can be configured with up to 16 channels of ADC sampling. Due to the multiplexing of some pins, the output pin of timer 5 and some sampling channels of ADC use the same pin, so the two functions cannot be used at the same time. Since the frequency and duty cycle of PWM output are adjustable, the timers that can be used for PWM output are only advanced timers and general timers, that is, only 6 PWM outputs can be generated at most. Therefore, in the case of ensuring 6 PWM outputs, ADC sampling is only 15 at most. Generally, in order to ensure full cycle sampling, ADC sampling will be triggered regularly. However, since the trigger mode of ADC can only use advanced timers or general timers, and these two timers need to be used as PWM outputs, they cannot be directly triggered by timers. The method of using basic timers to read regularly in interrupts can ensure the full cycle, but it will take up a lot of MCU processing time. Summary of the invention
[0003] The purpose of the present invention is to provide a method for multi-channel analog acquisition and PWM output for VCU testing, which provides as many PWM output channels and as many analog acquisition channels as possible without occupying too much performance of the MCU.
[0004] The specific technical solution is a method for multi-channel analog acquisition and PWM output for VCU testing. An embedded microcontroller is used in a measurement board as the main controller MCU; a main output pin and a main input pin are provided on the measurement board, and a connection is established between the main output pin and the main input pin outside the MCU; the measurement board has a built-in basic timer, and DMA1 is triggered by the UPDATE event of the basic timer, and the SET / RESET register of the GPIO is modified by DMA1 to generate a PWM signal with a duty cycle of 50% on the main output pin; the measurement board has a built-in ADC sampling, and the ADC sampling is set to trigger the acquisition through the external signal received by the main input pin.
[0005] Preferably, it is necessary to set a regular channel for ADC sampling and configure DMA2 so that after the ADC sampling conversion is completed, the conversion result is stored in a specified array through DMA2.
[0006] Preferably, the regular channel for ADC sampling is set as the channel that needs to be converted, the scanning mode is turned on, the continuous conversion is turned off, and the external trigger conversion mode is set to start the DMA request for ADC sampling.
[0007] Preferably, when DMA2 reaches a specified length, that is, reaches a specified storage depth, an interrupt is generated to notify the MCU to perform data processing.
[0008] Preferably, the source address of DMA1_CH3 is configured to be an array storing IO register values, the target address is GPIO_BSRR, and is set to a circular mode.
[0009] Preferably, the basic timer is configured to be automatically reloaded, the automatic reload frequency is 10k, and the DMA request of the basic timer is enabled.
[0010] Preferably, the advanced timer and the general timer are reserved for PWM analog signal output.
[0011] Preferably, the MCU adopts STM32F103RCT6.
[0012] Compared with the prior art, the present invention adopts an embedded microcontroller as the main controller, integrates the two functions of triggering PWM signal output and using a timer to trigger ADC sampling on the same measurement board, fully utilizes the resources of the MCU, configures the basic timer to be automatically reloaded, triggers DMA1 through the UPDATE event of the basic timer, and sets the ADC sampling to trigger the acquisition through the external signal received by the main input pin, so as to realize the ADC sampling trigger; and retains the advanced timer and the general timer for PWM analog signal output; thus, 6-channel PWM output and 16-channel analog signal acquisition can be provided, and the MCU performance will not be consumed extra. In this way, the hardware resources of the MCU can be maximized, and the MCU will only participate in the processing of the analog sampling data after the sampling of the specified data volume is completed. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The drawings constituting a part of this application are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0014] Figure 1 It is a schematic diagram of the working principle of the present invention.
[0015] Figure 2 It is a schematic diagram of the circuit layout of the prior art. DETAILED DESCRIPTION
[0016] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments and the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0017] The invention discloses a method for multi-channel analog acquisition and PWM output for VCU test. The embedded microcontroller is used as the main controller MCU in the measurement board. The measurement board is provided with a main output pin and a main input pin, and a connection is established between the main output pin and the main input pin outside the MCU. The measurement board has a built-in basic timer, and DMA1 is triggered by the UPDATE event of the basic timer. The SET / RESET register of the GPIO is modified by DMA1 to generate a PWM signal with a duty cycle of 50% on the main output pin. The measurement board has a built-in ADC sampling, and the ADC sampling is set to trigger the acquisition through the external signal received by the main input pin.
[0018] In one embodiment, it is necessary to set a regular channel for ADC sampling and configure DMA2 so that after the ADC sampling conversion is completed, the conversion result is stored in a specified array through DMA2.
[0019] In one embodiment, the regular channel for ADC sampling is set as the channel that needs to be converted, the scanning mode is turned on, the continuous conversion is turned off, and the external trigger conversion mode is set to start the DMA request for ADC sampling.
[0020] In one embodiment, when DMA2 reaches a specified length, that is, reaches a specified storage depth, an interrupt is generated to notify the MCU to process the data.
[0021] In one embodiment, the source address of DMA1_CH3 is configured to be an array storing IO register values, the target address is GPIO_BSRR, and the loop mode is set.
[0022] In one embodiment, the basic timer is configured to be automatically reloaded, the automatic reload frequency is 10k, and the DMA request of the basic timer is enabled.
[0023] In one embodiment, the advanced timer and the general timer are reserved for PWM analog signal output.
[0024] In one embodiment, the MCU uses STM32F103RCT6.
[0025] Embodiment 1: A method for multi-channel analog acquisition and PWM output for VCU testing. For the convenience of testing and to make the best use of hardware resources, the two functions are implemented on the same measurement board. STM32F103RCT6 is used as the main controller. The measurement board is provided with a main output pin and a main input pin. The main output pin and the main input pin are connected outside the MCU. The implementation steps are as follows:
[0026] S1. Use the built-in basic timer TIM6 of the measurement board, trigger DMA1 through the UPDATE event of the basic timer TIM6, and modify the SET / RESET register of the GPIO through DMA1 to generate a PWM signal with a duty cycle of 50% on the main output pin;
[0027] S2, the measurement board has built-in ADC sampling, and the ADC sampling is set to be triggered by the external signal received by the main input pin. The PWM signal generated on the main output pin reaches the main input pin through the external connection to trigger the ADC sampling operation.
[0028] S3. You need to set the regular channel for ADC sampling and configure DMA2. By modifying the UPDATE frequency of the basic timer TIM6, you can modify the ADC sampling rate so that after the ADC sampling conversion is completed, the conversion result can be stored in the specified array through DMA2.
[0029] S4. When DMA2 reaches the specified length, that is, reaches the specified storage depth, an interrupt is generated to notify the MCU to process the data.
[0030] The present invention adopts an embedded microcontroller as a main controller, integrates the two functions of triggering PWM signal output and using a timer to trigger ADC sampling on the same measurement board, makes full use of the resources of the MCU, retains advanced timers and general timers for PWM analog signal output, that is, uses TIM1, TIM2, TIM3, TIM4, TIM5 and TIM8 as PWM output, with a total of 6 PWM outputs; configures the basic timer to be automatically reloaded, triggers DMA1 through the UPDATE event of the basic timer, and sets the ADC sampling to be triggered by an external signal received by the main input pin to trigger the acquisition, realizes ADC sampling triggering, and configures the remaining 15 ADC samplings to collect external analog data, with a total of 16 analog signal acquisitions, and does not consume the MCU performance extra. In this way, the hardware resources of the MCU can be maximized, and the MCU participates in the processing of analog sampling data only after the sampling of the specified data amount is completed.
[0031] Embodiment 2: Based on Embodiment 1, in step S1, the basic timer TIM6 is configured to be automatically reloaded, the automatic reload frequency is 10k, and the DMA request of the basic timer TIM6 is turned on, and the advanced timer and the general timer are reserved for PWM analog signal output; this can maximize the use of the hardware resources of the MCU, and the MCU will only participate in the processing of the analog sampling data after the sampling of the specified data volume is completed; the source address of DMA1_CH3 is configured to be the array storing the IO register value, the target address is GPIO_BSRR, and it is set to the loop mode. In step S3, the regular channel of ADC sampling is set to the channel that needs to be converted, the scanning mode is turned on, the continuous conversion is turned off, and it is set to the external trigger conversion mode, and the DMA request of ADC sampling is turned on.
[0032] The above is only the preferred embodiment of the present invention, and does not limit the present invention in other forms. Any technician familiar with the profession may use the above disclosed technical content to change or modify it into an equivalent embodiment with equivalent changes. However, any simple modification, equivalent change and modification made to the above embodiment according to the technical essence of the present invention without departing from the technical solution of the present invention still belongs to the protection scope of the technical solution of the present invention.
Claims
1. A method for multi-channel analog acquisition and PWM output for VCU testing, characterized in that: The measurement board uses an embedded microcontroller as the main controller MCU. The measurement board is provided with a main output pin and a main input pin, and the main output pin and the main input pin are connected outside the MCU. The measurement board has a built-in basic timer. The UPDATE event of the basic timer triggers DMA1, and the SET / RESET register of the GPIO is modified through DMA1 to generate a PWM signal with a duty cycle of 50% on the main output pin. The measurement board has built-in ADC sampling, and the ADC sampling is set to trigger the acquisition through the external signal received by the main input pin.
2. The method for multi-channel analog acquisition and PWM output for VCU testing according to claim 1, characterized in that: It is necessary to set up a regular channel for ADC sampling and configure DMA2 so that after the ADC sampling conversion is completed, the conversion results can be stored in the specified array through DMA2.
3. The method for multi-channel analog acquisition and PWM output for VCU testing according to claim 2, characterized in that: Set the regular channel for ADC sampling to the channel that needs to be converted, turn on the scan mode, turn off continuous conversion, set it to external trigger conversion mode, and turn on the DMA request for ADC sampling.
4. The method for multi-channel analog acquisition and PWM output for VCU testing according to claim 3, characterized in that: When DMA2 reaches the specified length, that is, the specified storage depth, an interrupt is generated to notify the MCU to process the data.
5. The method for multi-channel analog acquisition and PWM output for VCU testing according to claim 1, characterized in that: Configure the source address of DMA1_CH3 to be the array storing the IO register values, the target address to be GPIO_BSRR, and set it to loop mode.
6. The method for multi-channel analog acquisition and PWM output for VCU testing according to claim 1, characterized in that: Configure the basic timer to auto-reload, the auto-reload frequency is 10k, and enable the DMA request of the basic timer.
7. The method for multi-channel analog acquisition and PWM output for VCU testing according to claim 1, characterized in that: Advanced timers and general timers are reserved for PWM analog signal output.
8. The method for multi-channel analog acquisition and PWM output for VCU testing according to claim 1, characterized in that: The MCU used is STM32F103RCT6.
