Low Power Application on SAMC2x Using Harmony v3 Peripheral Libraries: Step 3

Step 3.1: Configure ADC Peripheral Library

1

Under the bottom left tab, Device Resources, expand Harmony > Peripherals > ADC.
Double-click or drag and drop ADC1 to add the Analog-to-Digital Converter (ADC) Peripheral Library (PLIB) to the project graph.

adc_adding.png

2

Configure ADC PLIB to sample and convert the light sensor input. ADC is also configured to generate an interrupt (and thereby wakeup CPU) when the ADC result is greater than a set threshold value.

adc_config1.png
  • When the light sensor is not covered (light is falling on the sensor), the phototransistor is turned on. The ADC input is ~0V and the ADC RESULT register is close to 0x00.
  • When the light sensor is covered (light is not falling on the sensor), the phototransistor is turned off. The ADC input is ~3.3V and the ADC RESULT register will be saturated (0xFF).
  • The ADC RESULT register is compared with the Window Lower Threshold (WINLT), which is set to 150.
  • When the light sensor is covered (ADC RESULT > WINLT), an ADC Window Monitor interrupt is generated. This interrupt is used to bring the CPU out of IDLE/STANDBY Sleep mode when the user covers the light sensor.
adc_config2.png

Select ADC1 and configure as shown below.

a

Select Prescaler: Divides the ADC input clock with the configured pre-scaler value and provides more sampling time (CLKADC = 48 MHz/256 = 187500 Hz).

b

Select Reference: ADC reference voltage = 3.3V

c

Select Conversion Trigger: Use hardware trigger

d

Enable Start Event Input: Configures ADC to start conversion when an event is received from the Event System

e

Select Positive Input: The light sensor is connected to AIN10 pin of ADC

f

Select Result Resolution: 8-bit result (ADC conversion value range from 0 to 255)

g

Window Mode Configuration: Allows the conversion result in the RESULT register to be compared to predefined threshold values.

h

Select Window Monitor Mode: Mode1: Result > WINLT. A Window Monitor Interrupt is generated when the ADC result is greater than the configured Window Lower Threshold value.

  • Window Upper Threshold: Sets the upper threshold of the window comparator. It is set to 0 as the ADC resolution is 8-bit.
  • Window Lower Threshold: Sets the lower threshold of the window comparator. It is set to 150. This means that the ADC Window Monitor Interrupt will be generated when the ADC result is greater than 150. This value is decided based on the light sensor voltage when we cover the light sensor it approximately generates 2.2V. Hence threshold is set near to this voltage.
  • Enable Window Monitor Interrupt: A Window Monitor Interrupt is generated when the ADC result is greater than the configured Window Lower Threshold.
adc_setup.png

3

Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration. Go to the Pin Settings tab and configure PA08 (Pin #17) as ADC_AIN10 pin.

adc_pin_configuration.png

Step 3.2: Configure EIC Peripheral Library for Switch

1

Under the Device Resources tab, expand Harmony > Peripherals > EIC.

Double-click on EIC to add the project.

eic_selection.png

Select the EIC peripheral library and configure it to produce an interrupt when switch SW0 is pressed.

eic_configuration.png

2

Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration. Go to the Pin Settings tab and configure PA28 (Pin #53) as EIC_EXTINT8 pin.

eic_pin_configuration.png

Note: EIC is configured to produce an interrupt whenever switch is pressed. This feature is used to measure the wake up time from Sleep mode. EIC is configured to run on internal low power 32 kHz clock. A switch press is also one of the sources to wake the device up from Sleep mode.

Step 3.3: Configure Event System Peripheral Library

1

Event System (EVSYS) is added by default to the project graph. Launch Event System Configuration window by going to the Project Graph tab in MPLAB® X IDE and then selecting Plugins > Event System Configuration.

event_systems_select.png

A new tab, EVENT0 Easy View, will open.

event_systems_blank.png

2

Add and configure Event System Channel 0 with:
• RTC compare 0 match as the event generator
• ADC1 Start of Conversion as the event user

Note: Make sure that the status of the event and user (Event Status and User Ready) is green in color. If it is red, verify if the Event Output and Event Input is enabled in the respective (RTC and ADC) PLIB configuration.

event_systems_config.png



Next Step >

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.