You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firstly, thank you for the monumental effort of providing megaTinyCore.
My tests on megaTinyCore ef7b787 show that ADCPowerOptions(ADC_DISABLE) enabled the ADC and ADCPowerOptions(ADC_ENABLE) disables it. This is the opposite of what I expected.
I am using an ATtiny826. So, for a series-2 device:
void ADCPowerOptions(uint8_t options) {
contains
if (options & 0x20) {
if (options & 0x10) {
temp |= 1; // ADC on
} else {
temp &= 0xFE; // ADC off
}
}
from Arduino.h for series-2, the relevant options can be
#define ADC_ENABLE 0x20
#define ADC_DISABLE 0x30
temp.bit0 needs to be 1 to run the ADC according to spec 30.5.1 for ADC.CTRLA
Following the code,
ADC_ENABLE will do “ADC off”
ADC_DISABLE will do “ADC on”
Tested with a 10R resistor in the ATtiny826 VDD line:
With ADCPowerOptions(ADC_DISABLE), there is 1mV across the 10R, implying about 100uA.
With ADCPowerOptions(ADC_ENABLE), there is 0mV across the 10R, implying < 10uA (accuracy limited by my multimeter).
Code is
#define MILLIS_USE_TIMERNONE 1
#if defined(__AVR_ATtiny826__) || defined(__AVR_ATtiny1626__) || defined(__AVR_ATtiny3226__)
#else
#error "Only ATtiny Series 2 supported."
#endif
#include <avr/sleep.h>
void RTC_init(void)
{
/* Initialize RTC: */
while (RTC.STATUS > 0)
{
; /* Wait for all register to be synchronized */
}
RTC.CLKSEL = RTC_CLKSEL_INT32K_gc; /* 32.768kHz Internal Ultra-Low-Power Oscillator (OSCULP32K) */
RTC.PITINTCTRL = RTC_PI_bm; /* PIT Interrupt: enabled */
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc /* RTC Clock Cycles 16384, resulting in 32.768kHz/16384 = 2Hz */
| RTC_PITEN_bm; /* Enable PIT counter: enabled */
}
ISR(RTC_PIT_vect)
{
RTC.PITINTFLAGS = RTC_PI_bm; /* Clear interrupt flag by writing '1' (required) */
}
void setup() {
// PA0 is the UPDI programming pin
pinMode(PIN_PA1, OUTPUT);
pinMode(PIN_PA2, OUTPUT);
pinMode(PIN_PA3, OUTPUT);
pinMode(PIN_PA4, OUTPUT);
pinMode(PIN_PA5, OUTPUT);
pinMode(PIN_PA6, OUTPUT);
pinMode(PIN_PA7, OUTPUT);
pinMode(PIN_PB0, OUTPUT);
pinMode(PIN_PB1, OUTPUT);
pinMode(PIN_PB2, OUTPUT);
pinMode(PIN_PB3, OUTPUT);
pinMode(PIN_PB4, OUTPUT);
pinMode(PIN_PB5, OUTPUT);
pinMode(PIN_PC0, OUTPUT);
pinMode(PIN_PC1, OUTPUT);
pinMode(PIN_PC2, OUTPUT);
pinMode(PIN_PC3, OUTPUT);
ADCPowerOptions(ADC_ENABLE);
RTC_init(); /* Initialize the RTC timer */
set_sleep_mode(SLEEP_MODE_PWR_DOWN); /* Set sleep mode to POWER DOWN mode */
sleep_enable(); /* Enable sleep mode, but not going to sleep yet */
}
void loop() {
digitalWrite(PIN_PA5, HIGH);
sleep_cpu(); /* Sleep the device and wait for an interrupt to continue */
digitalWrite(PIN_PA5, LOW);
digitalWrite(PIN_PA4, CHANGE); /* Device woke up and toggle LED on pin#7 */
}
The text was updated successfully, but these errors were encountered:
Firstly, thank you for the monumental effort of providing megaTinyCore.
My tests on megaTinyCore ef7b787 show that ADCPowerOptions(ADC_DISABLE) enabled the ADC and ADCPowerOptions(ADC_ENABLE) disables it. This is the opposite of what I expected.
I am using an ATtiny826. So, for a series-2 device:
contains
from Arduino.h for series-2, the relevant options can be
temp.bit0 needs to be 1 to run the ADC according to spec 30.5.1 for ADC.CTRLA
Following the code,
Tested with a 10R resistor in the ATtiny826 VDD line:
Code is
The text was updated successfully, but these errors were encountered: