| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

init_dsp.c
1 /*
2 * File: init_dsp.c
3 * Author: M91406
4 *
5 * Created on October 16, 2018, 12:00 PM
6 */
7
8
9 #include <xc.h>
10 #include "xc16_pral.h"
11
12 /***********************************************************************************
13 * @fn uint16_t sysDsp_Initialize(void)
14 * @ingroup dsp-initialization
15 * @brief Digital Signal Processor initialization
16 * @return unsigned integer
17 * 0=failure
18 * 1=success
19 *
20 * @details
21 * This routine initializes the default configuration of the
22 * DSP core for performing SMPS control loop libraries.
23 * If any other section of the firmware needs to use the DSP
24 * with different settings, this code module would have to
25 * make sure the core configuration is reset to these defaults
26 * when the SMPS control library is executed.
27 *
28 * @note:
29 * The configuration of the control library allows to add its own
30 * core configuration save & restore cycle in the control code.
31 * Please enable this function in the control loop configuration
32 * if conflicts between different DSP configurations cannot be
33 * resolved differently within the firmware.
34 * This routine initializes the default configuration of the
35 * DSP core for performing SMPS control loop libraries.
36 * If any other section of the firmware needs to use the DSP
37 * with different settings, this code module would have to
38 * make sure the core configuration is reset to these defaults
39 * when the SMPS control library is executed.
40 *
41 * The configuration of the control library allows to add its own
42 * core configuration save & restore cycle in the control code.
43 * Please enable this function in the control loop configuration
44 * if conflicts between different DSP configurations cannot be
45 * resolved differently within the firmware.
46 *
47 **********************************************************************************/
48 volatile uint16_t sysDsp_Initialize(void) {
49
50 CORCONbits.ACCSAT = CORCON_ACCSAT_131; // Accumulator Saturation Mode Selection: 9.31 saturation (super saturation)
51 CORCONbits.IF = CORCON_IF_FRACTIONAL; // Integer or Fractional Multiplier Mode Selection: Fractional mode is enabled for DSP multiply
52 CORCONbits.RND = CORCON_RND_UNBIASED; // Rounding Mode Selection: Unbiased (convergent) rounding is enabled
53 CORCONbits.SATA = CORCON_SATA_ON; // ACCA Saturation Enable: Accumulator A saturation is enabled
54 CORCONbits.SATB = CORCON_SATB_ON; // ACCB Saturation Enable: Accumulator B saturation is enabled
55 CORCONbits.SATDW = CORCON_SATDW_OFF; // Data Space Write from DSP Engine Saturation Enable: Data Space write saturation is enabled
56 CORCONbits.US = CORCON_US_SIGNED; // DSP Multiply Unsigned/Signed Control: DSP engine multiplies are signed
57 CORCONbits.VAR = CORCON_VAR_FIXED; // Variable Exception Processing Latency Control: Fixed exception processing is enabled
58
59 // CORCONbits.DL = CORCON_DL_0; // (read only)
60 // CORCONbits.EDT = CORCON_EDT_RUN; // control bit => do not set during configuration
61 // CORCONbits.SFA = CORCON_SFA_ACTIVE; // (read only)
62 // CORCONbits.IPL3 = CORCON_IPL3_STAT_LT7; // (read only)
63
64 Nop();
65 Nop();
66 Nop();
67
68 return(1);
69 }
70