Hello everyone,
I'm trying to get started with interrupt programming for a project in which I want to measure voltages and other things under real time conditions. First of all I wanted to try a very simple program, where the Teensy creates a square wave signal by toggling an output pin on every timer overflow. Therefore I used the following code:
Later I want to try a PWM signal, with adjustable pulse width and frequency, but first the square wave is already a problem.
I'm not really sure, but I think I have to put the digitalWrite function into the ISR(){} or could the code above also work?
The Arduino software throws an error at me, that it expects a constructor or destructor before "(" is used in ISR(TIMER0_OVF_vect). Did I do something wrong including the libraries or is something in the code missing?
Am I on the right track with my approach?
Thank you in advance
I'm trying to get started with interrupt programming for a project in which I want to measure voltages and other things under real time conditions. First of all I wanted to try a very simple program, where the Teensy creates a square wave signal by toggling an output pin on every timer overflow. Therefore I used the following code:
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#define PWM_PIN 2
volatile byte PWMState = LOW;
void setup() {
pinMode(PWM_PIN, OUTPUT);
}
ISR(TIMER0_OVF_vect)
{
if(PWMstate == LOW){
PWMstate = HIGH;
} else {
PWMstate = LOW;
}
}
void loop() {
digitalWrite(PWM_PIN, PWMstate);
}
Later I want to try a PWM signal, with adjustable pulse width and frequency, but first the square wave is already a problem.
I'm not really sure, but I think I have to put the digitalWrite function into the ISR(){} or could the code above also work?
The Arduino software throws an error at me, that it expects a constructor or destructor before "(" is used in ISR(TIMER0_OVF_vect). Did I do something wrong including the libraries or is something in the code missing?
Am I on the right track with my approach?
Thank you in advance