Re: [Amforth] microsecond delay

2019-01-06 Thread Matthias Trute
Am Freitag, den 04.01.2019, 18:46 + schrieb Tristan Williams:
> 
> On 03Jan19 16:07, Jan Kromhout wrote:
> > Hello,
> > 
> > Is in AmForth a microsecond delay available?
> > 
> > Cheers,
> > 
> > Jan
> > 
> 
> Jan,
> 
> As far as I know, whilst AmForth does have a millisecond word 1ms, it
> does not have an equivelent microsecond word, say 1us. I think it
> would be possible to make one, using 1ms.asm as a template.

A full cycle through the (AVR) inner interpreter takes around 45 
CPU cycles. At 1MHz that translates to 45us *at least*.
Probably the NOOP word is the closest approximation to the
1us, the actual time spent there depends on the cpu frequency.
at 16MHz it comes down to 3us (45/16)


> I have, however, made specific assembler words for specific project
> delays (eg. 250us), for when the existing 1ms was too long.

You may use the macro DELAY that optimizes the cpu cycles to
spent for given fixed delay. It is used in the 1-wire code, but it
cannot be exposed to Forth level due to the very specific operations
it has to do *at compile time*.

Matthias



___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel


Re: [Amforth] microsecond delay

2019-01-04 Thread Tristan Williams



On 03Jan19 16:07, Jan Kromhout wrote:
> Hello,
> 
> Is in AmForth a microsecond delay available?
> 
> Cheers,
> 
> Jan
> 

Jan,

As far as I know, whilst AmForth does have a millisecond word 1ms, it
does not have an equivelent microsecond word, say 1us. I think it
would be possible to make one, using 1ms.asm as a template. However,

: 10us ( -- ) 1us 1us 1us 1us 1us 1us 1us 1us 1us 1us ;

would not give the 10 microsecond delay one might hope for because of
the time taken by the inner interpreter between forth words, which I
think, on a 16MHz UNO, is the same order of magnitude as a microsecond[1]. 

I have, however, made specific assembler words for specific project
delays (eg. 250us), for when the existing 1ms was too long.

Tristan

[1] In the absence of an interrupt




___
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel