Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
17 votes
6 answers
21k views

Avoiding global variables when using interrupts in embedded systems

Is there a good way of implementing communication between an ISR and the rest of the program for an embedded system which avoids global variables? It seems that the general pattern is to have a ...
user avatar
15 votes
4 answers
5k views

AVR SEI instruction

The AVR SEI instruction (http://www.atmel.com/webdoc/avrassembler/avrassembler.wb_SEI.html) waits for the next instruction to finish before enabling interrupts. If I use another instruction to set ...
jayjay's user avatar
  • 347
10 votes
2 answers
8k views

Any reason not to use Timer0 on AVR?

Just a basic question... For arduino/avr/ATMega328 I find lots of examples using Timer1 (there's even a whole library for it) but rarely any that utilize Timer0 (or Timer2). Now, I know that using ...
Adam Haile's user avatar
  • 1,623
10 votes
2 answers
28k views

Determining which pin triggered a PCINTn interrupt?

Am I correct in thinking that if you have two pins causing the same AVR PCINT interrupt, (e.g. PCINT0 vector caused by either PCINT0 or PCINT1 pins -- I think the naming overlap of vectors and pins is ...
Tom Davies's user avatar
10 votes
2 answers
8k views

AVR interrupt service routine not executing as fast as expected (instruction overhead?)

I'm developing a small logic analyzer with 7 inputs. My target device is an ATmega168 with a 20MHz clock rate. To detect logic changes I use pin change interrupts. ...
arminb's user avatar
  • 1,642
8 votes
3 answers
2k views

ATtiny13A - Can't generate software PWM with CTC mode

I'm trying to make a remote control RGB LED light using an ATtiny13A. I know the ATtiny85 is better suited for this purpose, and I know I might not eventually be able to fit the whole code, but for ...
Pouria P's user avatar
  • 320
7 votes
1 answer
2k views

Tell if interrupts are enabled

Is there a way of telling if sei()/interrupts() or cli()/...
Tyilo's user avatar
  • 377
6 votes
3 answers
10k views

How to read whole data sent to USART with interrupt?

I am currently able to read byte by byte from USART with this code ...
Zgrkpnr__'s user avatar
  • 209
6 votes
4 answers
5k views

Multithreading on AVR

If I have an AVR micro controller and have an ISR coming up about every 100 micro seconds or so, can I change the stack pointer in the ISR and then fake multi threading? Psuedo code: ...
DarthRubik's user avatar
6 votes
2 answers
2k views

Teensy USB Interrupts

I'm trying to learn about interrupts using one of the Teensy USB boards. It's got an AVR AT90USB1286 chip on it. I'm using the code below, and I'm expecting my ISR block to get called and periodically ...
MattyW's user avatar
  • 163
6 votes
2 answers
10k views

Calculate exact timer frequency for ATTiny

Trying to wrap my head around these overflow timers for the ATTinyx5 (45 in this particular case). I seemed to have a great handle on it with the ATMega328 but I cannot get it to work the way I want ...
Adam Haile's user avatar
  • 1,623
6 votes
1 answer
777 views

Time Base ISR Concurrency

This is sort of a "classic" problem, and I think I have a solution, but I want to vet it with this community. I am building a project using the ATtiny88 microcontroller, and I'm programming in avr-gcc....
vicatcu's user avatar
  • 22.9k
6 votes
1 answer
7k views

Handling timer overflow and compare interrupts in ATMega328 (Arduino)

I'm trying to simulate PMW mode on multiple pins in software by controlling a Timer2. I'm using maximum prescaler value to get approximately 60 pulses per second when timer counts to its maximum ...
aliher's user avatar
  • 161
6 votes
1 answer
267 views

Millis versus centis on AVR platform

I am building a device on the AVR platform. The device will need some timing information, so I was thinking of reimplementing Arduino millis-like functionality (...
angelatlarge's user avatar
  • 3,631
5 votes
4 answers
21k views

Understanding interrupts and software button debounce

I'm quite new to AVR programming (avr-gcc). To react on button-press, I am using a PCINT ISR with the internal pull-up resistor enabled like this: ...
Torsten Römer's user avatar
5 votes
2 answers
3k views

How can I control things without using delay?

I have always hated that you couldn't do other things while you used the delay(); function. However, I want to blink a LED or do whatever while using serial, but ...
Anonymous Penguin's user avatar
5 votes
1 answer
3k views

Overflow interrupt firing only once

I've run into an issue where, it appears, my interrupt only fires once, then simply refuses to fire again on my ATMega32U2. I have the following (stripped down) code: ...
Bojangles's user avatar
  • 1,006
5 votes
1 answer
823 views

ATtiny45 pin change interrupt PB5?

On the ATTiny45 data sheets it states that PB5 can be used as a digital IO pin and I want to use it to trigger a pin change interrupt, my only issue is that it is also the reset pin and the moment I ...
Gerharddc's user avatar
  • 285
5 votes
2 answers
840 views

AVR: How optimize cycle-counted ISR to portable code, using inline asm

I'm trying to optimize my RX and TX interrupts to meet maximum execution time of 25 cycles while interrupts are disabled. So far, I have found that code is optimized enough, but pushing and popping ...
jnk0le's user avatar
  • 153
4 votes
3 answers
7k views

AVR ADC performance: interrupts vs. manual conversion

I have a device on ATMega16 microcontroller that is supposed to constantly send ADC measurement results over USART. The controller is operating at 16MHz with an external crystal and ADC prescaler is ...
Ashton H.'s user avatar
  • 811
4 votes
2 answers
2k views

Interrupt fails to change variable, how so?

Problem was virtually undebuggable, the interrupt that was changing a variable would randomly fail to do so, with no apparent pattern; within interrupt code variable would change but outside of it the ...
Raidho Coaxil's user avatar
4 votes
2 answers
863 views

How can I wake up an ATtiny84 microcontroller at specific time of the day?

I am trying to create an alarm that wakes up at a certain time and does a series of instructions. To set the times that it wakes up, I am going to use the headphone of an Android device to send ...
Shane's user avatar
  • 43
4 votes
2 answers
951 views

Race condition in AVR timers

I'm trying to implement a global timer, so that I can call time_us() anywhere in program and the function will return microseconds since program start. I've done this using TIMER2 (8-bit clock) and ...
akrasuski1's user avatar
4 votes
2 answers
193 views

Low power strategy for dealing with spontainious bit flips durring sleep on AVR 8-bit?

I am designing a ATTINY-based circuit that is intended to run unattended for very long periods of time on a very small battery. The device spends almost all of its time in deep sleep, and only wakes ...
bigjosh's user avatar
  • 10.2k
4 votes
2 answers
3k views

Can't set to Fast PWM OCRA mode

Trying to have Fast PWM mode when TOP == ORCA. Works fine with OCA toggle (measuring correct frequency), but doesn't work in ...
Pablo's user avatar
  • 1,561
4 votes
2 answers
1k views

Moving the code and interrupt locations in Arduino

I need to be able to choose between two Arduino apps running on an atmega 1280 (megaavr) at boot time. Therefore I need to move one of those apps to a different location in program memory, and I need ...
Adam Davis's user avatar
  • 20.7k
4 votes
1 answer
5k views

AVR: Timer overflow flag in TIFR [duplicate]

I have a little question about the TOVn flag located in the TIFRn register. The datasheet says, if the ...
Marco's user avatar
  • 1,031
4 votes
1 answer
3k views

Modifying Interrupt Vector Table of Atmega32

A project that I'm working on involves a cycle accurate interrupt service routine. This routine is written in AVR Assembly where I just wrote: ...
tecfreak's user avatar
3 votes
2 answers
4k views

Interrupt Management - Large AVR Projects

This is for the more experienced one's out there. I am currently involved with a large AVR project (using ATMega328) and it's getting confusing with respect to interrupts. The project involves ...
Ankit's user avatar
  • 1,761
3 votes
4 answers
17k views

AVR SPI target with interrupt

For a project, I want to have two microcontrollers talk to each other via an SPI interface. I wrote the following code for the target microcontroller: ...
BoboProg's user avatar
3 votes
2 answers
2k views

Understanding volatile class fields in AVR C++ programs

I'm having some confusion about what members to declare volatile in a program I'm writing in C++ for an AVR microcontroller, with interrupts. When it's plain C it makes sense - the compiler doesn't ...
QuadrupleA's user avatar
3 votes
4 answers
4k views

Arduino interrupts for button input

I have 6 buttons on my printed board, and I'd like to use interrupts on them all, but they don't correspond to the interrupts listed on the specs. Is it true that you cannot choose arbitrary pins to ...
aaaidan's user avatar
  • 563
3 votes
1 answer
3k views

Clearing Flag Bits By Writing 1

Most of the interface devices have various flag bits (that can also raise interrupts if that functionality is provided) used to check the status of the device/operation. Usually they are cleared by ...
Ankit's user avatar
  • 1,761
3 votes
1 answer
1k views

AVR external interrupt triggering by the falling edge: for how long should I keep signal low to guarantee triggering?

The question header appeared to bee too long. I'm sorry for that. So I have a schematic generating a short LOW on INT0 pin of ATmega48PA. From the simulation I figured out that the LOW level will be ...
Roman Matveev's user avatar
3 votes
2 answers
2k views

Timer0 overflow interrupt does not work on ATtiny10

I am trying to use the Timer0 overflow interrupt to make a little project. I used such a timer in the ATtiny45 and it worked, but with ATtiny10 no result. So I tried an easy LED blinking program and ...
sepplhans's user avatar
  • 205
3 votes
1 answer
272 views

AVR diagram of functions calling, ISR and main loop share the same resource

I made a simple diagram of functions calls to illustrate the potential problem which bothering me a little. As you can see, my task_list (which is simple linked ...
bielu000's user avatar
  • 139
3 votes
1 answer
2k views

AVR USART Random Behaviour

I seem to be getting random character in my USART output with an ATMEGA8 uart.c ...
Ankit's user avatar
  • 1,761
3 votes
2 answers
7k views

Use PWM and ISR at same time on AVR

Is it possible to use AVR PWM outputs and ISR interrupts at the same time? I've got a project I'm trying to do on an ATMega328P and I need 3 PWM outputs but ALSO need to be able to use ISR interrupts ...
Adam Haile's user avatar
  • 1,623
3 votes
2 answers
2k views

avr-gcc timer overflow interrupt handler in inline assembly

My current project involves producing 200KHz PWM waveforms using timer 1 in fast PWM mode. I would like to increment a 16-bit counter every time the timer overflows (every 5μS) ...
jms's user avatar
  • 8,681
3 votes
1 answer
5k views

AVR Measuring frequency using external interrupt - where are my cycles going?

I'm using an external interrupt to measure the frequency of a signal, the AVR clock is at 8MHz. I'm essentially counting the ticks between pin toggles using a 16 bit timer (with some handling for ...
Josh's user avatar
  • 291
3 votes
2 answers
325 views

Setting port in main loop causes ISR to starve

The example code initializes an asynchronous timer that is fired every second sets two ports as outputs (PA4, PA6 - LEDs connected) the timer ISR toggles pin PA4 permanently sets pin PA6 to 1 in the ...
Rev's user avatar
  • 10.2k
3 votes
0 answers
430 views

ISR won't modify a global variable (IAR)?

First, some background on what I'm working on. I have a custom board with ATmega324A that I designed as part of a project I'm working on. Originally, software for the uC was written for GCC in Atmel ...
0xd4v3's user avatar
  • 109
2 votes
1 answer
9k views

Global variable in AVR interrupt routine

I am writing a code with interrupt routine. For debugging the code am using UART. So, here is the snippet: ...
gzix's user avatar
  • 403
2 votes
2 answers
9k views

How many external interrupts has attiny85?

The title is quite self descriptive. I ask this question because I found contradicting information in the atmel web page. I need two external interrupts to control one rotary encoder. One interrupt ...
Terrik's user avatar
  • 123
2 votes
2 answers
1k views

Can't trigger AVR ADC Interrupt

I am using an Atmel's XPlained mini board with Atmega328PB. I am trying to use ADC interrupt, however I can't get it to fire. Here's the code that I have a problem with: ...
Anthropomorphous Dodecahedron's user avatar
2 votes
1 answer
2k views

AVR: why each Interrupt Vector occupies two instruction words

During my study of Atmega328 datasheet I found that each interrupt vector occupies two addresses and after searching i can not find why that. That is a screen shot from atmega328p datasheet page 82
M Y's user avatar
  • 239
2 votes
2 answers
2k views

Missed Interrupt Problem with Attiny85

I'm trying to use an Attiny85 (digispark) to wake another controller from sleep (an ESP8266). The Attiny is connected to an IR receiver which has an active low output. Basically I have connected an ...
localhost's user avatar
  • 302
2 votes
1 answer
20k views

AVR Timer1 OCR1A controls TIMER1_COMPB_vect interrupt!

I was struggling with timer interrupts in my project. I couldn't make it work properly. So I decided writing a simple code and I saw a very interesting case. ...
Zgrkpnr__'s user avatar
  • 209
2 votes
2 answers
18k views

Toggle OC1A, OC1B and OC1C using timer in CTC mode

Most AVR microcontrollers got three dedicated pins for each timer (for example, OC1A, OC1B, and OC1C) that can be toggled automatically when the counter reaches the so called top value in the ...
Muayyad Alsadi's user avatar