8 #if (__XC16_VERSION__ > 2000) 9 #pragma message ("Warning: Library file '" __FILE__ "' has not been tested with the recently selected compiler version") 16 #include "dev_boost_pconfig.h" 17 #include "dev_boost_templates.h" 36 volatile uint16_t boostGPIO_PrivateInitialize(
volatile struct BOOST_GPIO_INSTANCE_s* boostGPIOInstance);
54 volatile uint16_t boostPWM_ModuleInitialize(
volatile struct BOOST_CONVERTER_s* boostInstance)
56 volatile uint16_t retval=1;
60 volatile bool _pmdlock = PMDCONbits.PMDLOCK;
61 PMDCONbits.PMDLOCK = 0;
63 PMDCONbits.PMDLOCK = _pmdlock;
85 pwm = p33c_PwmModule_GetHandle();
86 retval &= p33c_PwmModule_ConfigWrite(boostPwmModuleConfig);
110 volatile uint16_t boostPWM_ChannelInitialize(
volatile struct BOOST_CONVERTER_s* boostInstance)
112 volatile uint16_t retval=1;
113 volatile uint16_t _i=0;
117 volatile uint16_t pwm_Instance;
118 volatile uint16_t gpio_Instance;
127 gpio = p33c_GpioInstance_GetHandle(gpio_Instance);
138 pg = p33c_PwmGenerator_GetHandle(pwm_Instance);
139 retval &= p33c_PwmGenerator_ConfigWrite(boostInstance->
sw_node[_i].
pwm_instance, boostPwmGeneratorConfig);
215 volatile uint16_t boostPWM_Start(
volatile struct BOOST_CONVERTER_s* boostInstance)
217 volatile uint16_t retval=1;
218 volatile uint16_t _i=0;
219 volatile uint16_t timeout=0;
220 volatile uint16_t pwm_Instance=0;
221 volatile uint16_t sync_sw_mask=0;
231 pg = p33c_PwmGenerator_GetHandle(pwm_Instance);
241 while((!PCLKCONbits.HRRDY) && (timeout++ < 5000));
242 if ((timeout >= 5000) || (PCLKCONbits.HRERR))
263 retval &= (
volatile uint16_t)(pg->
PGxCONL.
bits.ON);
284 volatile uint16_t boostPWM_Stop(
volatile struct BOOST_CONVERTER_s* boostInstance)
286 volatile uint16_t retval=1;
287 volatile uint16_t _i=0;
288 volatile uint16_t pwm_Instance=0;
298 pg = p33c_PwmGenerator_GetHandle(pwm_Instance);
306 retval &= (
volatile uint16_t)((
volatile bool)(pg->
PGxCONL.
bits.ON == 0));
330 volatile uint16_t boostPWM_Suspend(
volatile struct BOOST_CONVERTER_s* boostInstance)
332 volatile uint16_t retval=1;
333 volatile uint16_t _i=0;
334 volatile uint16_t pwm_Instance;
344 pg = p33c_PwmGenerator_GetHandle(pwm_Instance);
372 volatile uint16_t boostPWM_Resume(
volatile struct BOOST_CONVERTER_s* boostInstance)
374 volatile uint16_t retval=1;
375 volatile uint16_t _i=0;
376 volatile bool sync_mode=
false;
377 volatile uint16_t pwm_Instance=0;
378 volatile uint16_t sync_sw_mask=0;
388 pg = p33c_PwmGenerator_GetHandle(pwm_Instance);
411 retval &= (uint16_t)((
bool)(!(pg->
PGxIOCONL.
value & sync_sw_mask)));
432 volatile uint16_t boostADC_ModuleInitialize(
void)
434 volatile uint16_t retval=1;
437 volatile bool _pmdlock = PMDCONbits.PMDLOCK;
438 PMDCONbits.PMDLOCK = 0;
440 PMDCONbits.PMDLOCK = _pmdlock;
443 ADCON1Lbits.ADON = 0;
444 ADCON1Lbits.ADSIDL = 0;
447 ADCON1Hbits.SHRRES = 0b11;
448 ADCON1Hbits.FORM = 0;
451 ADCON2Lbits.REFCIE = 0;;
452 ADCON2Lbits.REFERCIE = 0;
453 ADCON2Lbits.EIEN = 1;
454 ADCON2Lbits.SHREISEL = 0b111;
455 ADCON2Lbits.SHRADCS = 0b0000001;
458 ADCON2Hbits.SHRSAMC = 8;
459 ADCON2Hbits.REFERR = 0;
460 ADCON2Hbits.REFRDY = 0;
463 ADCON3Lbits.REFSEL = 0b000;
464 ADCON3Lbits.SUSPEND = 0;
465 ADCON3Lbits.SUSPCIE = 0;
466 ADCON3Lbits.SUSPRDY = 0;
467 ADCON3Lbits.SHRSAMP = 0;
468 ADCON3Lbits.CNVRTCH = 0;
469 ADCON3Lbits.SWLCTRG = 0;
470 ADCON3Lbits.SWCTRG = 0;
471 ADCON3Lbits.CNVCHSEL = 0;
474 ADCON3Hbits.CLKSEL = 0b01;
475 ADCON3Hbits.CLKDIV = 0b000000;
476 ADCON3Hbits.SHREN = 0;
477 ADCON3Hbits.C0EN = 0;
478 ADCON3Hbits.C1EN = 0;
481 ADCON4Lbits.SAMC0EN = 0;
482 ADCON4Lbits.SAMC1EN = 0;
485 ADCON4Hbits.C0CHS = 0b00;
486 ADCON4Hbits.C1CHS = 0b00;
492 ADCON5Lbits.SHRPWR = 0;
493 ADCON5Lbits.C0PWR = 0;
494 ADCON5Lbits.C1PWR = 0;
497 ADCON5Hbits.WARMTIME = 0b1111;
498 ADCON5Hbits.SHRCIE = 0;
499 ADCON5Hbits.C0CIE = 0;
500 ADCON5Hbits.C1CIE = 0;
503 ADCORE1Lbits.SAMC = 0b0000000000;
504 ADCORE0Lbits.SAMC = 0b0000000000;
507 ADCORE0Hbits.RES = 0b11;
508 ADCORE0Hbits.ADCS = 0b0000000;
509 ADCORE0Hbits.EISEL = 0b111;
511 ADCORE1Hbits.RES = 0b11;
512 ADCORE1Hbits.ADCS = 0b0000000;
513 ADCORE1Hbits.EISEL = 0b111;
533 volatile uint16_t retval=1;
534 volatile uint8_t* ptrADCRegister;
535 volatile uint8_t bit_offset;
557 bit_offset = (2 * adcInstance->
adc_input);
559 bit_offset = (2 * (adcInstance->
adc_input-8));
561 bit_offset = (2 * (adcInstance->
adc_input-16));
563 bit_offset = (2 * (adcInstance->
adc_input-24));
567 ptrADCRegister = (
volatile uint8_t *)
568 ((
volatile uint8_t *)&ADMOD0L + (
volatile uint8_t)(adcInstance->
adc_input >> 8));
570 *ptrADCRegister |= ((
unsigned int)adcInstance->
signed_result << bit_offset);
571 *ptrADCRegister |= ((
unsigned int)adcInstance->
differential_input << (bit_offset + 1));
574 ptrADCRegister = (
volatile uint8_t *)
575 ((
volatile uint8_t *)&ADTRIG0L + (
volatile uint8_t)adcInstance->
adc_input);
625 volatile uint16_t boostADC_Start(
void)
627 volatile uint16_t retval=1;
628 volatile uint16_t timeout=0;
629 volatile uint16_t adcore_mask_compare=0;
632 ADCON1Lbits.ADON = 1;
658 volatile uint16_t retval=1;
659 volatile uint16_t filter_mask=0;
663 gpio = p33c_GpioInstance_GetHandle(boostGPIOInstance->
port);
666 filter_mask = (0x0001 << boostGPIOInstance->
pin);
669 if (boostGPIOInstance->
polarity == 0)
693 volatile uint16_t retval=1;
694 volatile uint16_t filter_mask=0;
698 gpio = p33c_GpioInstance_GetHandle(boostGPIOInstance->
port);
701 filter_mask = (0x0001 << boostGPIOInstance->
pin);
704 if (boostGPIOInstance->
polarity == 0)
728 volatile bool retval=1;
732 gpio = p33c_GpioInstance_GetHandle(boostGPIOInstance->
port);
735 retval = (bool)(gpio->
PORTx.
value & (0x0001 << boostGPIOInstance->
pin));
738 if(boostGPIOInstance->
polarity == 1)
757 volatile uint16_t boostGPIO_Initialize(
volatile struct BOOST_CONVERTER_s* boostInstance)
759 volatile uint16_t retval=1;
763 retval = boostGPIO_PrivateInitialize(&boostInstance->
gpio.
EnableInput);
767 retval = boostGPIO_PrivateInitialize(&boostInstance->
gpio.
PowerGood);
789 volatile uint16_t boostGPIO_PrivateInitialize(
volatile struct BOOST_GPIO_INSTANCE_s* boostGPIOInstance)
791 volatile uint16_t retval=1;
795 gpio = p33c_GpioInstance_GetHandle(boostGPIOInstance->
port);
798 if (boostGPIOInstance->
polarity == 0)
799 gpio->
LATx.
value &= ~(0x0001 << boostGPIOInstance->
pin);
804 if(boostGPIOInstance->
io_type == 1)
810 if(boostGPIOInstance->
io_type == 2)
813 gpio->
ODCx.
value &= ~(0x0001 << boostGPIOInstance->
pin);
union P33C_GPIO_INSTANCE_s::@126 LATx
volatile uint8_t trigger_source
input channel trigger source
volatile uint16_t pwm_instance
number of the PWM channel used
union P33C_GPIO_INSTANCE_s::@124 TRISx
volatile uint16_t dead_time_falling
Dead time setting at falling edge of a half-bridge drive.
volatile uint16_t leb_period
Leading-Edge Blanking period.
volatile bool swap_outputs
Selecting if PWMxH (default) or PWMxL should be the leading PWM output.
volatile bool high_resolution_enable
Selecting if PWM module should use high-resolution mode.
union P33C_PWM_GENERATOR_s::@270 PGxIOCONH
union P33C_PWM_GENERATOR_s::@286 PGxPER
volatile uint16_t adcore_diff_mask
This variable is use to set the ADC core mask.
volatile uint8_t adc_input
number of the ADC input channel used
union P33C_PWM_GENERATOR_s::@271 PGxEVTL
volatile struct BOOST_SWITCH_NODE_SETTINGS_s sw_node[BOOST_MPHASE_COUNT]
BOOST converter switch node settings.
volatile uint16_t dead_time_rising
Dead time setting at rising edge of a half-bridge drive.
volatile bool enabled
input channel enable bit
volatile uint16_t gpio_instance
GPIO instance of the selected PWM generator.
union P33C_PWM_GENERATOR_s::@266 PGxCONL
#define P33C_PGxIOCONL_OVREN_ASYNC_SWAP
PWMxL output is leading PWM.
#define P33C_PGxSTAT_UPDREQ
Control bit in PGxSTAT setting the Update Request bit.
union P33C_PWM_GENERATOR_s::@269 PGxIOCONL
struct tagPG1CONLBITS bits
volatile uint16_t no_of_phases
number of converter phases
union P33C_PWM_GENERATOR_s::@290 PGxDTL
volatile uint16_t io_type
Input/Output definition (0=push-pull output, 1=input, 2=open-drain output)
#define P33C_PGxIOCONH_PEN_ASYNC
PWMxH output is leading PWM.
union P33C_PWM_GENERATOR_s::@281 PGxLEBL
volatile uint16_t gpio_low
GPIO port pin-number of PWMxL of the selected PWM generator.
volatile uint16_t period
Switching period.
volatile bool sync_drive
Selecting if switch node is driven in synchronous or asnchronous mode.
volatile uint16_t phase
Switching signal phase-shift.
union P33C_GPIO_INSTANCE_s::@129 CNPDx
volatile uint16_t gpio_high
GPIO port pin-number of PWMxH of the selected PWM generator.
union P33C_GPIO_INSTANCE_s::@127 ODCx
union P33C_GPIO_INSTANCE_s::@123 ANSELx
union P33C_PWM_MODULE_s::@217 vMPER
#define ADC_SHRCORE_MASK_INDEX
This define masks shared core of ADC.
volatile uint16_t pin
GPIO port pin number.
#define P33C_PGxCONL_HRES_EN
control bit in PGxCONL enabling/disabling High Resolution Mode
#define ADC_CORE2_MASK_INDEX
This define masks core 2 of ADC.
volatile bool enabled
Specifies, if this IO is used or not.
volatile uint8_t adc_core
number of the ADC core connected to the selected channel
#define P33C_PGxIOCONL_OVREN_ASYNC
control bits in PGxIOCONL enabling/disabling the PWM output override in asynchronous mode
#define ADC_POWERUP_TIMEOUT
Digital-To-Analog Converter and High Speed Comparator Special Function Register Set.
volatile struct BOOST_GPIO_INSTANCE_s PowerGood
Power Good Output.
union P33C_PWM_GENERATOR_s::@291 PGxDTH
#define P33C_PGxCONL_PWM_ON
control bit in PGxCONL enabling/disabling the PWM generator
volatile bool async_mode
Bit #9: Control bit suspending the synchronous rectifier switch PWM channel.
union P33C_PWM_GENERATOR_s::@289 PGxTRIGC
volatile bool differential_input
input channel differential mode enable bit
#define ADC_CORE1_MASK_INDEX
This define masks core 1 of ADC.
ADC input channel configuration.
volatile uint16_t polarity
Output polarity, where 0=ACTIVE HIGH, 1=ACTIVE_LOW.
volatile bool early_interrupt_enable
input channel early interrupt enable bit
#define P33C_PGxIOCONH_PEN_SYNC
control bits in PGxIOCONH enabling/disabling the PWM outputs in synchronous mode
union P33C_GPIO_INSTANCE_s::@125 PORTx
volatile bool interrupt_enable
input channel interrupt enable bit
#define ADC_CORE3_MASK_INDEX
This define masks core 3 of ADC.
GPIO instance of the converter control GPIO.
volatile uint16_t adcore_mask
This variable is use to set the ADC core mask.
volatile struct BOOST_CONVERTER_STATUS_s status
BOOST operation status bits.
union P33C_PWM_GENERATOR_s::@268 PGxSTAT
volatile bool signed_result
input channel singed result mode enable bit
volatile uint16_t port
GPIO port instance number (0=Port RA, 0=Port RB, 0=Port RC, etc.)
volatile uint16_t duty_ratio_min
Absolute duty cycle minimum during normal operation.
volatile struct BOOST_GPIO_SETTINGS_s gpio
BOOST converter additional GPIO specification.
union P33C_PWM_GENERATOR_s::@267 PGxCONH
volatile bool master_period_enable
Selecting MASTER or Individual period register.
volatile struct BOOST_GPIO_INSTANCE_s EnableInput
External ENABLE input.
#define P33C_PGxIOCONL_OVREN_SYNC
control bits in PGxIOCONL enabling/disabling the PWM output override in synchronous mode
BOOST control & monitoring data structure.
union P33C_PWM_GENERATOR_s::@284 PGxDC
#define ADC_CORE0_MASK_INDEX
This define masks core 0 of ADC.
#define P33C_PGxIOCONH_PEN_ASYNC_SWAP
PWMxL output is leading PWM.
volatile bool level_trigger
input channel level trigger mode enable bit
volatile struct BOOST_CONVERTER_SETTINGS_s set_values
Control field for global access to references.