Microchip Technology AC164133 Data Sheet

Page of 64
Demonstration Program Operation
© 2008 Microchip Technology Inc.
DS70336A-page 51
4.2
CODE DEMONSTRATION
4.2.1
System Initialization
When power is applied to the board, the program starts by executing the following system 
initialization routines:
• Peripherals – The required peripherals (PWM, ADC, Timers and GPIO) are 
configured and enabled.
• Variables – Program variables are defined. RAM locations and register usage are 
defined and documented.
• Constants – Program constants are defined including reference set points for 
both VOUT1 and VOUT2, input voltage, current limits, fault conditions, PWM 
periods and Timer periods. 
• Interrupts – The ADC and Timer Interrupts are set up and enabled.
• System Stabilization – All outputs are discharged to ensure a stable value at 
start-up.
4.2.2
Fault Check
The program checks the ADC for input undervoltage and output overvoltage conditions. 
If a fault occurs, the PWM outputs are disabled until the fault condition is cleared. If no 
fault is detected, the program proceeds.
4.2.3
Soft Start
The Soft Start Routine ramps up the output voltage in an open-loop fashion to bring the 
system within the operating range of the PID control loop. This routine ensures that the 
output does not overshoot the desired voltage. It also limits the current at start-up.
4.2.4
ADC Interrupt
The ADC Interrupt is the heart of the demo program. This routine takes up approximately 
75% of the execution time. It performs all the PID calculations and applies any needed 
corrections to the output.
4.2.5
System Idle Loop
All auxiliary functions are performed in the system idle routine. This is the time available 
to the CPU while the demo program is waiting for an ADC Interrupt. Non-critical functions 
can be performed in this loop. During this time the input voltage, fault timers and Soft 
Start flag are checked.
4.3
OTHER CODE EXAMPLES
Note 1:
The ADC Interrupt can occur any time during program execution. 
2:
The ADC Interrupt takes priority over any other tasks that the program is 
performing.