Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #14477

Re: GA144 Programming

From rickman <gnuarm@gmail.com>
Newsgroups comp.lang.forth
Subject Re: GA144 Programming
Date 2012-07-27 21:49 -0700
Organization http://groups.google.com
Message-ID <a4ae76c3-2635-4443-9fe8-8fee4e283d2b@googlegroups.com> (permalink)
References <1121f776-65ff-4d4a-9246-f8e3d50e0318@googlegroups.com> <336ee979-b27c-4a92-b667-b5aef6d04211@googlegroups.com> <7x394fifwk.fsf@ruckus.brouhaha.com>

Show all headers | View raw


On Wednesday, July 25, 2012 7:23:39 PM UTC-4, Paul Rubin wrote:
> rickman <gnuarm@gmail.com> writes:
> 
> > Here is my code for an 8 point boxcar averager. 
> 
> >     1  2  3   4  5   6  7  8  9  10 11 12 13  14  15  16 
> 
> > go  @ pop dup . drop .  + dup !b  –  .  +  – push go ; 
> 
> 
> 
> 1. What is the ? in slots 10 and 13?
> 
> 2. Why is there a delay at slot 6 and not one after slot 7?  Did you
> 
>    inadvertently switch 6 and 7?
> 
> 
> 
> I'd be interested in more explanation of what the code does,
> 
> including what a boxcar averager is.


A boxcar averager is just a type of low pass FIR filter that does not require multiplications.  This code is averaging 8 samples with no decimation.  In theory a boxcar averager requires a divide by N but in this case I prefer having the gain which I can make use of.  To include the divide to get gain of 1 just add 2/ 2/ 2/ between the DUP and the !b.  

The NOP '.' in instruction four is because there are only 8 instructions that can be in this slot and DROP is not one of them.  So a nop has to be inserted.  The other nops precede the + instruction to give the carry time to propagate in the adder.  This can be omitted if the instruction preceding + does not change S or T.  

Sorry about the ?.  What you are seeing as a ? is supposed to be a minus sign '-'.  I did this in a spread sheet which helped me visualize the stack.  To make he minus sign more visible I used one of the extended alt-codes, an m-dash or n-dash.  So the code should be as below. 

    1  2   3  4  5   6  7  8  9  10 11 12 13  14  15  16 
go  @ pop dup . drop .  + dup !b  -  .  +  - push go ; 

Go is the name of the word.

@ reads IO input through the A register.  

POP pulls the running sum from the return stack.  

DUP . DROP is just to push the input value down to the lower 8 levels of the stack which are a circular buffer used as a delay line.  . in the middle is just to fill out the first word since the DROP can't be in the last slot of a instruction word.  You don't need to type this in your code as the compiler will add it.  I'm trying to count cycles so I am including it.  

. + adds the new value to the running sum.  

Dup !b stores the running sum through the B register to the next node.  

- . + - subtracts the x(n-7) value in the circular buffer from the running sum in preparation for the next iteration.  This is a nice little trick the solves the SWAP problem for me and is actually shorter since it does not require a 1 be added to complete the subtract.  In essence, instead of computing S - T, this computes T - S by inverting both the inputs and the outputs making the carry input of zero into a logical one!  

PUSH moves the running sum to the return stack so the next fetch will be in the right place on the stack.  

GO ; would be a call to GO and a return, but tail call optimization changes this to a jump to GO completing the loop. 

I don't find this sort of thing too complicated, but then I have designed my own CPUs and have worked with micro-coded hardware.  This is not much different. 

Rick

Back to comp.lang.forth | Previous | NextPrevious in thread | Find similar


Thread

GA144 Programming rickman <gnuarm@gmail.com> - 2012-07-15 13:29 -0700
  Re: GA144 Programming rickman <gnuarm@gmail.com> - 2012-07-15 14:31 -0700
  Re: GA144 Programming Clyde Phillips <cwpjr02@gmail.com> - 2012-07-15 21:43 -0700
    Re: GA144 Programming rickman <gnuarm@gmail.com> - 2012-07-16 07:52 -0700
    Re: GA144 Programming "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2012-07-16 17:47 -0700
  Re: GA144 Programming "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2012-07-16 19:09 +0100
    Re: GA144 Programming rickman <gnuarm@gmail.com> - 2012-07-16 11:17 -0700
      Re: GA144 Programming "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2012-07-16 19:43 +0100
  Re: GA144 Programming rickman <gnuarm@gmail.com> - 2012-07-25 15:10 -0700
    Re: GA144 Programming Paul Rubin <no.email@nospam.invalid> - 2012-07-25 16:23 -0700
      Re: GA144 Programming rickman <gnuarm@gmail.com> - 2012-07-27 21:49 -0700

csiph-web