Methods and apparatus for performing self-diagnostics in a microcontroller
By introducing hardware components such as multiplexers, context switching circuits, and timers into the microcontroller, autonomous diagnosis of peripheral devices is achieved, solving the problems of high resource consumption and time sensitivity, and improving the efficiency and real-time performance of self-diagnosis.
Patent Information
- Application Number
- CN202580027805.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2024-04-18
- Filing Date
- 2025-04-17
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies for performing self-diagnostics in microcontrollers are resource-intensive, time-sensitive, and heavily reliant on CPU and memory resources, making it difficult to achieve high frequency and real-time reliability.
By combining hardware components and control logic, and through multiplexers, context switching circuits, and timers, the autonomous switching of peripheral devices and the storage and selection of diagnostic settings are realized, reducing the dependence on CPU and memory. The interconnection system is used to generate trigger signals for self-diagnosis.
It reduces the consumption of microcontroller resources, improves time performance and real-time reliability, and enhances the frequency and efficiency of self-diagnosis.
Smart Images

Figure CN123125582A_ABST
Abstract
Description
Cross-references to related applications
[0001] This application claims priority to U.S. Nonprovisional Patent Application No. 19 / 181,748, filed April 17, 2025, and U.S. Provisional Patent Application No. 63 / 635,743, filed April 18, 2024, the entire contents of which are incorporated herein by reference. Technical Field
[0002] This disclosure relates in general to microcontrollers, and more specifically to methods and apparatus for performing self-diagnostics in microcontrollers. Summary of the Invention
[0003] According to one or more example aspects, a method for performing self-diagnostics in a microcontroller is provided. The method may include: storing one or more diagnostic settings in one or more registers; selecting a diagnostic setting from the one or more diagnostic settings; and using context switching circuitry to autonomously switch a peripheral device of the microcontroller to the selected diagnostic setting.
[0004] One or more diagnostic settings can define one or more parameters for a corresponding diagnostic test. The peripheral device can be at least one of an analog-to-digital converter (ADC), an analog comparator (AC), a digital-to-analog converter (DAC), an operational amplifier, a programmable ramp generator, and a zero-crossing detector, but other types of peripheral devices can be used. The peripheral device can receive one or more diagnostic settings stored in one or more registers via a multiplexer. The method can include using a timer to send a trigger signal to context switching circuitry to initiate an autonomous switching of the peripheral device to a selected diagnostic setting. The method can include using an interconnect system for context switching circuitry to generate the trigger signal. The interconnect system can generate the trigger signal based on a predetermined event associated with the peripheral device. The predetermined event can include at least one of reaching a threshold and encountering an error condition.
[0005] According to one or more examples, an apparatus for performing self-diagnostics in a microcontroller is provided. The apparatus may include: one or more registers for storing one or more diagnostic settings; a context switching circuit for selecting a diagnostic setting from the one or more diagnostic settings based on a trigger signal; and a peripheral device that autonomously switches to the selected diagnostic setting via the context switching circuit.
[0006] One or more diagnostic settings can define one or more parameters for corresponding diagnostic tests. Peripheral devices can be at least one of analog-to-digital converters (ADCs), analog comparators (ACs), digital-to-analog converters (DACs), operational amplifiers, programmable ramp generators, and zero-crossing detectors, but other types of peripheral devices can be used. The device can include a multiplexer for providing one or more diagnostic settings stored in one or more registers to the peripheral device based on a selection signal from context switching circuitry. The device can include a timer for transmitting a trigger signal to the context switching circuitry. The device can include an interconnect system for generating the trigger signal based on a predetermined event associated with the peripheral device. The predetermined event can include at least one of reaching a threshold and encountering an error condition.
[0007] According to one or more examples, a lockstep ADC system is provided, which may include: a first analog-to-digital converter (ADC) for receiving a first analog signal from a first sensor and a second analog signal from a second sensor; a second ADC for receiving the first and second analog signals; and a context switching circuit for selecting a diagnostic setting from a plurality of diagnostic settings for use by the first and second ADCs in a self-diagnostic test. The lockstep ADC system may include a multiplexer for receiving the plurality of diagnostic settings and outputting the selected diagnostic setting to the first and second ADCs based on a selection signal generated by the context switching circuit. The context switching circuit may generate the selection signal in response to a trigger signal. The trigger signal may be provided by a timer.
[0008] According to one or more examples, a self-diagnostic system is provided, which may include: an analog-to-digital converter (ADC) for receiving analog signals and outputting digital signals; one or more registers for storing one or more diagnostic settings; a multiplexer for receiving multiple analog input signals and outputting analog signals to the ADC; and a timer for providing a start diagnostic signal to the ADC. The ADC may select a diagnostic setting from the one or more diagnostic settings and perform a self-diagnostic test in response to the start diagnostic signal. The ADC may set a fault flag in response to detecting a fault in the self-diagnostic test. The self-diagnostic system may include a processor for sending a start conversion signal to cause the ADC to convert the analog signal into an output signal. The timer may provide the start diagnostic signal independently of the processor. Attached Figure Description
[0009] Figure 1A block diagram illustrating a device for performing self-diagnostics in a microcontroller, based on one or more examples, is shown.
[0010] Figure 2 A block diagram illustrating a lockstep ADC system with context switching circuitry according to one or more examples is shown.
[0011] Figure 3 A block diagram of a system with an analog-to-digital converter (ADC) for self-diagnosis, exemplified according to one or more examples, is shown.
[0012] Figure 4 A block diagram illustrating a system with multiple peripheral devices according to one or more examples is shown.
[0013] Figure 5 A block diagram illustrating a method for performing self-diagnostics in a microcontroller, based on one or more examples, is shown. Detailed Implementation
[0014] Reference will now be made to the various examples illustrated in the accompanying drawings, in which the same reference numerals always denote the same elements. These examples may be presented in various forms, and are not limited to those described herein.
[0015] In systems used in Functional Safety (FuSa) applications, self-tests are typically used to verify system reliability. However, self-tests can be resource-intensive, consuming CPU and / or memory resources from the microcontroller. For example, when testing analog-to-digital converters (ADCs) and digital-to-analog converters (DACs), the CPU may need to record the current register configurations of two peripherals to restore them after performing the self-test, configure the two peripherals for the self-test, run the test, reconfigure the DAC to test additional values when needed, compare these values with expected values in software, and restore the peripheral configurations after the test is complete by reading the recorded configurations and writing them to the applicable registers. Furthermore, self-tests are time-sensitive and often must be performed in real-time. Therefore, there is a need for a method and apparatus for performing self-diagnostics that can reduce the use of limited processor and memory resources, improve time performance and real-time reliability, and increase the frequency of such self-diagnostics.
[0016] Figure 1 A block diagram illustrating an apparatus 100 for performing self-diagnostics in a microcontroller, according to one or more examples, is shown. Apparatus 100 may utilize a combination of hardware components and control logic to perform self-diagnostics in a microcontroller. Apparatus 100 may include a peripheral device 102, a multiplexer 104, one or more registers 106, a context switching circuit 108, and a timer 110.
[0017] Peripheral device 102 may be at least one of an analog-to-digital converter (ADC), an analog comparator (AC), a digital-to-analog converter (DAC), an operational amplifier, a programmable ramp generator, a zero-crossing detector, etc. In one or more examples, a single peripheral device may be used in device 100. However, those skilled in the art will understand that any number of peripheral devices may be used within device 100. Peripheral device 102 may act as an interface between the microcontroller and one or more external systems. Peripheral device 102 may process at least one of one or more analog signals and one or more digital signals received from one or more sensors, one or more actuators, or one or more external devices. During self-diagnosis, peripheral device 102 may interact with context switching circuitry 108 of device 100.
[0018] Multiplexer 104 can be a digital circuit that acts as a programmable selector. Multiplexer 104 may include one or more input lines and one or more input lines, but... Figure 1 In the example, multiplexer 104 includes an output line. One or more input lines may carry specific diagnostic settings for peripheral device 102. Multiplexer 104 may be operatively coupled to context switching circuitry 108 and one or more registers 106. The output line of multiplexer 104 may be operatively coupled to peripheral device 102. Multiplexer 104 may route the selected diagnostic setting from a specific input line connected to a corresponding register in one or more registers 106 to peripheral device 102 via the output line. Multiplexer 104 is operatively coupled to context switching circuitry 108, and one or more selection signals may be sent to multiplexer 104 to enable logical selection of specific diagnostic settings for peripheral device 102 from one or more diagnostic settings, thereby facilitating self-diagnosis.
[0019] One or more registers 106 may store one or more diagnostic settings. In one or more examples, the one or more diagnostic settings stored in one or more registers 106 may be hard-coded, configurable, or some combination of both. The one or more diagnostic settings may define one or more parameters for the corresponding diagnostic test. The one or more parameters may include one or more thresholds, one or more reference values, one or more calibration parameters, one or more test parameters, one or more error handling settings, etc. The one or more calibration parameters may include one or more offset adjustments, one or more gain settings, one or more calibration coefficients, etc. The one or more test parameters may include test duration, one or more sampling rates, signal resolution, etc.
[0020] Context switching circuit 108 can coordinate the self-diagnosis of peripheral device 102 by facilitating autonomous switching between one or more diagnostic settings stored in one or more registers 106 without CPU intervention. In one or more examples, the CPU can trigger context switching circuit 108 to autonomously switch between one or more diagnostic settings stored in one or more registers 106. Context switching circuit 108 can continuously monitor trigger signals that initiate self-diagnosis. Context switching circuit 108 can receive trigger signals from timer 110 for self-diagnosis. In one or more examples, timer 110 can be programmed with specific intervals to periodically test peripheral device 102 by sending trigger signals to context switching circuit 108.
[0021] Context switching circuitry 108 can be operatively coupled to an interconnect system (not shown) to generate a trigger signal with or without CPU intervention. The interconnect system can be an alternative to timer 110. In one or more examples, the interconnect system can allow one or more peripheral devices to act as generators or users on an event channel. Generator peripheral devices (such as timers, universal synchronous asynchronous receiver-transmitters, analog-to-digital converters, etc.) can assert a trigger signal when a specific event (e.g., timeout, transmission completion, conversion completion, etc.) occurs. User peripheral devices can receive the trigger signal and initiate context switching circuitry 108. The interconnect system can generate the trigger signal based on a predetermined event associated with peripheral device 102. The predetermined event can include at least one of reaching a threshold and encountering an error condition. When using the interconnect system, context switching circuitry 108 can interpret predetermined events transmitted through the interconnect system as trigger signals for self-diagnosis.
[0022] Context switching circuitry 108 can select a diagnostic setting from one or more diagnostic settings based on a trigger signal. Peripheral device 102 can autonomously switch to the selected diagnostic setting via context switching circuitry 108. By autonomously switching between one or more diagnostic settings using context switching circuitry 108, the microcontroller may not require direct memory access (DMA) and one or more additional registers. Context switching circuitry 108 can provide a combination of flexibility and autonomy within the microcontroller for self-diagnostics. In one or more examples, the microcontroller may be an 8-bit microcontroller. However, those skilled in the art will understand that a microcontroller of any resolution can be used.
[0023] Figure 2A block diagram illustrating a lockstep ADC system 200 with context switching circuitry 216 according to one or more examples is shown. The lockstep ADC system 200 may include a first sensor 202, a second sensor 204, a first analog-to-digital converter (ADC) 206, a second ADC 208, a multiplexer (MUX 210), one or more first registers 212, one or more second registers 214, context switching circuitry 216, a CPU 218, a timer 220, a first comparator 222, and a second comparator 224.
[0024] The first sensor 202 and the second sensor 204 can provide analog signals to the first ADC 206 and the second ADC 208. The first ADC 206 and the second ADC 208 can simultaneously perform a conversion process from the same analog signals from the first sensor 202 and the second sensor 204 to digital format. The first ADC 206 and the second ADC 208 can operate in parallel, processing the same analog signals. The first ADC 206 can output the digital format of the analog signals from the first sensor 202 and the second sensor 204 to a first comparator 222, which compares the digital signal corresponding to the first sensor 202 with the digital signal corresponding to the second sensor 204. The second ADC 208 can output the digital format of the analog signals from the first sensor 202 and the second sensor 204 to a second comparator 224, which also compares the digital signal corresponding to the first sensor 202 with the digital signal corresponding to the second sensor 204. The first comparator 222 and the second comparator 224 can output diagnostic fault signals in response to the comparison. For example, if the digital signals corresponding to the first sensor 202 and the second sensor 204 do not match, or differ by more than a predetermined threshold, comparators 222 and 224 can output diagnostic fault signals. According to various examples, the result of the comparison performed by the first comparator 222 can be compared with the result of the comparison performed by the second comparator 224 to determine whether the first ADC 206 and the second ADC 208, as well as the first comparator 222 and the second comparator 224, are functioning correctly. According to various examples, the first ADC 206 and the second ADC 208 can convert only one of the input analog signals from the first sensor 202 and the second sensor 204 into digital format. The first comparator 222 and the second comparator 224 can compare the digital signal with a reference value to determine whether the first sensor 202 or the second sensor 204, or the first ADC 206 or the second ADC 208, are functioning correctly.
[0025] Multiplexer 210 can simultaneously transfer shared diagnostic settings from one or more first registers 212 and one or more second registers 214 to the first ADC 206 and the second ADC 208. Using shared diagnostic settings during self-diagnosis in the lockstep ADC system 200 ensures that the first ADC 206 and the second ADC 208 are subjected to the same conditions, thereby facilitating reliable comparison of results. One or more first registers 212 can store one or more first diagnostic settings associated with the first ADC 206. One or more second registers 214 can store one or more second diagnostic settings associated with the second ADC 208.
[0026] Context switching circuit 216 can perform self-diagnosis by selecting a diagnostic setting from at least one of one or more first registers 212 and one or more second registers 214 based on a trigger signal generated by CPU 218. Context switching circuit 216 enables multiplexer 210 to share the selected diagnostic setting between first ADC 206 and second ADC 208. Context switching circuit 216 can autonomously switch first ADC 206 and second ADC 208 to the selected diagnostic setting without intervention from CPU 218. Timer 220 can transmit a trigger signal generated by CPU 218 to context switching circuit 216 to periodically test first ADC 206 and second ADC 208. In lockstep ADC system 200, one or more first registers 212 and one or more second registers 214 can be shared between first ADC 206 and second ADC 208. Lockstep ADC system 200 may not require direct memory access (DMA) and one or more additional registers.
[0027] Figure 3A block diagram of a system 300 with an analog-to-digital converter (ADC) 304 for self-diagnosis, exemplified according to one or more examples, is shown. System 300 can be designed for low configurability and high autonomy. The system may include a multiplexer 302, an ADC 304, one or more registers 306, one or more diagnostic settings 308, a result register 310, a CPU 312, and a timer 314. Multiplexer 302 can manage multiple analog input signals from multiple pins. Multiplexer 302 can route one of the multiple analog input signals to ADC 304. ADC 304 converts the analog input signal into a digital representation based on a start conversion signal from CPU 312. The digital representation can be stored in result register 310. When a start diagnostic signal is received from timer 314, ADC 304 can perform self-diagnosis. During self-diagnosis, one of the diagnostic settings stored in one or more registers 306 can be selected based on the start diagnostic signal from timer 314 to ADC 304. In one or more examples, one or more diagnostic settings 308 may be hardware-defined diagnostic settings. ADC 304 may set diagnostic status flags for faults.
[0028] According to one or more examples, ADC 304 can receive analog input signals from a touch sensor and convert the received analog input signals into digital signals. When not used for touch sensor data, ADC 304 can be used for self-diagnostic testing. ADC 304 can use one or more diagnostic settings 308 when in self-diagnostic mode, and can revert to a different set of settings when used for touch sensor data.
[0029] Figure 4 A block diagram illustrating a system 400 with multiple peripheral devices according to one or more examples is shown. System 400 may include multiple peripheral devices, multiple diagnostic settings, and multiple enable signals. The multiple peripheral devices may include an analog comparator (AC) 402, a digital-to-analog converter (DAC) 404, and an analog-to-digital converter (ADC) 406. In one or more examples, ADC 406 and DAC 404 may be configured to test each other using diagnostic settings 2 from the multiple enable signals when an enable signal for diagnostic settings 2 is received from the multiple enable signals. The multiple diagnostic settings may be hard-coded, configurable, or some combination of both. The multiple enable signals may be operatively coupled to one or more interconnect systems.
[0030] Figure 5 A flowchart 500 illustrating a method for performing self-diagnostics in a microcontroller, based on one or more examples, is shown. It should be noted that, in order to explain the method operation of flowchart 500, reference will be made to... Figure 1 The components explained in the text.
[0031] Flowchart 500 begins at operation 502. At operation 504, the method may include storing one or more diagnostic settings in one or more registers 106 of the microcontroller. At operation 506, the method may include selecting a diagnostic setting from the one or more diagnostic settings based on a trigger signal. At operation 508, the method may include using context switching circuitry 108 to autonomously switch the microcontroller's peripheral device 102 to the selected diagnostic setting.
[0032] Flowchart 500 terminates at operation 510. It should be noted that flowchart 500 is to be interpreted as having the process operations described above; however, those skilled in the art will understand that flowchart 500 may have more or fewer process operations that can implement all the above examples of this disclosure.
[0033] Various examples have been disclosed herein in conjunction with the foregoing description and accompanying drawings. It should be understood that describing and illustrating each combination and sub-combination of these examples literally would be an undue repetition. Therefore, all examples can be combined in any manner and / or combination, and this specification (including the accompanying drawings) should be construed as constituting a complete written description of all combinations and sub-combinations of these examples herein, as well as the ways and processes of preparing and using them, and should support the claims for any such combinations or sub-combinations.
[0034] Those skilled in the art will understand that the examples described herein are not limited to those specifically shown and described above. Furthermore, unless the contrary is mentioned above, it should be noted that all figures are not drawn to scale. Various modifications and variations are possible in accordance with the above teachings.
Claims
1. A method for performing self-diagnosis in a microcontroller, the method comprising: Store one or more diagnostic settings in one or more registers; Select a diagnostic setting from the one or more diagnostic settings; as well as The microcontroller's peripherals are autonomously switched to the selected diagnostic settings using a context switching circuit.
2. The method of claim 1, wherein the one or more diagnostic settings are used to define one or more parameters for the corresponding diagnostic test.
3. The method according to claim 1, wherein the peripheral device is at least one of an analog-to-digital converter (ADC), an analog comparator (AC), a digital-to-analog converter (DAC), an operational amplifier, a programmable ramp generator, and a zero-crossing detector.
4. The method of claim 1, wherein the peripheral device is configured to receive the one or more diagnostic settings stored in the one or more registers via a multiplexer.
5. The method of claim 1, further comprising using a timer to transmit a trigger signal to the context switching circuit to initiate the autonomous switching of the peripheral device to the selected diagnostic settings.
6. The method of claim 5, wherein the trigger signal is generated using an interconnect system for the context switching circuit.
7. The method of claim 6, wherein the interconnection system is configured to generate the trigger signal based on a predetermined event associated with the peripheral device, wherein the predetermined event includes at least one of reaching a threshold and encountering an error condition.
8. An apparatus for performing self-diagnostics in a microcontroller, the apparatus comprising: One or more registers, wherein the one or more registers are used to store one or more diagnostic settings; A context switching circuit, the context switching circuit being used to select a diagnostic setting from the one or more diagnostic settings based on a trigger signal; and Peripheral devices that autonomously switch to the selected diagnostic settings via the context switching circuit.
9. The apparatus of claim 8, wherein the one or more diagnostic settings are used to define one or more parameters for a corresponding diagnostic test.
10. The apparatus of claim 8, wherein the peripheral device is at least one of an analog-to-digital converter (ADC), an analog comparator (AC), a digital-to-analog converter (DAC), an operational amplifier, a programmable ramp generator, and a zero-crossing detector.
11. The apparatus of claim 8, the apparatus comprising a multiplexer for providing the peripheral device with the one or more diagnostic settings stored in the one or more registers based on a selection signal from the context switching circuit.
12. The apparatus of claim 8, further comprising a timer for transmitting the trigger signal to the context switching circuit.
13. The apparatus of claim 8, further comprising an interconnection system for generating the trigger signal based on a predetermined event associated with the peripheral device, wherein the predetermined event includes at least one of reaching a threshold and encountering an error condition.
14. A lockstep ADC system, the lockstep ADC system comprising: A first analog-to-digital converter (ADC) is used to receive a first analog signal from a first sensor and a second analog signal from a second sensor; A second ADC is used to receive the first analog signal and the second analog signal; and A context switching circuit is provided for selecting a diagnostic setting from a plurality of diagnostic settings for use by the first ADC and the second ADC in a self-diagnostic test.
15. The lockstep ADC system according to claim 14, wherein the lockstep ADC system comprises: A multiplexer is provided for receiving the plurality of diagnostic settings and outputting the selected diagnostic setting to the first ADC and the second ADC based on a selection signal generated by the context switching circuit.
16. The lockstep ADC system of claim 15, wherein the context switching circuit is configured to generate the selection signal in response to a trigger signal.
17. The lockstep ADC system of claim 16, wherein the trigger signal is provided by a timer.
18. A self-diagnostic system, the self-diagnostic system comprising: An analog-to-digital converter (ADC) is used to receive analog signals and output digital signals. One or more registers, wherein the one or more registers are used to store one or more diagnostic settings; A multiplexer, wherein the multiplexer is used to receive multiple analog input signals and output the analog signals to the ADC; and A timer, the timer being used to provide the ADC with a start diagnostic signal; The ADC is used to select a diagnostic setting from the one or more diagnostic settings and to perform a self-diagnostic test in response to the start diagnostic signal.
19. The self-diagnostic system of claim 18, wherein the ADC is configured to set a fault flag in response to detecting a fault in the self-diagnostic test.
20. The self-diagnostic system according to claim 18, wherein the self-diagnostic system comprises: A processor, configured to send a start conversion signal to cause the ADC to convert the analog signal into the output signal; The timer is used to provide the start diagnostic signal independently of the processor.
