My project is a tachometer for RC Aircraft engines. It is planned to be an onboard device so I want to use an Attiny85 as the processor.
The first prototype has been built using a mini OLED display and works very nice.
I am using two interrupts:
PCI for counting the ignition signal.
Timer1 Overflow Interrupt for gate period (around 500 mS).
This setup works flawlessly except the performance of the OLED display under daylight is very unsatisfactory. So I planned to change over to a 4 X 7 segment LED display. I want to use the ready made modules with two integrated 74HC595 shift registers.
The first prototype has been built around an Arduino Uno and works flawlessly. Now I have to move the code over to Attiny85. Attiny85 has only two timers and Timer1 is already being used by the counting system. The 7 segment display however must be refreshed regularly and this can only be achieved using another timer interrupt. That means I must use Timer0 for display driving and refreshing. Unfortunately Arduino IDE refuses these lines of code:
C:\Users\THESUR~1\AppData\Local\Temp\build707840c6d8e7f506bb0fd6671da87bc0.tmp/core\core.a(wiring.c.o): In function __vector_5':**</em> <em>**C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/wiring.c:47: multiple definition of __vector_5' sketch\SevenSegmentTacho_Attiny.ino.cpp.o:C:\Users\TheSurgeon\Desktop\SevenSegmentTacho_Attiny/SevenSegmentTacho_Attiny.ino:46: first defined here collect2.exe: error: ld returned 1 exit status exit status 1 Error compiling.
As my code does not have any of the timing commands like delay(), millis() I should be able to use Timer0 according to my needs but I cannot compile my code with Arduino IDE 1.6.7
What do you mean by "the led display has to be refreshed regularly?" Anyway you could use the 500ms timer to do double duty? Set the timer to the "least common denominator" of the two things needing a timer interrupt, 100ms say. Then every 5th time for the gate period?
It is only to update the display with new numbers that could have changed (or not) ? Is that really all that this is about ? Then millis() can be used for a software timer.
aarg:
A shift register based LED display is usually multiplexed. So the digits have to be switched faster than the eye can see. That's done in software.
That's the point! Only one digit at a time can be active and this necessitates a fast refresh rate to see all digits at once.
I know what multiplexing is btw. I don't know what relevance it has. It could be anything at all. Any two three or even a dozen things CAN BE a part of a single timer function.
I know what multiplexing is btw. I don't know what relevance it has. It could be anything at all. Any two three or even a dozen things CAN BE a part of a single timer function.
I called it a germ because you referred to it as a 100ms timer. Since that would not be nearly fast enough for a display refresh, and also because you asked, "What do you mean by "the led display has to be refreshed regularly?", I assumed that you didn't fully understand the reason for the display interrupt. The relevance is that the OP can not make the display work without it.
The idea of using the timer for both purposes is very good.
My solution is to use only Timer1.
Attiny85 @ 8 MHz
Prescaler 64
Timer1 Overflow Interrupt enabled
This gives approximately 488 Hz for the display refresh. As at each interrupt only one digit is displayed, the refresh rate for the entire display is around 122 Hz.
The ISR includes another counter which counts up to 244. When it reaches 244 this means that approximately 500 mS has elapsed. This sets a flag and moves the counted value (pulses are being counted in the background using PCI) to another variable to be processed in the main program loop. Main loop also decodes the 7 segment data and stores it in an array. The content of the array is then sent to the shift register from the ISR.
The code is working now on an Attiny85. It may require some calibration but it seems generally OK.
But...
Let's say I MUST use the Timer0 and it's interrupts in another project. Arduino IDE doesn't allow me to do this. Do you have any solution for this problem?
sumeryamaner:
Let's say I MUST use the Timer0 and it's interrupts in another project. Arduino IDE doesn't allow me to do this. Do you have any solution for this problem?