Moderators: adafruit_support_bill, adafruit
/*
Written 2007 by Michael Witt
Designed for the ATTiny13 AVR MCU
Changes can be made to accomodate different mcus
frequency counter v2
Referenced: http://www.atmel.com/avr
www.ladyada.net
I am not liable for any damages caused by any means by this code.
Don't agree? Don't use it.
rewritten from scratch March 3, 2007
my notes can be found in cap_src notes.txt, they're just my thought processes when coding
I didn't write them out for the benefits of others, they're for the benefit of myself
so don't ask questions about them
*/
#include <avr/io.h> //include standard defs.
//#include <math.h> //include math defs (don't need it. was for fmod)
#include <avr/interrupt.h> //include interrupt defs
//#include <avr/signal.h> //include obsolete signal header
#include <stdlib.h>
const static char chr_0 = 0x30;
/*
these aren't needed. if it's a number, just add it to chr_0
const static char chr_1 = 0x31;
const static char chr_2 = 0x32;
const static char chr_3 = 0x33;
const static char chr_4 = 0x34;
const static char chr_5 = 0x35;
const static char chr_6 = 0x36;
const static char chr_7 = 0x37;
const static char chr_8 = 0x38;
const static char chr_9 = 0x39;
//const static char chr_dot = 0x2E;
*/
static unsigned long long int timerCk; //this will be our clock cycle counter
static unsigned char finishedCk = 1; //this will be our indicator if we're
//done with counting clock cycles (inverse logic tho)
//this sub modified to remove optional baud rate
//you should be able to uncomment most parts, and
//add a var called baud in the dimming of the func.
//so it looks like: (i think, i removed it because
//i don't know C very well)
//void tx(unsigned long int baud, unsigned int chr) {
//oh, notes on this are available in the cap_main notes.txt file
void tx(unsigned char chr) {
unsigned long int timer;
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ (((chr - (chr % 0x80)) >> 7) << PORTB4);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ ((((chr - (chr % 0x40)) % 0x40) >> 6) << PORTB4);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ ((((chr - (chr % 0x20)) % 0x20) >> 5) << PORTB4);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ ((((chr - (chr % 0x10)) % 0x10) >> 4) << PORTB4);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ ((((chr - (chr % 0x08)) % 0x08) >> 3) << PORTB4);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ ((((chr - (chr % 0x04)) % 0x04) >> 2) << PORTB4);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ ((((chr - (chr % 0x02)) % 0x02) >> 1) << PORTB4);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ ((((chr - (chr % 0x01)) % 0x01)) << PORTB4);
for (timer = 1; timer <= 1000; timer++);
};
void startTimer(void) {
//this sub starts counting
while (finishedCk) timerCk++;
};
SIGNAL(SIG_INTERRUPT0) {
//unsigned long long int tempCk;
long double tTime = 0;
unsigned long int tFreq = 0;
unsigned long int time2 = 0;
//char letters[10];
if (finishedCk) {
cli();
finishedCk = 0;
//now read timerCk
tTime = timerCk / 0x927C00;
tFreq = 1 / tTime;
//now we need to pass our info to the TX function
for (time2 = 10000000; time2 >= 1; time2 /= 10) tx((((tFreq - (tFreq % time2)) % (time2 * 10)) / time2) + chr_0);
sei();
} else {
finishedCk = 1;
timerCk = 1;
startTimer();
};
};
int main (void) {
DDRB = 0x18; //set portB to output PORTB3,4
MCUCR |= 0x03; //set the INT0 to triger on rising edge of pulses
sei(); //set enable interrupts
};/*
Written 2007 by Michael Witt
Designed for the ATTiny13 AVR MCU
Changes can be made to accomodate different mcus
frequency counter v2
Referenced: http://www.atmel.com/avr
www.ladyada.net
I am not liable for any damages caused by any means by this code.
Don't agree? Don't use it.
rewritten from scratch March 3, 200
my notes can be found in cap_src notes.txt, they're just my thought processes when coding
I didn't write them out for the benefits of others, they're for the benefit of myself
so don't ask questions about them
*/
#include <avr/io.h> //include standard defs.
//#include <math.h> //include math defs (don't need it. was for fmod)
#include <avr/interrupt.h> //include interrupt defs
//#include <avr/signal.h> //include obsolete signal header
//#include <stdlib.h>
//const static char chr_0 = 0x30;
/*
these aren't needed. if it's a number, just add it to chr_0
const static char chr_1 = 0x31;
const static char chr_2 = 0x32;
const static char chr_3 = 0x33;
const static char chr_4 = 0x34;
const static char chr_5 = 0x35;
const static char chr_6 = 0x36;
const static char chr_7 = 0x37;
const static char chr_8 = 0x38;
const static char chr_9 = 0x39;
//const static char chr_dot = 0x2E;
*/
static unsigned int timerCk = 1; //this will be our clock cycle counter
static unsigned char finishedCk; //this will be our indicator if we're
//done with counting clock cycles (inverse logic tho)
//this sub modified to remove optional baud rate
//you should be able to uncomment most parts, and
//add a var called baud in the dimming of the func.
//so it looks like: (i think, i removed it because
//i don't know C very well)
//void tx(unsigned long int baud, unsigned int chr) {
//oh, notes on this are available in the cap_main notes.txt file
void tx(unsigned char chr) {
unsigned int timer;
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ ((chr - (chr % 0x80)) / 2);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ (((chr - (chr % 0x40)) % 0x40) / 1);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ (((chr - (chr % 0x20)) % 0x20));
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ (((chr - (chr % 0x10)) % 0x10) * 1);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ (((chr - (chr % 0x08)) % 0x08) * 2);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ (((chr - (chr % 0x04)) % 0x04) * 4);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ (((chr - (chr % 0x02)) % 0x02) * 8);
for (timer = 1; timer <= 1000; timer++);
PORTB ^= PORTB ^ (((chr - (chr % 0x01)) % 0x01) * 16);
for (timer = 1; timer <= 1000; timer++);
};
void startTimer(void) {
//this sub starts counting
while (finishedCk) timerCk++;
};
ISR(SIG_INTERRUPT0) {
//unsigned long long int tempCk;
//double tTime;
unsigned int tFreq;
unsigned long int time2;
//char letters[10];
if (finishedCk) {
cli();
finishedCk = 0;
//now read timerCk
//tTime = timerCk / 0x927C00;
tFreq = 1 / timerCk / 0x927C00;
//now we need to pass our info to the TX function
for (time2 = 10000000; time2 >= 1; time2 /= 10) tx((((tFreq - (tFreq % time2)) % (time2 * 10)) / time2) + 0x30);
timerCk = 1;
sei();
} else {
finishedCk = 1;
timerCk = 1;
startTimer();
//while (finishedCk) timerCk++;
};
};
int main (void) {
DDRB = 0x18; //set portB to output PORTB3,4
MCUCR |= 0x03; //set the INT0 to triger on rising edge of pulses
sei(); //set enable interrupts
while(1);
};It's usually in a different place each time (different bytes) but it always happens. Anyone have any ideas?C:\cap_src>make program-cap
avrdude -p attiny13 -P com2 -c dasa -U flash:w:cap_main.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9007
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "cap_main.hex"
avrdude: input file cap_main.hex auto detected as Intel Hex
avrdude: writing flash (804 bytes):
Writing | ################################################## | 100% 2.02s
avrdude: 804 bytes of flash written
avrdude: verifying flash memory against cap_main.hex:
avrdude: load data flash data from input file cap_main.hex:
avrdude: input file cap_main.hex auto detected as Intel Hex
avrdude: input file cap_main.hex contains 804 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 1.80s
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0044
0x35 != 0x34
avrdude: verification error; content mismatch
avrdude: safemode: Fuses OK
avrdude done. Thank you.
make: *** [program-cap] Error 1
C:\cap_src>
mikewitt wrote:Should I submit a bug report to WinAVR about it? Because I don't _think_ it's my code causing it, I think it's avrdude causing the problem, either that, or GCC isn't compiling code correctly.
Return to General Project help
Users browsing this forum: ArekKindAcere, mibignistinly, Pneumatic and 12 guests