DEVportal
API and Examples for the nPZero
Loading...
Searching...
No Matches
ADC Example

Description

This example demonstrates the usage of the nPZero driver to setup the ADC and there threshould's. Booth ADC's (Internal and External) are set in the example code, the ADC_IN pin for this example is connected to VDD.

Code Example ADC

Code snippet ...

  • The example will firstly set the Over and Under threshold registers for ADC's in the nPZero after is the setting of the device structure...
/*****************************************************************************
* Includes
*/
#include "example_adc.h"
#include "../../Drivers/nPZero_Driver/Inc/np0_device_control.h"
#include <stdio.h>
/****************************************************************************
* Private Methods
*/
np0_adc_config_channels_s np0_adc_internal_config = {
.over_threshold = 0x0B, // 2Vdc
.under_threshold = 0x06, // 1.6Vdc
};
np0_adc_config_channels_s np0_adc_external_config = {
.over_threshold = 0x2D, // 2.2Vdc
.under_threshold = 0x26, // 1.6Vdc
};
np0_device_config_s np0_config_ext_adc = {
.power_switch_normal_mode_per1 = 0,
.power_switch_normal_mode_per2 = 0,
.power_switch_normal_mode_per3 = 0,
.power_switch_normal_mode_per4 = 0,
.power_switch_gate_boost_host = 0,
.power_switch_gate_boost_peripherals = 0,
.system_clock_divider = SCLK_DIV_DISABLE,
.system_clock_source = SYS_CLOCK_10HZ,
.io_strength = IO_STR_NORMAL,
.i2c_pull_mode = I2C_PULL_DISABLE,
.spi_auto = SPI_PINS_ALWAYS_ON,
.xo_clock_out_sel = XO_CLK_OFF,
.wake_up_per1 = 0,
.wake_up_per2 = 0,
.wake_up_per3 = 0,
.wake_up_per4 = 0,
.wake_up_any_or_all = WAKEUP_ANY,
.global_timeout = 0x0BB8,
.interrupt_pin_pull_up_pin1 = INT_PIN_PULL_DISABLED,
.interrupt_pin_pull_up_pin2 = INT_PIN_PULL_DISABLED,
.interrupt_pin_pull_up_pin3 = INT_PIN_PULL_DISABLED,
.interrupt_pin_pull_up_pin4 = INT_PIN_PULL_DISABLED,
.adc_ext_sampling_enable = ENABLED,
.adc_clock_sel = ADC_CLK_256,
.adc_channels = {0, &adc_ext_channel_2},
.peripheral = {0, 0, 0, 0},
};
np0_device_config_s np0_config_int_adc = {
.power_switch_normal_mode_per1 = 0,
.power_switch_normal_mode_per2 = 0,
.power_switch_normal_mode_per3 = 0,
.power_switch_normal_mode_per4 = 0,
.power_switch_gate_boost_host = 0,
.power_switch_gate_boost_peripherals = 0,
.system_clock_divider = SCLK_DIV_DISABLE,
.system_clock_source = SYS_CLOCK_10HZ,
.io_strength = IO_STR_NORMAL,
.i2c_pull_mode = I2C_PULL_DISABLE,
.spi_auto = SPI_PINS_ALWAYS_ON,
.xo_clock_out_sel = XO_CLK_OFF,
.wake_up_per1 = 0,
.wake_up_per2 = 0,
.wake_up_per3 = 0,
.wake_up_per4 = 0,
.wake_up_any_or_all = WAKEUP_ANY,
.global_timeout = 0x0BB8,
.interrupt_pin_pull_up_pin1 = INT_PIN_PULL_DISABLED,
.interrupt_pin_pull_up_pin2 = INT_PIN_PULL_DISABLED,
.interrupt_pin_pull_up_pin3 = INT_PIN_PULL_DISABLED,
.interrupt_pin_pull_up_pin4 = INT_PIN_PULL_DISABLED,
.adc_ext_sampling_enable = 0,
.adc_clock_sel = ADC_CLK_256,
.adc_channels = {&adc_int_channel_1, 0},
.peripheral = {0, 0, 0, 0},
};
/*****************************************************************************
* Public Methods
*/
void example_adc_external(np0_device_config_s *np0_config)
{
printf("Executing external ADC example\r\n");;
*np0_config = np0_config_ext_adc;
np0_device_configure(np0_config);
}
void example_adc_internal(np0_device_config_s *np0_config)
{
printf("Executing internal ADC example\r\n");;
*np0_config = np0_config_int_adc;
np0_device_configure(np0_config);
}
*
@ ADC_CLK_256
Definition: np0.h:138
@ INT_PIN_PULL_DISABLED
Definition: np0.h:180
@ SYS_CLOCK_10HZ
Definition: np0.h:119
@ SCLK_DIV_DISABLE
Definition: np0.h:126
@ HOST_POWER_MODE_LOGIC_OUTPUT
Definition: np0.h:40
@ ENABLED
Definition: np0.h:157
@ WAKEUP_ANY
Definition: np0.h:201
@ XO_CLK_OFF
Definition: np0.h:145
void np0_device_configure(np0_device_config_s *device_config)
Setup np0 device configuration.
Definition: np0.h:520
uint8_t wakeup_enable
Definition: np0.h:523
Definition: np0.h:597
np0_host_power_mode_e host_power_mode
Definition: np0.h:603

Note

  • Adapt the code example to match your MCU throw np0_hal_read and np0_hal_write.
  • Consult the nPZero driver function documentation for precise function usage.