Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
init_opa.c
1 /*
2  * File: init_opa.c
3  * Author: M91406
4  *
5  * Created on May 19, 2020, 1:19 PM
6  */
7 
8 
9 #include <xc.h>
10 #include <stdint.h>
11 #include <stdbool.h>
12 
13 #include "init_opa.h"
14 
19 
34 volatile uint16_t sysOpAmp_Initialize(volatile uint16_t opaInstance, volatile bool disable_n_channel)
35 {
36  volatile uint16_t retval=1;
37  volatile uint16_t idum=0;
38  volatile struct P33C_OPA_MODULE_s* opa = p33c_OpaModule_GetHandle();
39 
40  // If instance is set = 0, op-amp will be skipped and op-amps will be turned off
41  if(opaInstance > 0)
42  {
43  // Disables Op Amp N channel input stage
44  if (disable_n_channel)
45  {
46  idum = (((uint16_t)disable_n_channel) << (opaInstance - 1));
47  opa->AmpCon1H.value |= idum;
48  }
49  else
50  {
51  idum = (1 << (opaInstance - 1));
52  opa->AmpCon1H.value &= (~idum);
53  }
54 
55  // Enable op-amp instance
56  idum = (0x0001 << (opaInstance - 1));
57  opa->AmpCon1L.value |= idum;
58  }
59 
60  return (retval);
61 }
62 
63 
77 volatile uint16_t sysOpAmp_ModuleEnable(void)
78 {
79  volatile struct P33C_OPA_MODULE_s* opa = p33c_OpaModule_GetHandle();
80  opa->AmpCon1L.bits.AMPON = true; // Enable Op-Amp module
81  return (opa->AmpCon1L.bits.AMPON);
82 }
83 
84 
85 
102 volatile uint16_t sysOpAmp_ModuleReset(void)
103 {
104  volatile struct P33C_OPA_MODULE_s* opa = p33c_OpaModule_GetHandle();
105 
106  // Disable and reset op-amp module
107  *opa = opaModuleDefault; // Load configuration defaults
108  opa->AmpCon1L.value = 0; // Disable and reset Op-Amp module
109 
110  return (1-opa->AmpCon1L.bits.AMPON);
111 }
112  // end of group op-amp-initialization
114 
115 // end of file
P33C_OPA_MODULE_s::AmpCon1H
union P33C_OPA_MODULE_s::@1 AmpCon1H
P33C_OPA_MODULE_s::bits
volatile struct tagAMPCON1LBITS bits
Definition: p33c_opa.h:50
sysOpAmp_ModuleEnable
volatile uint16_t sysOpAmp_ModuleEnable(void)
Enables the on-chip operational amplifier module.
Definition: init_opa.c:77
P33C_OPA_MODULE_s::value
volatile uint16_t value
Definition: p33c_opa.h:51
P33C_OPA_MODULE_s::AmpCon1L
union P33C_OPA_MODULE_s::@0 AmpCon1L
opaModuleDefault
volatile struct P33C_OPA_MODULE_s opaModuleDefault
Default configuration of op-amp module running from 500 MHz input clock.
Definition: p33c_opa.c:176
sysOpAmp_ModuleReset
volatile uint16_t sysOpAmp_ModuleReset(void)
Resets the on-chip operational amplifier module.
Definition: init_opa.c:102
p33c_OpaModule_GetHandle
volatile struct P33C_OPA_MODULE_s * p33c_OpaModule_GetHandle(void)
Gets pointer to op-amp Module SFR set.
Definition: p33c_opa.c:43
sysOpAmp_Initialize
volatile uint16_t sysOpAmp_Initialize(volatile uint16_t opaInstance, volatile bool disable_n_channel)
Initializes the on-chip operational amplifier module.
Definition: init_opa.c:34
P33C_OPA_MODULE_s
Definition: p33c_opa.h:48