In my blog - 'Blog #6 : Moving Towards Clinical Grade Oximeter & Respiratory Diagnostics', I have discussed the problem concerning air purification and related medical diagnostics with an oximeter and the pressure sensor. In this blog, I am submitting working codes (not pseduo codes) but incomplete as today is an extended deadline date. I cannot do testing as I need to address personal works & court works also, and I still have to write proper code but this is only how I work or would do work if given project, this is still away 8-12 months(with additional components/project costing) for the proper implementation of the proposed idea.
This blog is divided into eight sections
One need not do so much programming, as the APIs may be available, anyway I m taking hard route for this experiment. This is the same code on which I will work on if given project.
1. Power Supplies
- LCD 16 x 2 : 5 VDC
- LCD MiniClick : 5VDC
- Fans : 5 VDC
- Accelerometer : 3.3 VDC
- Respiratory Diagnostics : 11 VDC
- Oximeter 2 Click : 3.3 VDC
- Microchip SAM E51 Curiosity Nano Evaluation Kit : powered by USB
- AVNET's Ultra96V2G shown here is not used in this project but I have used to it to get 3.3VDC and 5 VDC, (you can use any other power source).
- 5 VDC is taken from click Megazzine click 2 (you can use any other power source).
- 3.3 VDC is taken from click Megazzine click 1 (you can use any other power source).
- For 12 VDC, SMPS is used.
Caution : If one is connecting LCD Miniclick like I have done, do not connect both 5V and 3.3 V power supplies and batteries to 'Curiosity Nano Base', as here when I did, it caused minor accident- burning and melting of wires.
When LCD Miniclick is supplied with only 1 voltage, it works fine, and neither boards- Curiosity Nano nor LCD Miniclick nor click Megazzine click got any damage.
So, melting of Part-1 of the proposal got demonstrated, bad joke
The pin description with Microchip SAM E51 Curiosity Nano Evaluation Kit are already explained in blog 5.
The Infineon AIROC will be used to transfer to AWS IoT Cloud and Android Applet. The LED will blink with different frequencies, while doing this.
The LCD code- Miniclick and 16x2 of this blog is given in blog 10.
The AWS IoT Cloud code is in blog 9.
The Android applet code is in blog 8.
2. Code :AIR PURIFIER ENGINE MOTOR 1
In this the DC motor is run with PWM frequency of 42.826 kHz directly from Microchip SAM E51
//Created by Mr. Abhishek Bansal
//Company: New Era Consultancy Services
#define EIC_PIN_5 (5U)
typedef struct
{ EIC_CALLBACK callback;
uintptr_t context;
EIC_PIN eicPinNo;
} EIC_CALLBACK_OBJ;
typedef enum
{
TCC1_PWM_STATUS_OVF = TCC_INTFLAG_OVF_Msk,
TCC1_PWM_STATUS_FAULT_0 = TCC_INTFLAG_FAULT0_Msk,
TCC1_PWM_STATUS_FAULT_1 = TCC_INTFLAG_FAULT1_Msk,
TCC1_PWM_STATUS_MC_0 = TCC_INTFLAG_MC0_Msk,
TCC1_PWM_STATUS_MC_1 = TCC_INTFLAG_MC1_Msk,
TCC1_PWM_STATUS_MC_2 = TCC_INTFLAG_MC2_Msk,
TCC1_PWM_STATUS_MC_3 = TCC_INTFLAG_MC3_Msk,
}TCC1_PWM_STATUS;
EIC_REGS->EIC_CTRLA |= (uint8_t)EIC_CTRLA_SWRST_Msk;
bool status = false;
if ((TCC1_REGS->TCC_STATUS & (1UL << (TCC_STATUS_CCBUFV0_Pos + (uint32_t)channel))) == 0U)
{
TCC1_REGS->TCC_CCBUF[channel] = duty & 0xFFFFFFU;
status = true;
}
TCC1_REGS->TCC_CTRLA = TCC_CTRLA_SWRST_Msk;
while ((TCC1_REGS->TCC_SYNCBUSY & TCC_SYNCBUSY_SWRST_Msk) != 0U)
{ }
TCC1_REGS->TCC_CTRLA = TCC_CTRLA_PRESCALER_DIV1 | TCC_CTRLA_PRESCSYNC_PRESC ;
TCC1_REGS->TCC_WEXCTRL = TCC_WEXCTRL_OTMX(0UL);
TCC1_REGS->TCC_WEXCTRL |= TCC_WEXCTRL_DTIEN0_Msk | TCC_WEXCTRL_DTIEN1_Msk | TCC_WEXCTRL_DTIEN2_Msk | TCC_WEXCTRL_DTIEN3_Msk
| TCC_WEXCTRL_DTLS(64UL) | TCC_WEXCTRL_DTHS(64UL);
TCC1_REGS->TCC_WAVE = TCC_WAVE_WAVEGEN_NPWM | TCC_WAVE_RAMP_RAMP1;
TCC1_REGS->TCC_CTRLA |= TCC_CTRLA_ENABLE_Msk;
TCC1_REGS->TCC_CC[0] = 0U;
TCC1_REGS->TCC_CC[1] = 0U;
TCC1_REGS->TCC_CC[2] = 0U;
TCC1_REGS->TCC_CC[3] = 0U;
TCC1_REGS->TCC_PER = 1400U;
TCC1_REGS->TCC_CTRLBSET |= (uint8_t)TCC_CTRLBSET_CMD_READSYNC;
TCC1_REGS->TCC_CTRLA &= ~TCC_CTRLA_ENABLE_Msk;
bool TCC1_PWM24bitPeriodSet (uint32_t period)
TCC1_REGS->TCC_WEXCTRL &= ~(TCC_WEXCTRL_DTHS_Msk | TCC_WEXCTRL_DTLS_Msk);
TCC1_REGS->TCC_WEXCTRL |= TCC_WEXCTRL_DTHS((uint32_t)deadtime_high) | TCC_WEXCTRL_DTLS((uint32_t)deadtime_low);
TCC1_REGS->TCC_COUNT = countVal & 0xFFFFFFU;
TCC1_REGS->TCC_CTRLBSET |= (uint8_t)TCC_CTRLBCLR_CMD_UPDATE;
eicCallbackObject[5].eicPinNo = EIC_PIN_5;
EIC_REGS->EIC_INTENCLR = (1UL << (uint32_t)pin);
EIC_REGS->EIC_INTENSET = (1UL << (uint32_t)pin);
if (eicCallbackObject[pin].eicPinNo == pin)
{
eicCallbackObject[pin].callback = callback;
eicCallbackObject[pin].context = context;
}
EIC_REGS->EIC_INTFLAG = (1UL << 5);
if ((eicCallbackObject[5].callback != NULL))
{ uintptr_t context = eicCallbackObject[5].context;
eicCallbackObject[5].callback(context);
}
3. Code :AIR PURIFIER ENGINE MOTOR 2
In this demo, 2-wire BLDC fan is run with PWM frequency of 582.524 kHz directly from Microchip SAM E51
//Created by Mr. Abhishek Bansal //Company: New Era Consultancy Services #define EIC_PIN_6 (6U) typedef struct { EIC_CALLBACK callback; uintptr_t context; EIC_PIN eicPinNo; } EIC_CALLBACK_OBJ; typedef enum { TCC2_PWM_STATUS_OVF = TCC_INTFLAG_OVF_Msk, TCC2_PWM_STATUS_FAULT_0 = TCC_INTFLAG_FAULT0_Msk, TCC2_PWM_STATUS_FAULT_1 = TCC_INTFLAG_FAULT1_Msk, TCC2_PWM_STATUS_MC_0 = TCC_INTFLAG_MC0_Msk, TCC2_PWM_STATUS_MC_1 = TCC_INTFLAG_MC1_Msk, TCC2_PWM_STATUS_MC_2 = TCC_INTFLAG_MC2_Msk, }TCC2_PWM_STATUS; uint32_t interrupt_status; interrupt_status = TCC2_REGS->TCC_INTFLAG; TCC2_REGS->TCC_INTFLAG = interrupt_status; (void)TCC2_REGS->TCC_INTFLAG; return interrupt_status; EIC_REGS->EIC_CTRLA |= (uint8_t)EIC_CTRLA_SWRST_Msk; bool status = false; if ((TCC2_REGS->TCC_STATUS & (1UL << (TCC_STATUS_CCBUFV0_Pos + (uint32_t)channel))) == 0U) { TCC2_REGS->TCC_CCBUF[channel] = duty; status = true; } eicCallbackObject[6].eicPinNo = EIC_PIN_6; TCC2_REGS->TCC_CTRLA = TCC_CTRLA_SWRST_Msk; TCC2_REGS->TCC_CTRLA = TCC_CTRLA_PRESCALER_DIV1 | TCC_CTRLA_PRESCSYNC_PRESC ; TCC2_REGS->TCC_WEXCTRL = TCC_WEXCTRL_OTMX(0UL); TCC2_REGS->TCC_WAVE = TCC_WAVE_WAVEGEN_NPWM | TCC_WAVE_RAMP_RAMP1; TCC2_REGS->TCC_CC[0] = 0U; TCC2_REGS->TCC_CC[1] = 0U; TCC2_REGS->TCC_CC[2] = 0U; TCC2_REGS->TCC_PER = 102U; while (TCC2_REGS->TCC_SYNCBUSY != 0U) { } TCC2_REGS->TCC_CTRLA |= TCC_CTRLA_ENABLE_Msk; TCC2_REGS->TCC_CTRLA &= ~TCC_CTRLA_ENABLE_Msk; while ((TCC2_REGS->TCC_SYNCBUSY & TCC_SYNCBUSY_PER_Msk) != 0U) { } return (uint16_t)TCC2_REGS->TCC_PER; TCC2_REGS->TCC_CTRLBSET |= (uint8_t)TCC_CTRLBSET_CMD_READSYNC; TCC2_REGS->TCC_COUNT = countVal; TCC2_REGS->TCC_CTRLBSET |= (uint8_t)TCC_CTRLBCLR_CMD_UPDATE; TCC2_REGS->TCC_INTENSET = TCC_INTENSET_OVF_Msk; EIC_REGS->EIC_INTENCLR = (1UL << (uint32_t)pin); EIC_REGS->EIC_INTENSET = (1UL << (uint32_t)pin); if (eicCallbackObject[pin].eicPinNo == pin) { eicCallbackObject[pin].callback = callback; eicCallbackObject[pin].context = context; } EIC_REGS->EIC_INTFLAG = (1UL << 6); if ((eicCallbackObject[6].callback != NULL)) { uintptr_t context = eicCallbackObject[6].context; eicCallbackObject[6].callback(context); }
4. Code :AIR PURIFIER ENGINE MOTOR 3
In this demo, 3-wire BLDC fan is run with PWM frequency of 983.606 kHz directly from Microchip SAM E51
//Created by Mr. Abhishek Bansal
//Company: New Era Consultancy Services
#define EIC_PIN_9 (9U)
typedef struct
{ EIC_CALLBACK callback;
uintptr_t context;
EIC_PIN eicPinNo;
} EIC_CALLBACK_OBJ;
typedef enum
{
TCC3_PWM_STATUS_OVF = TCC_INTFLAG_OVF_Msk,
TCC3_PWM_STATUS_FAULT_0 = TCC_INTFLAG_FAULT0_Msk,
TCC3_PWM_STATUS_FAULT_1 = TCC_INTFLAG_FAULT1_Msk,
TCC3_PWM_STATUS_MC_0 = TCC_INTFLAG_MC0_Msk,
TCC3_PWM_STATUS_MC_1 = TCC_INTFLAG_MC1_Msk,
}TCC3_PWM_STATUS;
EIC_REGS->EIC_CTRLA |= (uint8_t)EIC_CTRLA_SWRST_Msk;
TCC3_REGS->TCC_CTRLA = TCC_CTRLA_SWRST_Msk;
TCC3_REGS->TCC_CTRLA = TCC_CTRLA_PRESCALER_DIV1 | TCC_CTRLA_PRESCSYNC_PRESC ;
TCC3_REGS->TCC_WAVE = TCC_WAVE_WAVEGEN_NPWM | TCC_WAVE_RAMP_RAMP1;
TCC3_REGS->TCC_COUNT = countVal;
TCC3_REGS->TCC_CC[0] = 0U;
TCC3_REGS->TCC_CC[1] = 0U;
TCC3_REGS->TCC_PER = 60U;
TCC3_REGS->TCC_CTRLA &= ~TCC_CTRLA_ENABLE_Msk;
eicCallbackObject[9].eicPinNo = EIC_PIN_9;
while (TCC3_REGS->TCC_SYNCBUSY != 0U)
{ }
TCC3_REGS->TCC_CTRLBSET |= (uint8_t)TCC_CTRLBSET_CMD_READSYNC;
TCC3_REGS->TCC_CTRLBSET |= (uint8_t)TCC_CTRLBCLR_CMD_UPDATE;
bool status = false;
if ((TCC3_REGS->TCC_STATUS & (TCC_STATUS_PERBUFV_Msk)) == 0U)
{
TCC3_REGS->TCC_PERBUF = period;
status = true;
}
TCC3_REGS->TCC_INTENSET = TCC_INTENSET_OVF_Msk;
TCC3_REGS->TCC_INTENCLR = TCC_INTENCLR_OVF_Msk;
uint32_t interrupt_status;
interrupt_status = TCC3_REGS->TCC_INTFLAG;
TCC3_REGS->TCC_INTFLAG = interrupt_status;
(void)TCC3_REGS->TCC_INTFLAG;
bool status = false;
if ((TCC3_REGS->TCC_STATUS & (1UL << (TCC_STATUS_CCBUFV0_Pos + (uint32_t)channel))) == 0U)
{
TCC3_REGS->TCC_CCBUF[channel] = duty;
status = true;
}
EIC_REGS->EIC_INTENCLR = (1UL << (uint32_t)pin);
EIC_REGS->EIC_INTENSET = (1UL << (uint32_t)pin);
if (eicCallbackObject[pin].eicPinNo == pin)
{
eicCallbackObject[pin].callback = callback;
eicCallbackObject[pin].context = context;
}
EIC_REGS->EIC_INTFLAG = (1UL << 9);
if ((eicCallbackObject[9].callback != NULL))
{ uintptr_t context = eicCallbackObject[9].context;
eicCallbackObject[9].callback(context);
}
5. Code : AIR PURIFIER ENGINE MOTOR 4
In this demo, 4-wire BLDC fan is run with PWM frequency of 1.935483 MHz directly from Microchip SAM E51
//Created by Mr. Abhishek Bansal //Company: New Era Consultancy Services #define EIC_PIN_10 (10U) typedef enum { TCC4_PWM_STATUS_OVF = TCC_INTFLAG_OVF_Msk, TCC4_PWM_STATUS_FAULT_0 = TCC_INTFLAG_FAULT0_Msk, TCC4_PWM_STATUS_FAULT_1 = TCC_INTFLAG_FAULT1_Msk, TCC4_PWM_STATUS_MC_0 = TCC_INTFLAG_MC0_Msk, TCC4_PWM_STATUS_MC_1 = TCC_INTFLAG_MC1_Msk, }TCC4_PWM_STATUS; typedef struct { EIC_CALLBACK callback; uintptr_t context; EIC_PIN eicPinNo; } EIC_CALLBACK_OBJ; EIC_REGS->EIC_CTRLA |= (uint8_t)EIC_CTRLA_SWRST_Msk; TCC4_REGS->TCC_CTRLA = TCC_CTRLA_SWRST_Msk; TCC4_REGS->TCC_CTRLA = TCC_CTRLA_PRESCALER_DIV1 | TCC_CTRLA_PRESCSYNC_PRESC ; TCC4_REGS->TCC_WAVE = TCC_WAVE_WAVEGEN_NPWM | TCC_WAVE_RAMP_RAMP1; TCC4_REGS->TCC_CC[0] = 0U; TCC4_REGS->TCC_CC[1] = 0U; TCC4_REGS->TCC_PER = 30U; TCC4_REGS->TCC_CTRLA |= TCC_CTRLA_ENABLE_Msk; TCC4_REGS->TCC_CTRLA &= ~TCC_CTRLA_ENABLE_Msk; bool status = false; if ((TCC4_REGS->TCC_STATUS & (TCC_STATUS_PERBUFV_Msk)) == 0U) { TCC4_REGS->TCC_PERBUF = period; status = true; } if ((TCC4_REGS->TCC_STATUS & (1UL << (TCC_STATUS_CCBUFV0_Pos + (uint32_t)channel))) == 0U) { TCC4_REGS->TCC_CCBUF[channel] = duty; status = true; } eicCallbackObject[10].eicPinNo = EIC_PIN_10; EIC_REGS->EIC_INTENCLR = (1UL << (uint32_t)pin); EIC_REGS->EIC_INTENSET = (1UL << (uint32_t)pin); if (eicCallbackObject[pin].eicPinNo == pin) { eicCallbackObject[pin].callback = callback; eicCallbackObject[pin].context = context; } EIC_REGS->EIC_INTFLAG = (1UL << 10); if ((eicCallbackObject[10].callback != NULL)) { uintptr_t context = eicCallbackObject[10].context; eicCallbackObject[10].callback(context); }
6. Code : Moving Towards Clinical Grade Oximeter
//Created by Mr. Abhishek Bansal
//Company: New Era Consultancy Services
#define SERCOM2_I2CM_SPEED_HZ 100000
#define SERCOM2_I2CM_BAUD_VALUE (0xFFU)
typedef enum
{ SERCOM_I2C_ERROR_NONE,
SERCOM_I2C_ERROR_NAK,
SERCOM_I2C_ERROR_BUS,
} SERCOM_I2C_ERROR;
typedef enum
{
SERCOM_I2C_STATE_ERROR = -1,
SERCOM_I2C_STATE_IDLE,
SERCOM_I2C_STATE_ADDR_SEND,
SERCOM_I2C_REINITIATE_TRANSFER,
SERCOM_I2C_STATE_TRANSFER_READ,
SERCOM_I2C_STATE_TRANSFER_WRITE,
SERCOM_I2C_STATE_TRANSFER_ADDR_HS,
SERCOM_I2C_STATE_TRANSFER_DONE,
} SERCOM_I2C_STATE;
volatile static SERCOM_I2C_OBJ sercom2I2CObj;
uint32_t baudValue = 0U;
float fSrcClkFreq = (float)srcClkFreq;
float fI2cClkSpeed = (float)i2cClkSpeed;
float fBaudValue = 0.0f;
uint32_t baudValue;
uint32_t i2cClkSpeed;
uint32_t i2cSpeedMode = 0;
i2cClkSpeed = setup->clkSpeed;
sercom2I2CObj.writeCount = 0U;
sercom2I2CObj.readCount = 0U;
sercom2I2CObj.address = address;
sercom2I2CObj.readBuffer = rdData;
sercom2I2CObj.readSize = rdLength;
sercom2I2CObj.writeBuffer = wrData;
sercom2I2CObj.writeSize = wrLength;
sercom2I2CObj.transferDir = dir;
sercom2I2CObj.isHighSpeed = isHighSpeed;
sercom2I2CObj.error = SERCOM_I2C_ERROR_NONE;
SERCOM2_REGS->I2CM.SERCOM_CTRLA = SERCOM_I2CM_CTRLA_SWRST_Msk ;
SERCOM2_REGS->I2CM.SERCOM_CTRLB = SERCOM_I2CM_CTRLB_SMEN_Msk;
while((SERCOM2_REGS->I2CM.SERCOM_SYNCBUSY) != 0U)
{ }
SERCOM2_REGS->I2CM.SERCOM_BAUD = SERCOM2_I2CM_BAUD_VALUE;
SERCOM2_REGS->I2CM.SERCOM_CTRLA = SERCOM_I2CM_CTRLA_MODE_I2C_MASTER | SERCOM_I2CM_CTRLA_SDAHOLD_75NS | SERCOM_I2CM_CTRLA_SPEED_STANDARD_AND_FAST_MODE | SERCOM_I2CM_CTRLA_SCLSM(0UL) | SERCOM_I2CM_CTRLA_ENABLE_Msk ;
SERCOM2_REGS->I2CM.SERCOM_STATUS = (uint16_t)SERCOM_I2CM_STATUS_BUSSTATE(0x01UL);
sercom2I2CObj.error = SERCOM_I2C_ERROR_NONE;
sercom2I2CObj.state = SERCOM_I2C_STATE_IDLE;
SERCOM2_REGS->I2CM.SERCOM_INTENSET = (uint8_t)SERCOM_I2CM_INTENSET_Msk;
if (srcClkFreq < (2U * i2cClkSpeed))
{ return false; }
SERCOM2_REGS->I2CM.SERCOM_BAUD = baudValue;
SERCOM2_REGS->I2CM.SERCOM_CTRLA = ((SERCOM2_REGS->I2CM.SERCOM_CTRLA & ~SERCOM_I2CM_CTRLA_SPEED_Msk) | (SERCOM_I2CM_CTRLA_SPEED(i2cSpeedMode)));
SERCOM2_REGS->I2CM.SERCOM_CTRLA |= SERCOM_I2CM_CTRLA_ENABLE_Msk;
SERCOM2_REGS->I2CM.SERCOM_STATUS = (uint16_t)SERCOM_I2CM_STATUS_BUSSTATE(0x01UL);
sercom2I2CObj.callback = callback;
sercom2I2CObj.context = contextHandle;
SERCOM2_REGS->I2CM.SERCOM_ADDR = ((uint32_t)address << 1U) | (dir ? 1UL :0UL);
SERCOM2_REGS->I2CM.SERCOM_INTFLAG = (uint8_t)SERCOM_I2CM_INTFLAG_Msk;
SERCOM2_REGS->I2CM.SERCOM_CTRLB &= ~SERCOM_I2CM_CTRLB_ACKACT_Msk;
SERCOM2_I2C_XferSetup(address, NULL, 0, rdData, rdLength, true, false);
SERCOM2_I2C_XferSetup(address, wrData, wrLength, NULL, 0, false, false);
SERCOM2_I2C_XferSetup(address, wrData, wrLength, rdData, rdLength, false, false);
bool isBusy = true;
if((sercom2I2CObj.state == SERCOM_I2C_STATE_IDLE))
{
if(((SERCOM2_REGS->I2CM.SERCOM_STATUS & SERCOM_I2CM_STATUS_BUSSTATE_Msk) == SERCOM_I2CM_STATUS_BUSSTATE(0x01U)))
{
isBusy = false;
}
}
sercom2I2CObj.error = SERCOM_I2C_ERROR_NONE;
sercom2I2CObj.state = SERCOM_I2C_STATE_IDLE;
SERCOM2_REGS->I2CM.SERCOM_CTRLA &= ~SERCOM_I2CM_CTRLA_ENABLE_Msk;
SERCOM2_REGS->I2CM.SERCOM_CTRLA |= SERCOM_I2CM_CTRLA_ENABLE_Msk;
SERCOM2_REGS->I2CM.SERCOM_STATUS = (uint16_t)SERCOM_I2CM_STATUS_BUSSTATE(0x01UL);
Register 0x11.
Register 0x12.
Register 0x14.
Register: NUM_AVG.
Description: Average samples for Time Slot A = 8 and Time Slot B = 8.
Register: SLOTA_CH1_OFFSET.
Description: 8,176 half scale.
Register: SLOTA_CH2_OFFSET.
Description: 8,176 half scale.
Register: SLOTA_CH3_OFFSET.
Description: 8,176 half scale.
Register: SLOTA_CH4_OFFSET.
Description: 8,176 half scale.
Register: SLOTB_CH1_OFFSET.
Description: 8,176 half scale.
Register: SLOTB_CH2_OFFSET.
Description: 8,176 half scale.
Register: SLOTB_CH3_OFFSET.
Description: 8,176 half scale.
Register: SLOTB_CH4_OFFSET.
Description: 8,176 half scale.
Register: ILED1_COARSE.
Description: 100mA current.
Register: ILED2_COARSE.
Description: 130mA current.
Register: ILED_FINE.
Register: SLOTA_LEDMODE.
Register: SLOTA_NUMPULSES.
Register: SLOTB_LEDMODE.
Register: SLOTB_NUMPULSES.
Register: SLOTA_AFEMODE.
Register: SLOTB_AFEMODE.
Register: SLOTA_GAIN.
Register: SLOTB_GAIN.
Register: ADC_TIMING.
7. Code : Moving Towards Clinical Grade Respiratory Diagnostics
//Created by Mr. Abhishek Bansal
//Company: New Era Consultancy Services
#define LUNG1_BIASCOMP_POS (16U)
#define LUNG1_BIASCOMP_Msk (0x7UL << LUNG1_BIASCOMP_POS)
#define LUNG1_BIASREFBUF_POS (19U)
#define LUNG1_BIASREFBUF_Msk (0x7UL << LUNG1_BIASREFBUF_POS)
#define LUNG1_BIASR2R_POS (22U)
#define LUNG1_BIASR2R_Msk (0x7UL << LUNG1_BIASR2R_POS)
LUNG1_REGS->ADC_CTRLA = ADC_CTRLA_SWRST_Msk;
LUNG1_REGS->ADC_CALIB =(uint16_t)((ADC_CALIB_BIASCOMP((((*(uint32_t*)SW0_ADDR) & ADC1_BIASCOMP_Msk) >> ADC1_BIASCOMP_POS))) \
| ADC_CALIB_BIASR2R((((*(uint32_t*)SW0_ADDR) & ADC1_BIASR2R_Msk) >> ADC1_BIASR2R_POS))
| ADC_CALIB_BIASREFBUF(((*(uint32_t*)SW0_ADDR) & ADC1_BIASREFBUF_Msk)>> ADC1_BIASREFBUF_POS ));
LUNG1_REGS->ADC_CTRLA = ADC_CTRLA_PRESCALER_DIV8;
LUNG1_REGS->ADC_SAMPCTRL = ADC_SAMPCTRL_SAMPLEN(3U);
LUNG1_REGS->ADC_REFCTRL = ADC_REFCTRL_REFSEL_INTVCC1;
LUNG1_REGS->ADC_INPUTCTRL = (uint16_t) ADC_POSINPUT_AIN0 | (uint16_t) ADC_NEGINPUT_GND ;
LUNG1_REGS->ADC_CTRLB = ADC_CTRLB_RESSEL_12BIT | ADC_CTRLB_WINMODE(0U) | ADC_CTRLB_FREERUN_Msk;
LUNG1_REGS->ADC_INTFLAG = ADC_INTFLAG_Msk;
ADC1_REGS->ADC_CTRLA &=(uint16_t) ~ADC_CTRLA_ENABLE_Msk;
ADC1_REGS->ADC_INTENSET = interruptMask;
ADC1_REGS->ADC_CTRLA |= ADC_CTRLA_ENABLE_Msk;
ADC1_REGS->ADC_CTRLA &=(uint16_t) ~ADC_CTRLA_ENABLE_Msk;
ADC1_REGS->ADC_INTENCLR = interruptMask;
uint16_t channel;
channel = ADC1_REGS->ADC_INPUTCTRL;
channel &= (uint16_t)~(ADC_INPUTCTRL_MUXPOS_Msk | ADC_INPUTCTRL_MUXNEG_Msk);
channel |= (uint16_t) positiveInput | (uint16_t) negativeInput;
ADC1_REGS->ADC_INPUTCTRL = channel; uint16_t channel;
channel = ADC1_REGS->ADC_INPUTCTRL;
channel &= (uint16_t)~(ADC_INPUTCTRL_MUXPOS_Msk | ADC_INPUTCTRL_MUXNEG_Msk);
channel |= (uint16_t) positiveInput | (uint16_t) negativeInput;
ADC1_REGS->ADC_INPUTCTRL = channel;
Top Comments