Hi,
searching for a high speed serial output on ATtiny84 for debugging purposes I found USISerial which is based on AVR307. This software "borrows" timer0 which is used by the core for millis() and micros(().
But like the core, USISerial also uses overflow interrupts from timer0. In my understanding this means that the interrupt vector of millis() is overwritten by USISerial software. I could'nt find a saving of the interrupt vector of millis() and restoration after USISerial has sent a byte.
If this is true then millis() and micros() will not be available after using USISerial.
Is this true?
This timer0 use case is old, see if you can take advantage of something from this Issue:
opened 01:35AM - 02 Feb 22 UTC
closed 07:03AM - 02 Feb 22 UTC
duplicate
enhancement
Hello,
I'm trying to port a code from ATtiny2313 to ATmega328 (using Arduino … IDE), but I found something interesting when looking at the [datasheet](https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf).
Projects that need external input to Timer0 cannot be ported to Timer2 because timer2 has no external input.
14. 8-bit Timer/Counter0
- 14.9.2 TCCR0B – Timer/Counter Control Register B:
- - Table 14-9. Clock Select Bit Description
- - - CS22=1, CS21=1, CS20=1: External clock source on T0 pin. Clock on rising edge.
17. 8-bit Timer/Counter2
- 17.11.2 TCCR2B – Timer/Counter Control Register B:
- - Table 17-9. Clock Select Bit Description
- - - CS22=1, CS21=1, CS20=1: clkT2S/1024 (from prescaler)
As Timer0 is restricted to internal use, like delay(), micros() etc., so it cannot be used by the user.
But if there is some way to use timer2 instead of using timer0 for internal use like delay(), micros() etc. then timer0 could be used for external input purposes.
Would it be possible to add (if it doesn't already exist) a way to use timer2 and leave timer0 free?
Maybe something like:
`#define use_timer2_for_delay_and_micros 1`
Or
`#define leave_timer0_free 1`
The code I'm trying to port is this:
- High Resolution Frequency Counter
- - A reciprocal frequency counter with an ATTINY2313 (Tested from 0.2 Hz to 2 MHz)
https://gitlab.com/WilkoL/high-resolution-frequency-counter/-/blob/master/main.c
This is the schematic (note that external input is used in timer0 [PD4] and timer1 [PD5]):
https://gitlab.com/WilkoL/high-resolution-frequency-counter/-/blob/master/schematic.png
I could use the IDE "[Microchip Studio for AVR](https://www.microchip.com/en-us/tools-resources/develop/microchip-studio)" to program the ATmega328, the same way it was used for this project with the ATtiny2313, but I believe it will be very useful to have this possibility of use, using the Arduino IDE.
Thank you.
opened 11:01AM - 09 May 17 UTC
enhancement
Would be great to be able to define which timer to use for millis/micros/delay a… nd may be others, where timer0 currently used. For example timer2 (where available) can be used instead.
This will be useful in case both timers 0 and 1 have to be clocked from external source to count pulses from two independent sources. Something like #define CORE_USE_TIMER2
An alternative would be to use a more resourceful board just to debug the code, and after the routines are acceptable, it would be ported to the low resource board.
https://www.circuito.io/blog/arduino-debugging/
https://circuitdigest.com/tutorial/how-to-debug-an-arduino-project-arduino-ide-debugging-tools
https://randomnerdtutorials.com/software-debugger-arduino-ide-serialdebug-library/
system
Closed
September 6, 2022, 12:03am
3
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.