Skip to content
Snippets Groups Projects
Commit 909c7cc3 authored by Markus Scheck's avatar Markus Scheck
Browse files

deleted unused programms

parent b5682c64
No related branches found
No related tags found
No related merge requests found
Showing
with 5 additions and 101 deletions
// all functions inline to save execution time
// initialize timer for time measurement
inline void timer_init(void);
// start time measurement
inline void timer_start(void);
// stop time measurement, return ticks
inline uint32_t timer_stop(void);
// get timer ticks
inline uint32_t timer_ticks(void);
// This module uses TIMER1 to keep track of time
#include "timer_1.h"
#include <avr/interrupt.h>
uint32_t overflow_count;
#define TIMER_MASK (1<<CS10)
inline void timer_init(void) {
// enable overflow interrupt
TIMSK1 |= (1<<TOIE1);
}
inline void timer_start(void) {
//disable interrupts globally
cli();
//clear out timer counting register
TCNT1 = 0;
//clear overflow count
overflow_count = 0;
// set up clock source
// we have a 16MHz Clock
// and a 16 Bit timer
// Use a prescaler of 256 -> 16/256 = 62.5kHz
TCCR1B |= TIMER_MASK;
//enable interrupts
sei();
}
inline uint32_t timer_ticks(void) {
return TCNT1 ^ (overflow_count << 16);
}
inline uint32_t timer_stop(void) {
// stop timer clock
TCCR1B &= ~(TIMER_MASK);
return timer_ticks();
}
ISR(TIMER1_OVF_vect) {
overflow_count++;
}
...@@ -71,6 +71,8 @@ inline void tp_i2c(uint16_t len) { ...@@ -71,6 +71,8 @@ inline void tp_i2c(uint16_t len) {
recv_data(); recv_data();
} }
transmit_stop(); transmit_stop();
delayMicroseconds(20); delayMicroseconds(5); // wait for hardware to create stop cond
// may need to be altered for slow bit speeds
// hardware needs time to latch the request for a stop
} }
} }
...@@ -13,20 +13,10 @@ int main(void) { ...@@ -13,20 +13,10 @@ int main(void) {
// initialize pin change interrupt // initialize pin change interrupt
init_pc(); init_pc();
// enable interrupts // enable interrupts
sei(); sei();
// notify user of starting test
//Serial.println("begin sending...");
// start timer
//timer_start();
// start i2c test procedure
//tp_i2c();
// timer will be stopped in pc interrupt somewhere here
// notify user of test ending. May be interrupted due to pin change / timer stop
//Serial.println("End sending");
for(uint16_t i = 0; i < 1024; i++) { for(uint16_t i = 0; i < 1024; i++) {
Serial.print(i+1); Serial.print(i+1);
Serial.print(" : "); Serial.print(" : ");
...@@ -43,5 +33,5 @@ int main(void) { ...@@ -43,5 +33,5 @@ int main(void) {
// do nothing // do nothing
while(1) { while(1) {
} }
} }
// all functions inline to save execution time
inline void init_pc(void);
// This module uses PIN CHANGE INTERRUPT INT3
#include <avr/interrupt.h>
#include <avr/io.h>
#include "timer_1.h"
//initialize pin change interrupt and data directions
inline void init_pc(void) {
// enable/ setup output port
DDRA = 0xff; // all out
PORTA = 0x00; // all low
// enable input port
// enable interrupt
EICRA |= (1<<ISC30)|(1<<ISC31);
EIMSK |= (1<<INT3);
}
ISR(INT3_vect) {
// stop timer, print measured tick count to user
Serial.println(timer_stop());
}
// all functions inline to save execution time
inline void init_i2c(void);
// all functions inline to save execution time
inline void init_pc(void);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment