Updated pendulum.c, timer.h/.c to use timer.h/.c

This commit is contained in:
Max Braungardt 2018-04-04 19:37:26 +02:00
parent 0497b5f531
commit 8079072422
3 changed files with 15 additions and 37 deletions

View File

@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include "timer.h"
#include "color_hsv.h" #include "color_hsv.h"
#define HUE_MAX 610 #define HUE_MAX 610
#define HUE_MIN 350 #define HUE_MIN 350
@ -39,7 +40,7 @@ uint8_t volatile triggered = 0;
// On External Interrupt: // On External Interrupt:
ISR(INT1_vect) { ISR(INT1_vect) {
uint32_t now = time + TCNT1; uint32_t now = timer_now32(); // time + TCNT1;
//~ triggered = (triggered + 1) % 4; //~ triggered = (triggered + 1) % 4;
if(now > cooldown) { if(now > cooldown) {
triggered = true; triggered = true;
@ -59,6 +60,7 @@ ISR(INT1_vect) {
TCNT0 = 0; // Reset Timer/Counter0 TCNT0 = 0; // Reset Timer/Counter0
time = 0; time = 0;
oldTime = 0; oldTime = 0;
timer_reset();
} }
//~ triggered = 0; //~ triggered = 0;
min = HUE_MID; min = HUE_MID;
@ -67,9 +69,10 @@ ISR(INT1_vect) {
} }
//~ // On Timer Overflow Interrupt: //~ // On Timer Overflow Interrupt:
ISR(TIMER1_OVF_vect) { //~ ISR(TIMER1_OVF_vect) {
time += 0x00010000; //~ // time += 0x00010000;
} //~ timer_overflow();
//~ }
int main(void) { int main(void) {
@ -90,33 +93,8 @@ int main(void) {
DDRC = 0x3f; // Digital Direction PORTC[5:0] = output DDRC = 0x3f; // Digital Direction PORTC[5:0] = output
PORTC = 0x00; PORTC = 0x00;
// Timer concatenation timer_init();
// Timer 2 (8 Bit, 50 ns) timer_reset();
//~ DDRB |= 0x08; // Digital Direction PORTB3 = output (PIN17 OC2A)
//~ PORTB |= 0x08; // POTRB3 = HIGH
//~ TCNT2 = 0x00; // Timer/Counter2 value register clear
//~ OCR2A = 0xff; // Timer/Counter2 output compare register A
//~ TIMSK2 |= 0x02; // Timer/Counter2 Interrupt Mask Register
//~ // Enable compare A match interrupt
//~ TCCR2A |= 0x40; // Timer/Counter2 Control Register A
//~ // Toggle OC2A on compare match
//~ TCCR2B |= 0x01; // Timer/Counter2 Control Register B
//~ // Prescale Factor 1
//~ // Timer 1 (16 Bit, 25.55 µs)
//~ DDRB |= 0x02; // Digital Direction PORTB1 = output (PIN15 OC1A)
//~ PORTB |= 0x02; // POTRB1 = HIGH
//~ TCNT1 = 0x0000; // Timer/Counter1 value register clear
//~ OCR1A = 0xffff; // Timer/Counter1 output compare register A
//~ TIMSK1 |= 0x02; // Timer/Counter1 Interrupt Mask Register
//~ // Enable compare register A match interrupt
//~ TCCR1A |= 0x40; // Timer/Counter1 Control Register A
//~ // Toggle OC1A on compare match
//~ TCCR1B |= 0x07; // Timer/Counter1 Control Register B
//~ // External Clock Source on T1 (PIN11) on rising edge
//~ // Timer 0 (8 Bit, 3,34891515 s)
//~ TCNT0 = 0x00; // Timer/Counter0 value register clear
//~ TCCR0B |= 0x07; // Timer/Counter0 Control Register B
//~ // External clock source on T0 (PIN6, PD4) on rising edge
// Init color // Init color
hsv_t colorsHSV[LEDS]; hsv_t colorsHSV[LEDS];
@ -150,7 +128,7 @@ int main(void) {
//~ uint64_t time1 = TCNT1; //~ uint64_t time1 = TCNT1;
//~ uint64_t time0 = TCNT0; //~ uint64_t time0 = TCNT0;
//~ uint64_t now = time2 | (time1 << 9) | (time0 << 26); //~ uint64_t now = time2 | (time1 << 9) | (time0 << 26);
uint32_t now = time + TCNT1; uint32_t now = timer_now32(); // time + TCNT1;
//~ if(now > delay) { //~ if(now > delay) {
//~ PORTC |= 0x08; // PORTC3 = HIGH //~ PORTC |= 0x08; // PORTC3 = HIGH
//~ } //~ }

View File

@ -31,8 +31,8 @@ void timer_reset(void)
highBits64 = 0; highBits64 = 0;
} }
// ISR(TIMER1_OVF_vect) ISR(TIMER1_OVF_vect)
void timer_overflow(void) //~ void timer_overflow(void)
{ {
highBits32 += 0x01000000; highBits32 += 0x01000000;
highBits64 += 0x0000000001000000; highBits64 += 0x0000000001000000;

View File

@ -7,9 +7,9 @@
void timer_init(void); void timer_init(void);
void timer_reset(void); void timer_reset(void);
void timer_overflow(void); // void timer_overflow(void);
// ISR(TIMER1_OVF_vect); ISR(TIMER1_OVF_vect);
uint32_t timer_now32(void); uint32_t timer_now32(void);
uint64_t timer_now64(void); uint64_t timer_now64(void);