Compare commits

...

2 Commits

Author SHA1 Message Date
Sven Vogel 6eaf4518fa added advanced interrupt handler 2023-10-31 13:18:52 +01:00
Sven Vogel bc915a7a3f added interrupt for summer and build src filter 2023-10-31 13:04:32 +01:00
9 changed files with 134 additions and 17 deletions

View File

@ -12,3 +12,13 @@
platform = atmelavr
board = nanoatmega328
framework = arduino
build_src_filter =
+<*>
-<.git/>
-<.svn/>
-<blink/>
-<button_interupt/>
-<button_poll/>
-<trafficlight/>
-<summer/>
+<summer_controlled/>

View File

@ -4,8 +4,6 @@
#include "button.h"
#ifdef BUTTON_INTERRUPT
ISR(INT0_vect)
{
PORTB = 0;
@ -43,5 +41,3 @@ void init() {
void loop() {
}
#endif

View File

@ -10,8 +10,6 @@
// PORTx set bit of port value
// PINx read voltage of bit of port D
#ifdef BUTTON_POLL
void init() {
// ---------------------------------------
// set Port B to output
@ -43,5 +41,3 @@ void loop() {
CLR_BIT(PORTB, DDB5);
}
}
#endif

View File

@ -5,12 +5,9 @@ extern void loop();
//#include "blink/blink.h"
//#include "button_poll/button.h"
//#include "button_interupt/button.h"
#include "trafficlight/trafficlight.h"
//#define BLINK
//#define BUTTON_POLL
//#define BUTTON_INTERRUPT
#define TRAFFIC_LIGHT
//#include "trafficlight/trafficlight.h"
//#include "summer/summer.h"
#include "summer_controlled/summer.h"
int main() {
init();

30
src/summer/summer.cpp Normal file
View File

@ -0,0 +1,30 @@
//
// Created by servostar on 30.10.23.
//
#include "summer.h"
ISR (TIMER0_COMPA_vect)
{
PORTB = ~PORTB;
}
void init() {
DDRB = 255;
PORTB = 0;
TCCR0A |= (1 << WGM01); // set timer to CTC
OCR0A = 0x70; // count up to this value 440Hz
// OCR0A = 0x117; // count up to this value 265Hz
TIMSK0 |= (1 << OCIE0A); // enable timer 0
TCCR0B |= (1 << CS02) | (1 << CS00); // start timer and set prescaler to 1024
sei(); // enable interrupts
}
void loop() {
}

13
src/summer/summer.h Normal file
View File

@ -0,0 +1,13 @@
//
// Created by servostar on 30.10.23.
//
#ifndef ARDUINO_SUMMER_H
#define ARDUINO_SUMMER_H
#include "prelude.h"
void init();
void loop();
#endif //ARDUINO_SUMMER_H

View File

@ -0,0 +1,65 @@
//
// Created by servostar on 30.10.23.
//
#include "summer.h"
void setup_summer_it();
void setup_button_it();
ISR (TIMER0_COMPA_vect)
{
PORTB = ~PORTB;
}
ISR(INT0_vect)
{
OCR0A = 18; // count up to this value 440Hz
}
ISR(INT1_vect)
{
OCR0A = 30; // count up to this value 265Hz
}
void init() {
setup_summer_it();
setup_button_it();
sei(); // enable interrupts
}
void setup_button_it() {
// set Port D to input (bit 2/3, remember bit 0/1 are for UART)
SET_INPUT(DDRD, DDD2);
SET_INPUT(DDRD, DDD3);
// put 5V on input (make it pull up resistor)
SET_BIT(PORTD, DDD2);
SET_BIT(PORTD, DDD3);
// configure interrupt mode
SET_INTERRUPT_MODE(0, FALLING);
SET_INTERRUPT_MODE(1, FALLING);
// enable interrupt 0 and 1
ENABLE_INTERRUPT(0);
ENABLE_INTERRUPT(1);
}
void setup_summer_it() {
DDRB = 255;
PORTB = 0;
TCCR0A |= (1 << WGM01); // set timer to CTC
OCR0A = 0x70; // count up to this value 440Hz
// OCR0A = 0x117; // count up to this value 265Hz
TIMSK0 |= (1 << OCIE0A); // enable timer 0
TCCR0B |= (1 << CS02) | (1 << CS00); // start timer and set prescaler to 1024
}
void loop() {
}

View File

@ -0,0 +1,13 @@
//
// Created by servostar on 30.10.23.
//
#ifndef ARDUINO_SUMMER_H
#define ARDUINO_SUMMER_H
#include "prelude.h"
void init();
void loop();
#endif //ARDUINO_SUMMER_H

View File

@ -4,8 +4,6 @@
#include "trafficlight.h"
#ifdef TRAFFIC_LIGHT
void init() {
// set Port B bit 0,1,2 to output mode
DDRB = 0b00000111;
@ -31,4 +29,3 @@ void loop() {
// set to red
PORTB ^= 0b00000110;
}
#endif