Shop Learn
Tachyon NEON V5 (FAT32 and Ethernet Servers in 32kB EEPROM!) - Page 9 — Parallax Forums

Tachyon NEON V5 (FAT32 and Ethernet Servers in 32kB EEPROM!)

1679111225

Comments

  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-27 13:18
    I wanted to add a simple melody player to the LCD CLOCK and now I've built it up to play across 8 octaves and uses a very simple format. I will expand on this later but for the moment you can just copy and paste this code but you need to assign an output. For example, I have a piezo connected to on P2 with 2 SPKR which will direct all tones to that output; I kept it real simple and connected the other end of the piezo transducer to ground.

    I've included two versions of TWINKLE TWINKLE LITTLE STAR with the second one you can even type STAR or SKY just to play that line(s). Try 6 OCTAVE TWINKLE to play the same song on the 6th octave.
    word tempo
    4 cword octave
    pub OCTAVE ( n -- ) 0 8 LIMIT octave C! ;
    pub SHIFT 
      octave C@ 4 - ?DUP IF DUP 0< IF ABS >> ELSE << THEN THEN ;
    
    pub T1        300 tempo W! ;
    pub T2        600 tempo W! ;
    pub NOTE        2 APIN SHIFT HZ tempo W@ ms MUTE 50 ms ;
    pub C        261 NOTE ;
    pub C#        277 NOTE ;
    pub D        294 NOTE ;
    pub D#        311 NOTE ;
    pub E        329 NOTE ;
    pub F        349 NOTE ;
    pub F#        370 NOTE ;
    pub G        392 NOTE ;
    pub G#        415 NOTE ;
    pub A        440 NOTE ;
    pub A#        466 NOTE ;
    pub B        493 NOTE ;
    
    pub TWINKLE
        T1 C C G G A A T2 G ( twinkle twinkle little star )
        T1 F F E E D D T2 C ( how I wonder what you are? )
        T1 G G F F E E T2 D ( up above the sky so high )
        T1 G G F F E E T2 D ( like a diamond in the sky )
        T1 C C G G A A T2 G ( twinkle twinkle little star )
        T1 F F E E D D T2 C ( how I wonder what you are )
    ;
    
    ( or alternatively )
    
    pri STAR        T1 C C G G A A T2 G   T1 F F E E D D T2 C ;
    pri SKY        T1 G G F F E E T2 D ;
    pub TWINKLE    STAR SKY SKY STAR ;
    
  • Peter,
    Made some progress this morning, got the LCD back to displaying again. I do thank your for the example code, it is helping me better understand Tachyon.I have never used Forth so I am learning a completely new language, NOT easy at 75 years old . I am not sure of the reason for the 1 emit in your code in the clock defination. How do I recover the day information as an actual number? The program I am working on needs the day number as part of a switch case defination. I will be checking for hours between 1500 and 2200 on days 1-5 and 20 minute segments 0-19, 20-39 and 40-59. My first CASE will BREAK if DAY >5. May get some more time to play later this AM as I got to work late.

    Again, thanks for all the help.
    Jim
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-27 23:39
    RS_Jim wrote: »
    Peter,
    Made some progress this morning, got the LCD back to displaying again. I do thank your for the example code, it is helping me better understand Tachyon.I have never used Forth so I am learning a completely new language, NOT easy at 75 years old . I am not sure of the reason for the 1 emit in your code in the clock defination. How do I recover the day information as an actual number? The program I am working on needs the day number as part of a switch case defination. I will be checking for hours between 1500 and 2200 on days 1-5 and 20 minute segments 0-19, 20-39 and 40-59. My first CASE will BREAK if DAY >5. May get some more time to play later this AM as I got to work late.

    Again, thanks for all the help.
    Jim

    The $0C is the ASCII code for a new page so I use this to clear the screen whereas I use the code of 1 to take it home without clearing the screen. I just had a look at the SEETRON displays and unfortunately their codes don't conform much to anything. My displays also have a lot more functionality that also allows the levels of brightness and contrast to adjusted over serial etc. My code of 2 sets it to display big digits where you can fit 4 digits across the screen but the digits are 4 lines high.

    So for a SEETRON LCD use these codes:
    --- main CLOCK task - in cog, assign hub regs,    clear         home   time on top line, continue indefintely
    pub CLOCK ( cog -- )	RUN: clkregs 8 COG! SERLCD 1 EMIT BEGIN 2 EMIT 4 SPACES .DT 100 ms AGAIN ;
    

    Use DAY@ (day fetch) to read the day as 1 to 7 for MON to SUN. Use DAY! (day store) to store the day. I found a small bug in EXTEND where the time variable (a long) was misaligned. I've now fixed this so make sure you load the new EXTEND which I've just updated it to report 180828-0000.

  • Ok, will update EXTEND to correct the time error. Probably first thing tomorrow AM.
    Jim
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-28 02:03
    MELODY PLAYER

    Here is an improved version of my initial melody code. This one stores the value for the notes in the 8th octave and simply divides down for the lower octaves. Later on I will introduce a better way of handling time signatures etc as well as a simple way to play notes in a string the same way that PRINT" works.

    At the moment this is all I've had time to play with but you can type notes in from the terminal and play them instantly.
    Try typing in: ct h D G A B h B d R ct B A B h G h G
    (hint - just copy and paste)
    TACHYON V5
    module MELODY		PRINT" Simple melody player 180828.0000 " ;
    
    300 cword tempo
    --- crotchet
    pub ct		300 tempo W! ;
    --- half and double timing
    pub h		tempo W@ 2* tempo W! ;
    pub d		tempo W@ 2/ tempo W! ;
    4 cword octave
    pub OCTAVE ( n -- ) 0 8 LIMIT 8 SWAP - octave C! ;
    ALIAS OCTAVE o
    pre NOTE   	CREATE W, DOES> R> W@ octave C@ >> HZ
    --- rest - also holds notes before muting
    pub R		tempo W@ ms MUTE 50 ms ;
    --- define notes in their 8th octave so we only have to divide down
    7902 NOTE B
    7459 NOTE A#
    7040 NOTE A
    6645 NOTE G#
    6272 NOTE G
    5920 NOTE F#
    5588 NOTE F
    5274 NOTE E
    4978 NOTE D#
    4699 NOTE D
    4435 NOTE C#
    4186 NOTE C
    
    pri STAR	ct C C G G A A h G   ct F F E E D D h C ;
    pri SKY		ct G G F F E E h D ;
    pub TWINKLE	STAR SKY SKY STAR ;
    
    END
    
    { DEMOS
    --- select a speaker pin
    2 SPKR
    --- play 1st line over 9 octaves
    9 FOR I o STAR NEXT
    
    --- you are my sunshine (rough)
    ct h D G A B h B d R  ct B A B h G h G
    
    }
    
  • RS_JimRS_Jim Posts: 1,453
    edited 2018-08-28 14:17
    Have 180828 downloaded and installed. No time yet to re install my programs. this time I will write my code out in an editor and paste it in to try the results.
    Jim
  • Peter,
    If I wanted to display The day as a number would it be like this?
    DAY@ $30 + EMIT
    
    I realize that for my coding I can use the result directly sort of like
    IF DAY@ >5 BREAK
    
    JIm
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-28 14:48
    Jim - simply print the day as a number but use PRINT instead of the dot symbol . since PRINT doesn't add any spaces whereas the dot adds a space after the number to help during console interaction. So DAY@ PRINT

    To convert that second statement to Tachyon Forth would be like this:
    DAY@ 5 > IF <do something> THEN
    or to simply return (break) when DAY>5 use the ?EXIT which will EXIT (return) if the flag is true (DAY>5).
    DAY@ 5 > ?EXIT

  • Peter,
    latest code
    pub SERLCD      19200 SERBAUD 6 SERIAL ;
    FORGET CLOCK
    128 bytes clkregs
    pub CLOCK  3 RUN:
    	clkregs 8 COG! 
     	SERLCD  17 EMIT  
    	BEGIN  12 EMIT 5 ms  .TIME  100 ms AGAIN ;
    
    pub !CLOCK 3 CLOCK ;
    ' !CLOCK + INIT BACKUP
    
    
    will print "Hello" to lcd but clock will not run
    Jim
  • RS_JimRS_Jim Posts: 1,453
    edited 2018-08-28 17:58
    Forgot to update you on my LCD, it is a Parallax 2 line with back light. Will display .TIME from the console just CLOCK won't run. Also not writing the time to RTC. Boot shows it being present but ^C and it is being reset. Also not reading Temp using 'F. I am sure I did $D0 SETRTC BACKUP.
    Off to work. Will have more time tomorrow as is a day off.
    Jim
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-28 22:24
    Since you have a "3" in this:
    pub CLOCK  3 RUN:
    
    There is no need for this:
    pub !CLOCK 3 CLOCK ;
    
    since the cog number 3 is already locked into the CLOCK definition itself.
    So you do not need !CLOCK and just:
    ' CLOCK   +INIT    BACKUP
    
    Notice though that (with extra whitespace) I have the word +INIT (add INIT) to add a new initialization vector to the startup table. I don't know if you have a typo but INIT is a separate word that actually performs the initialization at boot time. FYI, there's also !INITS which initializes the initialization table, effectively disabling any user code from autostarting.

    Also if you happen to test the LCD from cog 0 then it will "own" the I/O pin on P6 in that it will leave it high with cog 3 unable to make the pin go low to transmit since I/O pins are OR'd between all the cogs. Don't test but if you do test then simply include a 6 FLOAT after you are done so cog 3 can still use it.

    If you are not sure about the $D0 SETRTC BACKUP then do it again as the soft time is reset on every boot with !RTC and if an RTC hardware address is locked into EEPROM with SETRTC BACKUP then it will read that device and then set the time.

    BTW, I found a couple more bugs in my RTC routines, not just the misaligned time variable, I also had a bug in my midnight synchronization code which says if the time is => 24:00:00 then it will perform an !RTC which goes through that same boot procedure and ends up reading the hardware back into the soft RTC, taking care of the date at the same time. But the timer routine WAITCNTs every millisecond and !RTC was causing it to miss the WAITCNT, so the time appeared to be frozen for the next 53.68 seconds until the 32-bit CNT would wraparound and WAITCNT could trip again. Now I just restart the timing loop at midnight which gets around this hiccup. So use the latest EXTEND (again).

    Remember that Forth source code is not lexed by a big PC compiler tool, so OVER+SWAP are not the three words OVER and + and SWAP that will be recognized and tokenized, instead Forth will search the dictionary for a 9 character word called OVER+SWAP and upon not finding it, it will report that it was not found. Sure, you could define a 9 character OVER+SWAP word that does just that or something completely different, but once again, the exact word must match in the dictionary. It's also possible to add lexing to Forth but what's possible is not always best.
  • Peter,
    Years ago,I was a product manager and one of my functions was to break the control software so that Engineering could find the bugs. Feels like I am doing it with TACHYON. Did not realize test routine was leaving 6 locked hi. Will be happy to version update, what# will I likely see tomorrow AM?
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-29 03:01
    RS_Jim wrote: »
    Peter,
    Years ago,I was a product manager and one of my functions was to break the control software so that Engineering could find the bugs. Feels like I am doing it with TACHYON. Did not realize test routine was leaving 6 locked hi. Will be happy to version update, what# will I likely see tomorrow AM?

    You're a natural ;)

    Locking a pin high is a common mistake on the Prop chip, no matter whether you program in Spin, PASM, C, Basic, or Forth etc. It's the nature of the beast because it is so flexible, it lets any cog use any pin at any time. This is one of the reasons I love the Prop, the flexibility of its I/O pins.

    The thing with anything new is not to fall back on old assumptions, you need to be slow and methodical, especially for the first few steps, and then you start picking up speed without tripping over yourself!


    btw - checked the commands codes on the Parallax display and they use a standard $0C as the clear display and return home command but if you want to just go home without clearing the display you need to send $80 which positions the cursor in the top left hand corner. Also send it a $16 when you startup to hide the cursor and maybe an $11 to turn on the backlight.

    EDIT
    Here is the code as it should ideally be, including the bit that tells the cog to stop in case it is already running and forgetting from the very first definition which is actually SERLCD, just to have a clean slate. No need to keep clearing the display every 100ms and then having to wait, just go home and it will overwrite. I've put extra spaces between some words just to make sure you see them clearly.
    3 COGSTOP 
    FORGET SERLCD
    pub SERLCD      19200 SERBAUD 6 SERIAL ;
    128 bytes clkregs
    pub CLOCK  3 RUN:
    	clkregs 8 COG! 
     	SERLCD  $11 EMIT $16 EMIT $0C EMIT 3 ms
    	BEGIN  $80 EMIT  .TIME  100 ms AGAIN ;
    
    '   CLOCK   +INIT
    $D0 SETRTC
    BACKUP ( backup all code and setttings )
    


    If anyone wants some really high quality 20x4 FSTN amber backlit SERIAL LCD modules, I've got plenty of stock left over from supplying an OEM. The more you buy, the cheaper they are, but still cheaper than anybody else.
  • Cluso99Cluso99 Posts: 17,681
    Wow. Melodies too :)
  • If anyone wants some really high quality 20x4 FSTN amber backlit SERIAL LCD modules, I've got plenty of stock left over from supplying an OEM. The more you buy, the cheaper they are, but still cheaper than anybody else.

    How much and where do I order them?
  • I'd love to have a few too if the price/shipping isn't too high to California!
  • DaveJenson wrote: »
    If anyone wants some really high quality 20x4 FSTN amber backlit SERIAL LCD modules, I've got plenty of stock left over from supplying an OEM. The more you buy, the cheaper they are, but still cheaper than anybody else.

    How much and where do I order them?

    Ditto!
  • Never mind,saw your post in general discussion
  • Peter,
    I think I broke something again! I paisted the following code into the system after downloading the latest EXTEND
    3 COGSTOP 
    FORGET SERLCD
    pub SERLCD      19200 SERBAUD 6 SERIAL ;
    128 bytes clkregs
    pub CLOCK  3 RUN:
            clkregs 8 COG! 
            SERLCD  $11 EMIT $16 EMIT $0C EMIT 3 ms
            BEGIN  $80 EMIT  .TIME  100 ms AGAIN ;
    
    '   CLOCK   +INIT
    $D0 SETRTC
    BACKUP  
    
    When I do a ^C the following starts running looping and rebooting. I can stop it with ^A but ?? gives me no results. If I do !INITS BACKUP . The system will allow me to reboot normally. I can then manually enter CLOCK and the clock will run and diplay on the LCD with the backlite on
      Propeller .:.:--TACHYON--:.:. Forth V5r4 NEON 540180811.0000
      *** MODULES ***  Propeller .:.:--TACHYON--:.:. Forth V5r4 NEON 540180811.0000
    31B4: TOOLS            DEV TOOLS
    1980: EXTEND           Primary extensions to TACHYON V5 kernel  - 180829-0000
    
    AUTORUN BOOT 3146
    FREQ = 80.00MHZ
    *** INITS ***
    RESET 0000
    NO ROMS
    *** I2C ***
    $A0 EE/RTC
    $D0 RTC
    I/O =  31 :UHU~ 27 :U~~~ 23 :~~~~ 19 :~~~~ 15 :~~~~ 11 :~~~~ 7 :~U~~ 3 :~~~~
    INTERCOM:
    
    CODE:$39B6 = 14262 bytes
    NAME:$5B26 = 6362 bytes
    DATA:$7659 = 329 bytes
    FREE:      = 8560 bytes
     Data Stack (0)
    Mon, 01 Jan 2001 00:00:00 UTC
    
      Propeller .:.:--TACHYON--:.:. Forth V5r4 NEON 540180811.0000
      *** MODULES ***  Propeller .:.:--TACHYON--:.:. Forth V5r4 NEON 540180811.0000
    31B4: TOOLS            DEV TOOLS
    1980: EXTEND           Primary extensions to TACHYON V5 kernel  - 180829-0000
    
    AUTORUN BOOT 3146
    FREQ = 80.00MHZ
    *** INITS ***
    RESET 0000
    NO ROMS
    *** I2C ***
    $A0 EE/RTC
    $D0 RTC
    I/O =  31 :UHU~ 27 :U~~~ 23 :~~~~ 19 :~~~~ 15 :~~~~ 11 :~~~~ 7 :~U~~ 3 :~~~~
    INTERCOM:
    
    CODE:$39B6 = 14262 bytes
    NAME:$5B26 = 6362 bytes
    DATA:$7659 = 329 bytes
    FREE:      = 8560 bytes
     Data Stack (0)
    Mon, 01 Jan 2001 00:00:00 UTC
    
      Propeller .:.:--TACHYON--:.:. Forth V5r4 NEON 540180811.0000
     <aborting startup>
    
    Do I have the correct version of EXTEND?
    JIM
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-30 05:49
    I examined that mystery and it kept booting too. When I examined the vector that INIT was using I found that it was 0 (a false result). However ' CLOCK returned the correct address but putting extra spaces in there threw it out!!!!! :) I think this has to do with a different method I introduced to read additional parameters. For now it is easily fixed (or not broken) if we just use a single space between the ' and CLOCK. Extra spaces don't matter with anything else, but just keep it to a single space for now for any ' type words.
    AUTORUN BOOT 3146
    FREQ = 80.00MHZ
    *** INITS ***
    RESET 0000
    NO ROMS
    


    Wow, that was a weird one.
  • I told you that I was good at breaking software! Reinstalled clock without the extra spaces and the system will reboot once with a ^C and the clock will run in the background as was the goal. Now on to the next problem, I don't seem to be communicating with the RTC module. I set the time with 055000 TIME! and the clock will start counting from that time. I then do a ^C and it starts over counting at 21:00:00. I have to go back and look att thee glossery as I don't remember how to diaplay the Temperature from the DS1302. We know there is some communiction there as the RTC is reported at $D0. I outlined my program last night for my "Energy Management system" and I think it is going to be very easy to do. I need to figure out how to set up some I/O pin masks and re-examine my logic and go from there.
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-30 13:31
    Yeah, but it was me who put the extra spaces in there to make it clear which word was which!

    Which RTC chip do you have. The DS1302 is an SPI bus chip, I thought you had the DS1307 but it is the DS3231 that also has temperature available which we read with 'C or 'F.

  • Yes, I think it is a 1302 module I got from Parallax.
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-30 13:53
    What! a DS1302! That is NOT an I2C bus chip at all. Back on August the 8th you said " Attched RTC to i2c bus and it is recognized on boot." but now I wonder what magic is happening on your end. I don't bother supporting older SPI bus RTCs as there is no reason to use them when I2C RTCs do not require any extra I/O pins on the Prop. There are plenty of modules out there, maybe I should sell my tiny little modules that are equipped with a small super cap that never needs replacing and of course is not "a lithium primary cell". The cap will keep the RTC alive for a week without power which I figure means that it is out of service anyway.

    The one on the right has a really tiny supercap, good for a couple of days without power. Recharges within a minute or so.
    rtcpcbs.jpg
    1024 x 490 - 105K
  • My module is clearly marked with SCL and SDA pins with no markings for SPI. I just went looking to see if I could find the Parallax part number. BOY do I feel stupid! the module is not a DS1302 at all but a DS3231. I will have to go look see if that is supported and change my init statement. A really good reason not to communicate with the RTC!
    Jim
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-30 14:13
    Whew! Strange, sounds like the DS3231 made for RPi boards. This part is fully supported including the temperature sensor. Just use $D0 SETRTC along with the backup. But that doesn't explain why your software is not reading the chip. Remember that you have to use SETRTC before you use TIME! for the first time so that it writes the time to the chip as well. Ideally you should always set the date too. If the setting is not backed up or you reload your kernel, then the RTC address will be lost.

    These are the temperature words:
    pub 'C ( -- 'C*100 )		rtc# IF $12 RTC@ $11 RTC@ B>W 6 >> 25 * ELSE 0 THEN ;
    pub 'F ( -- 'F*100 )		'C 9 5 */ 3200 + ;
    pub .TEMP			'C .AS" #~#.##'C "  ;
    
    So the output of both 'C and 'F are scaled x100 so that 25.75'C would read 2575.
  • RS_JimRS_Jim Posts: 1,453
    edited 2018-08-30 14:28
    Yeah I see that the SETRTC with a$D0 is all that is required to set the RTC for the 3231. I will try the temp command in few minutes to see if I get any response. I do know that if I run the software (as modified without extra spaces between ' Clock, the clock is happily running in the background. It is just when I do ^C the clock restarts at 21:00:00.
    EDIT When I set the date does the software figure out the day of the week or do I need to set that as well?
  • The day needs to be set manually and bear in mind that for some Sunday is the start of the week but for me Monday is day 1.

    21:00:00 sounds like the RTC is reading back (otherwise it's zero) but not running, since it doesn't increment. Could it be that the /EOSC enable oscillator bit was set in register $0E of the DS3231? You can check using RTC@ or even dump the contents like this:
    RTC 0 $20 DUMP
    
    Check register $0E (address) and the msb should be clear. If not then write directly to the register like this:
    0 $0E RTC!
    
  • Peter,
    First dump of RTC:
    ...  RTC 0 $20 DUMP
    0000.0000:   7F 7F 07 07  3F 9F FF FF  00 00 3F 00  00 BF 1F 8F    ....?.....?.....
    0000.0010:   00 1F 80 00  00 00 00 00  00 00 00 00  00 00 00 00    ................ ok
    ...  0 $0E RTC!  ok
    ...  RTC 0 $20 DUMP
    0000.0000:   3F 00 0F 07  3F 9F FF FF  00 00 3F 00  00 BF 00 8F    ?...?.....?.....
    0000.0010:   00 1F 80 00  00 00 00 00  00 00 00 00  00 00 00 00    ................ ok
    ...  .TEMP 31.50'C  ok
    ...  080300 TIME!  ok
    ...
    

    Next I set the time then do another ^C
    ...  RTC 0 $20 DUMP
    0000.0000:   3F 07 0F 07  3F 9F FF FF  00 00 3F 00  00 BF 00 8F    ?...?.....?.....
    0000.0010:   00 1F 80 00  00 00 00 00  00 00 00 00  00 00 00 00
    
    .TIME comes back 21:00:00
    OK so where do I go from here?
    Jim
  • Peter JakackiPeter Jakacki Posts: 10,166
    edited 2018-08-30 21:57
    The trick is to do a dump after you set the time to check that it is in fact setting the time, and then to reset and double-check.

    This is my dump of a DS3231: ( it doesn't matter where the RTC word is, as long as it is before the DUMP )
    ...  0 $20 RTC DUMP 
    0000.0000:   00 30 07 05  31 08 18 00  00 00 3F 10  00 3E 1C 88    .0..1.....?..>..
    0000.0010:   00 15 40 00  00 00 00 00  00 00 00 00  00 00 00 00    ..@............. ok
    

    31.5'C ..... sounds like an outdoor temperature.

    BTW, try writing directly to a register such as address 0 with:
    $50 0 RTC!
    which will set the seconds to 50 and a dump should show it counting up and wrapping... not $3F though.
Sign In or Register to comment.