Comments (5)
Timer 0 is by default used for millis/micros(), and is initialized before setup(). it is bein initialised in the init() function:
MightyCore/avr/cores/MCUdude_corefiles/main.cpp
Lines 33 to 51 in b360c00
If you want to run code natively, without the Arduino framework, ditch setup() and loop() in your sketch, and use this instead:
#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <util/delay.h>
int main() {
DDRC |= (1 << PC2) | (1 << PC1); // leds for testing
DDRD &= ~(1 << PD2); // INT0: input...
PORTD |= (1 << PD2); // ...with pullup.
// level interrupt INT0 (low level)
MCUCR &= ~((1 << ISC01) | (1 << ISC00));
while(1) {
// trigger leds for testing
PORTC ^= (1 << PC1);
_delay_ms(500);
PORTC ^= (1 << PC1);
// enable external interrupt
GICR |= (1 << INT0);
// set sleep mode
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
// sleep_mode() has a possible race condition
sleep_enable();
sei();
sleep_cpu();
sleep_disable();
// waking up...
// disable external interrupt here, in case the external low pulse is too long
GICR &= ~(1 << INT0);
// disable all interrupts
cli();
}
}
ISR(INT0_vect)
{
// ISR might be empty, but is necessary nonetheless
PORTC ^= (1 << PC2); // debugging
}
from mightycore.
I don't get you. My problem is millis() return the same value after my above code wakeup from INT0 interrupt. My guess is that my deep sleep code disable the TImer0.
from mightycore.
SLEEP_MODE_POWER_DOWN stops timer0 as well:
from mightycore.
Yes, but when wakeup from PIN interrupt, the loop() run as usual but timer0 still not working. I also call sleep_disable() but still not working.
from mightycore.
At sei() after wakeup solved the problem.
from mightycore.
Related Issues (20)
- Atmega32-16u get error use encoder library HOT 2
- Can't update boards.txt HOT 3
- Custom baud? HOT 2
- How to Solve avrdude.conf errors when programming Atmega324PB with USBasp and MightyCore on Arduino 1.8.19 HOT 4
- 10MHz external clock support HOT 1
- I cant compile code using mighty core even tho the code compilers using normal arduino , error exec: "cmd": executable file not found in %PATH% HOT 7
- Perhaps some setting of the delay/clock functions need to be revised. HOT 2
- Atmega324pb: OC1b vs XCK1, OC2A vs XCK2 HOT 6
- Feature request: add linuxgpio programmer to programmer options in arduino IDE HOT 7
- arduino-cli compile with --output-dir flag set fails to build *.with_bootloader.hex file. HOT 9
- ATmega1284 clock source fuses are not set HOT 9
- ATmega32A reset after upload. HOT 6
- ATmega32 Serial doesn't work HOT 1
- No variants for ATmega32? HOT 2
- ATmega32 millis is not right using the 8 MHz internal oscillator? HOT 2
- Keep failure to flash the optiboot loader to the ATMEGA128P HOT 4
- urboot copy_flash_pages HOT 8
- Arduino IDE option for optiboot with version 3.0.0 HOT 12
- Error while burning bootloader (while using v3.0) HOT 1
- LED flashing on A, C, D, Atmega16 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mightycore.