Forum Update - Announcement about May 10th, 2018 update and your password.

Tachyon V4 "DAWN" - exploring new worlds

1242526272830»

Comments

  • Hi Peter,
    I got the WHEELCNT words working. After installing as a task it does not work.
    LONG COUNTER \ hold the wheel count
    [
    pub WHEELCNT ( --- )
    1 MASK 4 COG! --- setup for WAITCNT
    A 1 APIN
    1 FRQ
    12 CTRMODE --- POSEDGE mode
    0 COUNTER ! --- Zero counter
    1 FLOAT
    BEGIN
    --- CLKFREQ 400000 / DELTA WAITCNT
    WAITHI WAITLO
    COUNTER ++
    COUNTER @ DUP 56 = IF
    0 COUNTER ! THEN . CR --- set pulse number here
    AGAIN ;



    ' WHEELCNT TASK? RUN

    : DSP BEGIN COUNTER @ . CR KEY UNTIL ;
    ]
  • Peter JakackiPeter Jakacki Posts: 7,329
    edited February 28 Vote Up0Vote Down
    Ken, the main problem I see is that you do a ". CR" in your WHEELCNT which will have an I/O conflict with the serial I/O in the main console cog. Make sure you remove that diagnostic code from within the loop.

    btw - don't forget to enclose any code snippets you paste within the code tags (big C in the menu). You can always edit your post via the settings cog in the top right hand corner rather than reposting it again. Those square brackets don't cut it ;)

    Your code also looks strange in that it is doing all this CTRMODE stuff but is only implementing a counter in software, nothing to do with the hardware counter.

    Perhaps try this version:
    long COUNTER \ hold the wheel count
    
    pub WHEELCNT ( --- )
    	1 MASK 4 COG! --- setup input mask for WAITXX
    	COUNTER ~ --- Zero counter
    	BEGIN
    	  WAITHI WAITLO
    	  COUNTER ++
    	  COUNTER @ 56 = IF COUNTER ~ THEN
    	AGAIN
    	;
    
    ' WHEELCNT TASK? RUN
    
    pub DSP BEGIN <CR> COUNTER @ .  4 SPACES KEY UNTIL ;
    
    
    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    Tachyon Forth News Blog
    P2 SHORTFORM DATASHEET
    TAQOZ documentation
    Brisbane, Australia
  • Peter, thanks for the help. I was trying to use the hardware counter . As far as the formatting of the code should I use
    -- beginning
    
    end to post the code?
    Ken
  • Ken, the code tags are for the forum itself which removes multiple spaces and recognises keywords and tags to format what would otherwise be plain text. To get it to ignore all of that so that our pasted code looks just like it does in the editor we can select it after it is pasted and then click on the big C in the forum edit menu "B I U S C T" etc at the top of your post.. It's not WYSIWYG until you post it but you can preview it or edit it after it has been posted thankfully.
    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    Tachyon Forth News Blog
    P2 SHORTFORM DATASHEET
    TAQOZ documentation
    Brisbane, Australia
  • Sorry to bug you Peter, thanks for the patience and the info on the forum posting. I installed the WHEELCNT.TASK and ran the test code all is well. I loaded the PWM.TASK and it worked fine also.
    Here's the problem, when I load WHEELCNT.TASK and the PWM.TASK and run the counter test code the counter will not update but the PWM.TASK still works fine. My setup is a dc motor with an
    encoder coming to the counter task. I can ramp the motor speed but I can't see the pulses on the terminal or scope.

    Ken..
  • I when into EXTEND and the first 8 pins seem to be used by the PWM.TASK , I changed the pin # to 9 and all seems to work.
    Thanks,
    Ken
  • Ken - code?
    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    Tachyon Forth News Blog
    P2 SHORTFORM DATASHEET
    TAQOZ documentation
    Brisbane, Australia
  • Peter, here is the working code.
    Ken
    256 longs pwms        --- setup table store pwms
    $000F pwms 7600 PWM.START  --- start pwm task
    
    
    
    long COUNTER \ hold the wheel count
    
    pub WHEELCNT ( --- )
    	9 MASK 4 COG! --- setup input mask for WAITXX   \ change pin #9 is the counter input
    	
    	COUNTER ~    --- Zero counter
    	BEGIN
    	   WAITHI WAITLO
    	  COUNTER ++
    	  COUNTER @ 56 = IF COUNTER ~ THEN
    	AGAIN
    	;
    
    ' WHEELCNT TASK? RUN
    
     
    { test routines }
    
    pub startm 200 0 pwm ; --- run motor on pin 4
    pub stopm 0 0 pwm ;   --- stopmotor
    
    pub feedback BEGIN <CR> COUNTER @ .  4 SPACES  KEY UNTIL stopm ;  --- test code
    
    
    pub tst startm feedback ;
    
    
  • Is there a tutorial explaining the new FOR...NEXT procedure in depth? Or just some examples covering the use of FROM, BY, I+ etc?
    Gratitude is riches, complaint is poverty, and the worst I ever had was wonderful. - Brother Dave Gardener :innocent:
  • artkennedy wrote: »
    Is there a tutorial explaining the new FOR...NEXT procedure in depth? Or just some examples covering the use of FROM, BY, I+ etc?

    There's a bit here in my Tachyon blog but basically FOR NEXT like it always did and if you don't specify anything different the only other advantage is that it maintains an incrementing index "I" that starts from 0, just like in a DO LOOP. If you want your index to start from elsewhere then use "n FROM" before entering and if you want the index to step by a value other than the default of 1, then specify a signed number "n BY".

    This is an example from the blog.
    ..  CR 100 FROM 5 BY 10 FOR I . SPACE NEXT
    100 105 110 115 120 125 130 135 140 145  ok
    

    Having a single FOR NEXT and doing away with DO LOOP +LOOP ADO BOUND means I have more room in the kernel for more important things. The FROM and BY words are outside of the cog kernel. LEAVE also causes FOR NEXT to exit.

    There are additional words but I don't actually use them:
    BY! ( change the step within a loop)
    FOR! ( change the loop count )
    FOR@ ( get the loop count )
    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    Tachyon Forth News Blog
    P2 SHORTFORM DATASHEET
    TAQOZ documentation
    Brisbane, Australia
  • Thanks, Peter. I am now following your Tachyon blog.
    Gratitude is riches, complaint is poverty, and the worst I ever had was wonderful. - Brother Dave Gardener :innocent:
  • Hi all,

    I'm an electronics engineer based in Christchurch, New Zealand. In my spare time I've designed and built a small data acquisition and control system (which I've called DAQiri), with a view to using it as the control system for a scanning tunnelling microscope. The heart of the DAQiri system is a Propeller V1. The Propeller lines are divided into 4 groups and brought out to card slots. I've documented the hardware here: https://hackaday.io/project/27911-daqiri-a-data-acquisition-and-control-platform

    While trying to decide what language to use (Spin? PASM? PropGCC?) I discovered Tachyon FORTH. I think it's just what I'm looking for - compact and fast! Now I just need to learn it :)

    I've loaded v4.7 into DAQiri, and wrote some code to drive a stepper motor (a 28BYJ-48 driven by a ULN2003, via a TCA9535 I2C expansion IC):
    --- utility function to write a byte to an I2C chip register
    pub IO! ( data reg chip -- )
    	<i2c i2c! i2c! i2c! i2c>
    	; 
    
    --- Set I2C bus pins for stepper card, initialise TCA9535 ports 0 & 1 to output, set all outputs low
    pub motor_init ( -- )                         
    	7 6 i2cpins
    	$00 $02 $40 io!
    	$00 $03 $40 io!
    	$00 $06 $40 io!
    	$00 $07 $40 io!
    	; 
    
    --- set motor phase outputs on port 0 of TCA9535
    pub motor_phase ( phase -- )
    	$02 $40 io!
    	;
    
    --- Turn on activity LED for motor 1, run for <steps> steps, with <speed> ms between phase outputs 
    pub motor_run ( speed steps -- )                         
    	3 high
    	for
    	$02 motor_phase
    	DUP ms         
    	$04 motor_phase
    	DUP ms         
    	$08 motor_phase
    	DUP ms         
    	$10 motor_phase
    	DUP ms         
    	$00 motor_phase
    	next
    	3 low
    	DROP
    	; 
    

    The motor spins quite happily, which is encouraging :)

    Anyway, I've rather late to the Tachyon party but keen to catch up. Fantastic work Peter!

    Andrew
  • Peter JakackiPeter Jakacki Posts: 7,329
    edited April 28 Vote Up0Vote Down
    CtlAltDel wrote: »
    Hi all,

    I'm an electronics engineer based in Christchurch, New Zealand. In my spare time I've designed and built a small data acquisition and control system (which I've called DAQiri), with a view to using it as the control system for a scanning tunnelling microscope. The heart of the DAQiri system is a Propeller V1. The Propeller lines are divided into 4 groups and brought out to card slots. I've documented the hardware here: https://hackaday.io/project/27911-daqiri-a-data-acquisition-and-control-platform

    While trying to decide what language to use (Spin? PASM? PropGCC?) I discovered Tachyon FORTH. I think it's just what I'm looking for - compact and fast! Now I just need to learn it :)

    I've loaded v4.7 into DAQiri, and wrote some code to drive a stepper motor (a 28BYJ-48 driven by a ULN2003, via a TCA9535 I2C expansion IC):


    Hi Andrew, welcome to the Parallax forum and in particular to the Tachyon threads :) Good to hear you considered more than one option and ended up trying Tachyon out and it works for you!

    Forth encourages factoring code not just into smaller reusable functions but also if well structured and named, into an application specific language too. By using words like "STEPS" and "PACE" you can imagine that if you also defined constants named FAST, SLOW, MEDIUM you can end up talking to Tachyon like this:
    MEDIUM PACE 100 STEPS
    and since PACE "falls through" to motor_init you don't even have to specifically call that function either.


    Without changing the code too much here's a way you can factor and use your code. BTW, Tachyon allows fall-through code in that the end of a previous definition can fall through to the following code if you want it too. But unless you need to write to another TCA9535 there is probably no need for TCA! or even motor_init names either.

    BTW, V5.2 NEON is the latest version and is more compact too as well as other enhancements. It is also very easy to add a keypad and LCD and even an SD card for logging etc. There's a quick binary to try out at that link.
    --- utility function to write a byte to an I2C chip register
    pub IO! ( data reg -- )		$40
    pub TCA! ( data reg dev -- )	<I2C I2C! I2C! I2C! I2C> ; 
    
    word pacems 
    --- set the pace but also make sure the I/O is initiialized
    pub PACE ( ms -- )		pacems W!
    --- Set I2C bus pins for stepper card, initialise TCA9535 ports 0 & 1 to output, set all outputs low
    pub motor_init ( -- )           7 6 I2CPINS 0 2 IO! 0 3 IO! 0 6 IO! 0 7 IO! ; 
    
    
    --- set motor phase outputs on port 0 of TCA9535 and delay for programmed speed
    pub STEP ( phase --)		2 IO40! pacems W@ ms ;
    
    --- Turn on activity LED for motor 1, run for <steps> steps, at set ms pace between phase outputs 
    pub STEPS ( steps -- )       	3 HIGH FOR $02 STEP $04 STEP $08 STEP $10 STEP NEXT 0 STEP 3 LOW ; 
    { Example:
    5 PACE 100 STEPS
    
    Try defining FAST and SLOW and OPTIMAL as constants like this:
    2 == FAST 
    5 == MEDIUM 
    20 == SLOW
    
    }
    
    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    --->CLICK THE LOGO for more links<---
    Tachyon Forth News Blog
    P2 SHORTFORM DATASHEET
    TAQOZ documentation
    Brisbane, Australia
Sign In or Register to comment.