Hi all,
First off, a big thank you to all the contributors to these forums, they are an invaluable learning and reference resource. I’ve been reading the forums for quite a while but this is my first message here so apologies if I’ve chosen the wrong section or otherwise flouted some rule I wasn’t aware of.
Now to my issue.
I have a pH/temperature logger based on an Arduino Nano. I would like to add some extra functionality and several more pH buffer temperature dependence tables, but as it is, the program code takes 99% of the available memory. This is mostly because it includes a complete menu-driven user interface (with ANSI colour/cursor control etc) via PuTTY. At some point I will rewrite this to talk to a PC-based client which will dispense with the user interface and free a lot of the memory, but I’m not there yet (learning C++ as I go along). In any case, it works well as it is, we’ve had one in the lab where I work for close to a year now and I’ve recently had to build a second one because of high/near constant demand.
Then I’ve heard of the new Arduino Nano Every. Pin-compatible with the original Nano but with 50% more program memory. Sounded like exactly what I needed, so I got two of these. But since it runs on a different processor, the register architecture and names have been changed around. Which means that the bit where my code sets up a timer interrupt does not compile.
I’ve got the ATMega 4808/4809 datasheet and will at some point crunch my way through it and hopefully eventually understand how to set up a timer ISR on a Nano Every from first principles, but right now I’m being lazy and would just like the damn thing to work.
I found the link below, but it’s no help as it doesn’t compile for me.
So my question is, could somebody rewrite the code below (register names etc) so it works on an Arduino Nano Every, or point me to somewhere that explains how to do it succinctly (i.e. not a link to the ATmega 4808/09 datasheet, I can do that myself)?
Here is the bit that sets up the timer:
void menu_system::setup_timer1_ISR(volatile unsigned int ms) {
cli(); // disable all interrupts
TCCR1A = 0; // set TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // initialize counter value to 0
TCCR1B |= (1 << WGM12); // turn on CTC mode
TCCR1B |= (1 << CS12) | (1 << CS10); // Set CS10 and CS12 bits for
// 1024 prescaler
if (ms == 0) { // ISR will be disabled if ms is zero
TCCR1B |= (0 << CS12) | (0 << CS11) | (0 << CS10);
// Disable counter
TIMSK1 |= (0 << OCIE1A); // disable timer compare int
} else { // calculate OCR1A value for
// requested interval
float freq = 1.0/(float(ms)/1000.0); // Interrupt frequency
float f = freq * 1024; // Multiply by prescaler
long int i = 16000000ul / (long int)f; // Divide clock speed by that
i -= 1; // Subtract 1
OCR1A = int(i); // Set OCR1A register
TIMSK1 |= (1 << OCIE1A); // Enable timer compare ints
}
sei(); // re-enable all interrupts
}
And here is the ISR:
ISR(TIMER1_COMPA_vect) {
if (menu_system::ISR_entered) return;
menu_system::ISR_entered = true;
menu_system::draw_status();
menu_system::ISR_entered = false;
}
Thanks,
Bart