How to put Sleep and Wakeup MCU ATTiny804 for Optimizing Power Consumption of the Circuit? #1088
-
Hello, I'm currently working on a project that involves utilizing the ATTINY804 MCU. The device is powered by three AA Type Battery Cells, which sums up to 4.5 volts. However, its power consumption is remarkably high. I'm looking to optimize my code to conserve power. Could you kindly assist me in resolving this issue? Below is the code snippet I'm using: struct WirelessData {
float volt;
int level1;
int level2;
int level3;
int level4;
};
void setup() {
pinMode(level25Pin, INPUT);
pinMode(level50Pin, INPUT);
pinMode(level100Pin, INPUT);
pinMode(level75Pin, INPUT);
}
float readVoltage() {
analogReference(VDD);
VREF.CTRLA = VREF_ADC0REFSEL_1V5_gc;
uint16_t reading = analogRead(ADC_INTREF);
reading = analogRead(ADC_INTREF);
uint32_t intermediate = 1023UL * 1500;
reading = intermediate / reading;
return reading;
}
void loop() {
WirelessData data;
data.volt = readVoltage();
data.level1 = digitalRead(level25Pin);
data.level2 = digitalRead(level50Pin);
data.level3 = digitalRead(level75Pin);
data.level4 = digitalRead(level100Pin);
// Main code to send structured data.
delay(5000); // Delay 5 seconds between readings
} Question 1:I'm utilizing the code below to obtain the voltage of the circuit. My question is: Does this code consume power every time it runs in the loop? If it does consume a significant amount of power, I plan to execute it after longer intervals. Additionally, could you guide me on how to achieve this? float readVoltage() {
analogReference(VDD);
VREF.CTRLA = VREF_ADC0REFSEL_1V5_gc;
uint16_t reading = analogRead(ADC_INTREF);
reading = analogRead(ADC_INTREF);
uint32_t intermediate = 1023UL * 1500;
reading = intermediate / reading;
return reading;
} Question 2:Could you please provide a code snippet to put the ATTINY804 MCU into Sleep mode or Deep Sleep mode and automatically wake it up after a defined time, for example, 5 seconds? Question 3:I'm uncertain about whether changing the MHz of the MCU can also save power. I'm unaware of how to reduce or increase the MHz of the MCU and what effects it might have on the MCU or the circuit. Could you please provide some guidance? I'm eager to conserve as much power as possible. Thank you. When uploading a program to the ATTINY804, the default selection is 20MHz. If I opt to change it to 8MHz or 1MHz, will it impact the power consumption of the MCU? I'm uncertain about this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Did you read this page? |
Beta Was this translation helpful? Give feedback.
You can't set 5sec with the PIT. 1 sec is the longest you can set it to.
But you can put Tiny to sleep 5 times for one second like how I adapted the example below.