Thread: [Flashforth-devel] Microsecond counter problem, please help
Brought to you by:
oh2aun
From: Laszlo K. <Ko...@ce...> - 2021-10-29 15:55:22
Attachments:
timertest.fs
|
I am newbie in forth and especially MCUs I would like to ask for help. I would like to write a driver for DHT-22 humidity/thermo sensor. It needs measure microsecond resolution changes in pin state, so I wrote a small code in order to count microseconds based on this article: https://www.reddit.com/r/arduino/comments/1q1chr/using_timer1_to_count_clock_cycles/ I try to implement it but failed in several various ways. once it looks like stuck in a infinity reset, sometimes no prompt after running, sometimes flood garbage when use 'words' after running the code. What mistake I made in this code? Please help me! Thanks in advance! László Kollár |
From: Mikael N. <mik...@fl...> - 2021-10-30 12:41:02
|
You have the wrong interrupt vector number. #14 constant TIMER1_OVF_vect BR Mikael On 2021-10-29 14:05, Laszlo Kollar wrote: > I am newbie in forth and especially MCUs > I would like to ask for help. > I would like to write a driver for DHT-22 humidity/thermo sensor. It > needs measure microsecond resolution changes in pin state, so I wrote a > small code in order to count microseconds based on this article: > https://www.reddit.com/r/arduino/comments/1q1chr/using_timer1_to_count_clock_cycles/ > > I try to implement it but failed in several various ways. > once it looks like stuck in a infinity reset, sometimes no prompt after > running, sometimes flood garbage when use 'words' after running the > code. > > What mistake I made in this code? > Please help me! > > Thanks in advance! > > László Kollár > > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel -- -- Mikael |
From: Stefan <fli...@gm...> - 2021-10-30 18:16:57
Attachments:
timertest.fs
|
Did you check the word 'load'? If it exists, Timer1 is used by the system-load-counter. For other purposes TCNT1 is 'read only' then. You could use 'us' (from the 'avr/forth'-subdirectory) to wait for a specified number of microseconds. If Timer1 is free for use -> see timertest.fs greetz bitflipser Am 30.10.2021 um 04:59 schrieb Mikael Nordman: > You have the wrong interrupt vector number. > > #14 constant TIMER1_OVF_vect > > BR Mikael > > On 2021-10-29 14:05, Laszlo Kollar wrote: >> I am newbie in forth and especially MCUs >> I would like to ask for help. >> I would like to write a driver for DHT-22 humidity/thermo sensor. It >> needs measure microsecond resolution changes in pin state, so I wrote a >> small code in order to count microseconds based on this article: >> https://www.reddit.com/r/arduino/comments/1q1chr/using_timer1_to_count_clock_cycles/ >> >> >> I try to implement it but failed in several various ways. >> once it looks like stuck in a infinity reset, sometimes no prompt after >> running, sometimes flood garbage when use 'words' after running the >> code. >> >> What mistake I made in this code? >> Please help me! >> >> Thanks in advance! >> >> László Kollár >> >> _______________________________________________ >> Flashforth-devel mailing list >> Fla...@li... >> https://lists.sourceforge.net/lists/listinfo/flashforth-devel > |
From: Laszlo K. <Ko...@ce...> - 2021-11-02 11:37:03
|
Fortunately I do not have 'load' command at all. Thank you! Laci ________________________________ From: Stefan <fli...@gm...> Sent: Saturday, October 30, 2021 7:46 PM To: fla...@li... <fla...@li...> Subject: Re: [Flashforth-devel] Microsecond counter problem, please help Did you check the word 'load'? If it exists, Timer1 is used by the system-load-counter. For other purposes TCNT1 is 'read only' then. You could use 'us' (from the 'avr/forth'-subdirectory) to wait for a specified number of microseconds. If Timer1 is free for use -> see timertest.fs greetz bitflipser Am 30.10.2021 um 04:59 schrieb Mikael Nordman: > You have the wrong interrupt vector number. > > #14 constant TIMER1_OVF_vect > > BR Mikael > > On 2021-10-29 14:05, Laszlo Kollar wrote: >> I am newbie in forth and especially MCUs >> I would like to ask for help. >> I would like to write a driver for DHT-22 humidity/thermo sensor. It >> needs measure microsecond resolution changes in pin state, so I wrote a >> small code in order to count microseconds based on this article: >> https://www.reddit.com/r/arduino/comments/1q1chr/using_timer1_to_count_clock_cycles/ >> >> >> I try to implement it but failed in several various ways. >> once it looks like stuck in a infinity reset, sometimes no prompt after >> running, sometimes flood garbage when use 'words' after running the >> code. >> >> What mistake I made in this code? >> Please help me! >> >> Thanks in advance! >> >> László Kollár >> >> _______________________________________________ >> Flashforth-devel mailing list >> Fla...@li... >> https://lists.sourceforge.net/lists/listinfo/flashforth-devel > |
From: Mikael N. <mik...@fl...> - 2021-10-31 11:40:53
Attachments:
timertest.fs
|
László, Just to show you an example of how to scale and format numbers I added printing of the time in microseconds. In idle mode you can see that the measured time is always the same because the execution of TIMERTEST is in sync with the millisecond interrupt. In busy mode the execution time varies with 1 milliseconds depending on the phase relationship of the TIMERTEST command and the millisecond timer0. idle hex ok<$,ram> timertest counter: 18781d time: 100225.812 us ok<$,ram> timertest counter: 18781d time: 100225.812 us ok<$,ram> busy hex ok<$,ram> timertest counter: 18a140 time: 100884.0 us decimal ok<#,ram> timertest counter: 1601046 time: 100065.375 us BR Mikael On 2021-10-30 20:46, Stefan wrote: > Did you check the word 'load'? If it exists, Timer1 is used by the > system-load-counter. For other purposes TCNT1 is 'read only' then. > You could use 'us' (from the 'avr/forth'-subdirectory) to wait for a > specified number of microseconds. > > If Timer1 is free for use -> see timertest.fs > > greetz bitflipser > > > Am 30.10.2021 um 04:59 schrieb Mikael Nordman: >> You have the wrong interrupt vector number. >> >> #14 constant TIMER1_OVF_vect >> >> BR Mikael >> >> On 2021-10-29 14:05, Laszlo Kollar wrote: >>> I am newbie in forth and especially MCUs >>> I would like to ask for help. >>> I would like to write a driver for DHT-22 humidity/thermo sensor. It >>> needs measure microsecond resolution changes in pin state, so I wrote >>> a >>> small code in order to count microseconds based on this article: >>> https://www.reddit.com/r/arduino/comments/1q1chr/using_timer1_to_count_clock_cycles/ >>> >>> >>> I try to implement it but failed in several various ways. >>> once it looks like stuck in a infinity reset, sometimes no prompt >>> after >>> running, sometimes flood garbage when use 'words' after running the >>> code. >>> >>> What mistake I made in this code? >>> Please help me! >>> >>> Thanks in advance! >>> >>> László Kollár >>> >>> _______________________________________________ >>> Flashforth-devel mailing list >>> Fla...@li... >>> https://lists.sourceforge.net/lists/listinfo/flashforth-devel >> > > > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel -- -- Mikael |
From: Laszlo K. <Ko...@ce...> - 2021-11-02 10:23:40
|
> You have the wrong interrupt vector number. Indeed, it is my fault! Thanks for the improved 'timer.fs' I am going to study it! Thaks again! Laci On Sun, 2021-10-31 at 06:36 +0200, Mikael Nordman wrote: > László, > > Just to show you an example of how to scale and format numbers > I added printing of the time in microseconds. > > In idle mode you can see that the measured time is always the same > because the execution of TIMERTEST is in sync with the millisecond > interrupt. > > In busy mode the execution time varies with 1 milliseconds depending > on > the > phase relationship of the TIMERTEST command and the millisecond > timer0. > > idle hex ok<$,ram> > timertest > counter: 18781d > time: 100225.812 us > ok<$,ram> > timertest > counter: 18781d > time: 100225.812 us > ok<$,ram> > busy hex ok<$,ram> > timertest > counter: 18a140 > time: 100884.0 us > decimal ok<#,ram> > timertest > counter: 1601046 > time: 100065.375 us > > > BR Mikael > > > On 2021-10-30 20:46, Stefan wrote: > > Did you check the word 'load'? If it exists, Timer1 is used by the > > system-load-counter. For other purposes TCNT1 is 'read only' then. > > You could use 'us' (from the 'avr/forth'-subdirectory) to wait for > > a > > specified number of microseconds. > > > > If Timer1 is free for use -> see timertest.fs > > > > greetz bitflipser > > > > > > Am 30.10.2021 um 04:59 schrieb Mikael Nordman: > > > You have the wrong interrupt vector number. > > > > > > #14 constant TIMER1_OVF_vect > > > > > > BR Mikael > > > > > > On 2021-10-29 14:05, Laszlo Kollar wrote: > > > > I am newbie in forth and especially MCUs > > > > I would like to ask for help. > > > > I would like to write a driver for DHT-22 humidity/thermo > > > > sensor. It > > > > needs measure microsecond resolution changes in pin state, so I > > > > wrote > > > > a > > > > small code in order to count microseconds based on this > > > > article: > > > > https://www.reddit.com/r/arduino/comments/1q1chr/using_timer1_to_count_clock_cycles/ > > > > > > > > > > > > I try to implement it but failed in several various ways. > > > > once it looks like stuck in a infinity reset, sometimes no > > > > prompt > > > > after > > > > running, sometimes flood garbage when use 'words' after running > > > > the > > > > code. > > > > > > > > What mistake I made in this code? > > > > Please help me! > > > > > > > > Thanks in advance! > > > > > > > > László Kollár > > > > > > > > _______________________________________________ > > > > Flashforth-devel mailing list > > > > Fla...@li... > > > > https://lists.sourceforge.net/lists/listinfo/flashforth-devel > > > > > > > > > _______________________________________________ > > Flashforth-devel mailing list > > Fla...@li... > > https://lists.sourceforge.net/lists/listinfo/flashforth-devel > > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel |