Hello,
I'm new to microcontroller programming, but try to learn constantly :-)
With the attached code I try to blink a LED on a ATTiny85 chip with 1 Hz frequency.
This works fine, but the intended fine tuning of the frequency by changing the SetTimer value (6) of Timer 1 shows no effect.
The blinking frequency always stays 1 Hz, even with a value of 255.
What am I doing wrong?
Kind regards
Philip
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#chiptiny85, 16
#optionExplicit
#defineLED_1PORTB.1;--- Set unused pins to input + pullup to avoid drifting ports:DirPORTBIN'set all pins to inputSetPORTB=0xFF'activate all internal pullupsDirLED_1OUTDimintervallasByteDimwarteseit, CounterValue_0, CounterValue_1, Pulse_Start, Pulse_LenasbyteStart:
'Enable portb.2 as the source of the interrupt. See the datasheet for more information.'Trigger on change of PB2OnInterruptTimer1OverflowCallIncCounter_1IntOn'enable Interrupts;Timer1 prescaler 1/64 => with 16 MHz, 8bit counter overflows every 1024µs;;with preload 6 overflow every 1000 µsInitTimer1Osc, PS_1_64SetTimer1, 6StartTimer1intervall=0warteseit=0SetLED_1OnMain:
doforever;Count Loops (0-10)intervall++ifintervall=50thenSETLED_1Offendififintervall>100thenintervall=0SetLED_1OnEndIf;Wait until next 10ms intervall startsdowhile(CounterValue_1-warteSeit)<10;emty looploopwarteseit+=10;next 10 ms IntervallloopSubIncCounter_1SetTimer1, 6CounterValue_1++EndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The timer code looks ok but the do while (CounterValue_1 - warteSeit) <10 loop is correct? Looks odd to me. CounterValue_1 has the range of 0 to 255 but warteseit will be the following sequence... 0, 10, 20, 30 .. 250, 4, 14, 24.... so, this test correct?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks for the reply.
The 'do while'-loop actually looks a bit weired, but it works fine.
Here is a short sequence of the values and the calculated results:
CounterValue_1
warteSeit
(CounterValue_1 - warteSeit)
. . .
254
250
4
255
250
5
0
250
6
1
250
7
2
250
8
3
250
9
4
4
0
5
4
1
6
4
2
. . .
12
4
8
13
4
9
14
14
0
15
14
1
16
14
2
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found out that the handling for the TCNT1 register for the subroutine SetTimer is missing in the timer library (timer.h). I added that in the attached "lcd.h" - line 1191 - #ifdef Var (TCNT1) ...
Please try it out.
; ----- Chip configuration:
#chiptiny85, 16.5; ----- Include (software optimised) serial library:
#include<SoftSerial.h>; ----- Config serial UART for sending:
#defineSER1_BAUD115200; 115200 baud
#defineSER1_TXPORTPORTB; PortB.3 = Pin2 on AtTiny85
#defineSER1_TXPIN3;; ----- Config Timer1:InitTimer1OSC, PS_1_32; ----- Test Timer1 methods:StartTimer1'start Timer1Ser1Send13'new line in TerminalSer1PrintTimer1'send timervalueClearTimer1'set timervalue to zeroSer1Send13'new line in TerminalSer1PrintTimer1'send timervalueSetTimer1, 100'set timervalue to 100Ser1Send13'new line in TerminalSer1PrintTimer1'send timervalueStopTimer1'stop Timer1SetTimer1, 100'set timervalue to 100Ser1Send13'new line in TerminalSer1PrintTimer1'send timervalue
Terminal output is:
44
45
144
100
That's what to expect, so timer.h seems ok for me now. Please do another check anyway.
Frank
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I'm new to microcontroller programming, but try to learn constantly :-)
With the attached code I try to blink a LED on a ATTiny85 chip with 1 Hz frequency.
This works fine, but the intended fine tuning of the frequency by changing the SetTimer value (6) of Timer 1 shows no effect.
The blinking frequency always stays 1 Hz, even with a value of 255.
What am I doing wrong?
Kind regards
Philip
Here is the code:
Morning,
We need Boris. Boris Breuer bbreuer@users.sf.net
He is our expert on the Tiny85.
The timer code looks ok but the do while (CounterValue_1 - warteSeit) <10 loop is correct? Looks odd to me. CounterValue_1 has the range of 0 to 255 but warteseit will be the following sequence... 0, 10, 20, 30 .. 250, 4, 14, 24.... so, this test correct?
Hi Anobium,
think I got it!
Instead of
now I use
Writing the value directly into the Timer1 register TCNT1 works fine.
Now it's possible to do a fine tuning of the time between the Interrup calls.
The "SetTimer" command seems not working on ATTiny85.
Thanks
Must be an issue in the Settimer method.
Hopefully, one of the AVR guys can resolve for the future.
Well done in resolving
Hi Anobium,
thanks for the reply.
The 'do while'-loop actually looks a bit weired, but it works fine.
Here is a short sequence of the values and the calculated results:
Hi,
I found out that the handling for the TCNT1 register for the subroutine SetTimer is missing in the timer library (timer.h). I added that in the attached "lcd.h" - line 1191 - #ifdef Var (TCNT1) ...
Please try it out.
Frank
Last edit: Frank Steinberg 2020-09-17
Let me know if this resolves the issue. And, I will copy to the release.
Hello Frank,
thank you for your support and for providing the corrected timer library.
I will test it soon and report back then.
Philip
I've tested with this:
Terminal output is:
44
45
144
100
That's what to expect, so timer.h seems ok for me now. Please do another check anyway.
Frank
Hello Frank,
i have also tested the new timer library in my project with success.
Works great!
Thanks again for your efforts.
Philip
Thank you. I have updated the distribution.