Shop OBEX P1 Docs P2 Docs Learn Events
Propforth v5.5 is available for download - Page 22 — Parallax Forums

Propforth v5.5 is available for download

12022242526

Comments

  • Question came in about serial comms and laser range finders.

    This is stuff I have for both:

    this page https://code.google.com/p/propforth/wiki/LIDARLite
    for I2C (faster communications but not serial)
    and this page https://code.google.com/p/propforth/wiki/SF02LaserRangeFinder
    for serial (easier if you know only serial and not I2C)

    If you have a laser rangefinger that is not either of those, please post!

    Also, if you have questions about those two pages, please ask. When I did those they made sense at the time and appeared to work, but I don't know if anybody else tried them yet. There may be errors.
  • caskazcaskaz Posts: 957
    edited 2015-11-03 02:28
    I tried to play a sound by using HDD.
    Used only sound part of code"SimpleGame2_0.1" below;
    http://forums.parallax.com/discussion/146693/propforth-v5-5-is-available-for-download/p18

    [video] [/video]
  • Modified a littel little bit PDF for SerialCommunication on 4/8.
  • caskazcaskaz Posts: 957
    edited 2015-11-09 07:55
    I wrote code for INA226.
    Shunt-resistor is 0.025ohm.

    Using i2c_utility_0.4_1.f.
    i2c_utility_0.4_1.f. modified only comments from i2c_utility_0.4.f.

    INA226's reading from I2C use 'i2c_rd_multi'.
    (PDF procedure is different.)
    I found out 'i2c_wr_multi is also available.
    I will update code later.

    Prop0 Cog6 ok
    i2c_detect
         0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
    00: 00 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- <-- INA226 reply
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- -- <-- APDS-9960
    40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- <-- INA226
    50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- <-- eeprom
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    i2c_device:3
    [0 - 7] and [h78 - h7F] are reserve-address
    
    Prop0 Cog6 ok
    ID
    Manufacture ID:h5449
    Die ID:h2260
    Prop0 Cog6 ok
    init_INA226
    Prop0 Cog6 ok
    dispReg
    
    Register                Value
    Configuration(h00):     h4727
    Shunt Voltage(h01):     d47
    Bus Voltage(h02):       d2625
    Power(h03):             d7
    Current(h04):           d47
    Calibration(h05):       d2048
    Mask/Enable(h06):       h8
    Alert Limit(h07):       d0
    Prop0 Cog6 ok
    demo
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .7 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:4 .6 mA Power:17 mW
    Prop0 Cog6 ok
    
    1024 x 816 - 316K
  • Updated code.
    demo
    Bus_V:3272 mV   Current:-4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:-4 .7 mA Power:17 mW
    Bus_V:3272 mV   Current:-4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:-4 .6 mA Power:17 mW
    Bus_V:3272 mV   Current:-4 .6 mA Power:17 mW
    Prop0 Cog6 ok
    
  • This is really interesting. What is INA226 used for in an application? For example, can we measure current and voltage to a DC motor, and determine how much load the motor is seeing as any given measurement?
  • caskazcaskaz Posts: 957
    edited 2015-11-10 01:54
    Hi ProfBraino.

    Changing shunt-resistor get different measure-range and resolution.
    This module use 0.025ohm; Resolution=0.1mA Range=-3.2768A to +3.2767A
    If shunt-resistor is 0.002ohm; Resolution=1mA Range=-32.768A to +32.767A

    This can connect both Hi-side and Lo-side for motor,etc.
    Application are power monitor,motor current monitor, etc.
    shunt-voltage,Bus voltage,power can issue limit-alert to alert-pin.
    This module cost 1000yen(about $8).
  • caskazcaskaz Posts: 957
    edited 2015-11-24 04:12
    I had written code about Charlieplexing in Novenber 2014.
    Date is unknown. I seems this forum delete date.
    I found out there is bug in Charlieplexing_8x8Matrix_0.3_1.f

    I re-write code and summary.
    But summary is bigger than 2M.
    Cannot upload.

    I upload only "Charlieplexing_8x8Matrix_0.3_2".

    Re-wrote word are 'matrix_Charlie_fth' and '_matrix_Charlie_asm'.
  • I will send you some notes about github, maybe we can put your notes in the propforth 5.5 github repository?
  • I wrote code for TouchScreen with threshold.

    Using TouchScreen under noise;
    1) Using capacitance
    2) Averasing value(x,y)
    3) Measuring TouchPressure, Use it as threshold value

    This time, measured TouchPress.
    This use float.f
    Prop0 Cog6 ok
     getZ
    *
    *
    *                                                      <--- Not touch
    *
    *
                                  *
                                           *               <--- Touching
                                              *
                                                *
                                             *
                                      *
    *
    *
    *
                                            *
                                              *
                                              *
                                                 *
                                              *
                                             *
    *
    *
    *
    *
    Prop0 Cog6 ok
    
  • caskazcaskaz Posts: 957
    edited 2015-11-24 13:25
    It's calculation for TouchScreen pressure.
    4096 is resolution of ADC(MCP3204).
    4320 x 3240 - 1M
    4320 x 3240 - 1M
  • caskazcaskaz Posts: 957
    edited 2015-12-18 05:37
    Hi.
    I'm going to practice Github.
    I uploaded "Charlieplexing".
    https://github.com/caskaz/PropForth5.5

    I erase someday because of practice.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-12-12 12:55
    Caskaz,
    What are you trying to do? Are you using a touch panel and trying to determine where it is pressed?
    If so, you can use the props sigma delta to do this but may not be as precise as you require. IIRC I posted pasm code in a thread a few years ago. Not sure if I put it in obex.
  • caskazcaskaz Posts: 957
    edited 2015-12-29 12:50
    I wrote code for TouchScreenController(ADS7843).
    fl
    
    {
    TouchScreen Controller(ADS7843)
    PropForth5.5
    
    2015/12/27 13:21:41
    
               --------------             
        3V3-- |Vref         Vcc| -- 3V3     -----------
    P5 -----> |cs            X+| --------- |           |
    P6 -----> |clk           X-| --------- |TouchScreen|
    P7 -----> |din  ADS7843  Y+| --------- |           |
    P8 <----- |dout          Y-| --------- |           |
              |     GND        |            -----------
               ----------------
                     |
                    GND
              
    }
    
    
    \ -------------------------------------------------------
    \ Constants
    \ -------------------------------------------------------
    5 wconstant cs
    6 wconstant clk
    7 wconstant din
    8 wconstant dout
    1 dout lshift constant doutm
    \ A/D selection
    1 wconstant Ydata
    5 wconstant Xdata
    2 wconstant Aux1
    6 wconstant Aux2
    \ Resolution
    0 wconstant 12bitData
    1 wconstant 8bitData
    \ Single/Differential
    0 wconstant diff
    1 wconstant single
    \ PowerDown selection
    0 wconstant enablePD
    1 wconstant disablePD
    
    \ -------------------------------------------------------
    \ Variables
    \ -------------------------------------------------------
    
    
    \ -------------------------------------------------------
    \ Main
    \ -------------------------------------------------------
    \ Output clk-pulse
    \ ( -- )
    : clk_pulse clk pinhi clk pinlo ;
    
    \ Set din to Hi
    \ ( -- )
    : din_h din pinhi ;
    \ Set din to Lo
    \ ( -- )
    : din_l din pinlo ;
    
    \ Convert analog to digital
    \ ( n1 n2 n3 n4 -- n5 ) n1:PD n2:single/diff(select single when Aux1/Aux2) n3:mode n4:address   n5:conversion data
    : ADS7843
    \ Set output port
    cs pinhi cs pinout clk pinout din pinout
    
    cs pinlo
    1                   \ Start bit
    3 lshift or         \ Add address
    over >r             \ Push mode
    1 lshift or         \ Add mode
    1 lshift or         \ Add single/diff
    2 lshift or         \ Add PD
    \ Send control data
    h80
    8 0 do
         2dup and
         if din_h else din_l then
         clk_pulse
         1 rshift
    loop
    2drop
    clk_pulse 
    \ Read data
    0                             
    r>                  \ Pop mode
    dup >r          \ Push mode
    if 8 else d12 then
    0 do
         1 lshift
         clk pinhi 
         ina COG@ doutm and      
         if 1 or then
         clk pinlo
    loop
    r>
    if
         clk_pulse clk_pulse clk_pulse
    else
         7 0 do clk_pulse loop
    then          
    cs pinhi
    ;
    
    
    \ Display 12bit(x,y) on TouchScreen
    \ ( -- )
    : demo
    begin
    enablePD diff 12bitData Ydata ADS7843 d2047 - .
    enablePD diff 12bitData Xdata ADS7843 d2047 - . cr 
    d100 delms
    fkey? swap drop
    until
    ;
    
    \ Display 8bit(x,y) on TouchScreen
    \ ( -- )
    : demo1
    begin
    enablePD diff 8bitData Ydata ADS7843 d127 - .
    enablePD diff 8bitData Xdata ADS7843 d127 - . cr 
    d100 delms
    fkey? swap drop
    until
    ;
    
  • caskazcaskaz Posts: 957
    edited 2015-12-30 11:38
    I wrote code for TouchScreenController(ADS7843) by using SPI-communication.
    When pen touched on touchscreen, measurment start.
    Data(x,y) are average-value[8samples].
    fl
    
    {
    TouchScreen Controller(ADS7843)
    PropForth5.5
    
    2015/12/30 13:19:29
    
               ----------------             
        3V3-- |Vref         Vcc| -- 3V3     -----------
    P5 -----> |cs            X+| --------- |           |
    P6 -----> |clk           X-| --------- |TouchScreen|
    P7 -----> |din  ADS7843  Y+| --------- |           |
    P8 <----- |dout          Y-| --------- |           |
         3V3  |                |            -----------
          |   |                |
         10k  |                |
          |   |                |
    P9 <----- |PENIRQ          |  
              |           GND  |
               ----------------
                           |
                          GND
    TouchPosition(X,Y) is averaged by sampled 8 times.
                          
    }
    
    
    \ -------------------------------------------------------
    \ Constants
    \ -------------------------------------------------------
    5 wconstant cs
    6 wconstant clk
    7 wconstant din
    8 wconstant dout
    1 dout lshift constant doutm
    9 wconstant penirq
    1 penirq lshift constant penirqm
    \ A/D selection
    9 wconstant Ydata
    hD wconstant Xdata
    hA wconstant Aux1
    hE wconstant Aux2
    \ Resolution
    0 wconstant 12bit
    1 wconstant 8bit
    \ Single/Differential
    0 wconstant diff
    1 wconstant single
    \ PowerDown selection
    0 wconstant enablePD
    1 wconstant disablePD
    8 wconstant average
    
    \ -------------------------------------------------------
    \ Variables
    \ -------------------------------------------------------
    wvariable cont_X
    wvariable cont_Y
    wvariable contAux1
    wvariable contAux2
    
    \ -------------------------------------------------------
    \ Main
    \ -------------------------------------------------------
    
    \ Set clk to Hi
    \ ( -- )
    : clk_h clk pinhi ;
    
    \ Set clk to Lo
    \ ( -- )
    : clk_l clk pinlo ;
    
    \ Set din to Hi
    \ ( -- )
    : din_h din pinhi ;
    \ Set din to Lo
    \ ( -- )
    : din_l din pinlo ;
    
    \ Set control byte(X and Y) for TouchScreen 
    \ ( n1 n2 n3 -- ) n1:mode n2:single/differential n3:PowerDown
    : setTSC
    swap 2 lshift or
    swap 3 lshift or
    dup
    Ydata 4 lshift or cont_Y W!
    Xdata 4 lshift or cont_X W!
    ;
    
    \ Set control byte(Aux1 and Aux2) for Aux 
    \ ( n1 n2 n3 -- ) n1:mode n2:single/differential n3:PowerDown
    : setAux
    swap 2 lshift or
    swap 3 lshift or
    dup
    Aux1 4 lshift or contAux1 W!
    Aux2 4 lshift or contAux2 W!
    ;
    
    \ SPI communication
    \ ( n1 -- n2 ) n1;control byte  n2:data
    : 24bitSPI
    cs pinlo
    0 swap                                  \ ( 0 n1 )
    d16 lshift h800000                      \ ( 0 n1 h800000 )
    d24 0 do
         \ transmitt
         2dup                               \ ( 0 n1 h800000 n1 h800000 )
         and
         if din_h else din_l then
         clk_h                              \ Send 1bit to din
         \ receive
         rot                                \ ( n1 h800000 0 )
         ina COG@ doutm and
         if 1 or then 1 lshift rot2         \ Receive 1bit from dout
         clk_l
         1 rshift                              
    loop
    2drop
    1 rshift
    cs pinhi
    ;
    
    \ Get A/D 1data
    \ ( n1 -- n2 )  n1;control byte  n2:data
    : rdA/D
    dup 24bitSPI                            \ ( n1 [received data] )
    swap 8 and                              \ ( [received data] 1/0 )
    if
         \ 8bit mode
         7 rshift hFF and
    else
         \ 12bit mode
         3 rshift hFFF and
    then                                    \ ( n2 )
    ;     
         
    \ Get Touch position
    \ ( -- )
    : rdTouch
    0                                       \ initial sum for Y
    average 0 do
         cont_Y W@ rdA/D               
         +
    loop                                
    average u/   
    0                                       \ initial sum for X
    average 0 do
         cont_X W@ rdA/D               
         +
    loop                                
    average u/   
    ;
    
    : demo
    \ Set data for TouchScreenController 
    12bit diff enablePD setTSC
    \ Set output port
    cs pinhi cs pinout clk pinout din pinout
    
    begin
         begin ina COG@ penirqm and 0= until      \ Wait until pen-touch is detected
         rdTouch ." X:" . ." Y:". cr
         fkey? swap drop
    until
    
    \ Set data for TouchScreenController 
    8bit diff enablePD setTSC
    begin
         begin ina COG@ penirqm and 0= until      \ Wait until pen-touch is detected
         rdTouch ." X:" . ." Y:". cr
         fkey? swap drop
    until
    ;
    
    \ Time to get X-position
    \ ( -- )         
    : test2 cnt COG@ cont_X W@ rdA/D cnt COG@ nip swap - dup . ." ticks  "  d80 u/ . ." usec" ;
    
    

  • caskazcaskaz Posts: 957
    edited 2016-01-02 04:09
    I wrote TouchScreen Controller' code by using 2cog.
    Cog6 send control-byte and clock.
    Cog0 receive A/D conversion data from ADS7843.
    8data need 136clocks(12bit mode), 104clocks(8bit mode).

    Above SPI code, it need 24clock(12bit mode/8bit mode).
    It need 196clock at 8data.
    fl
    
    {
    TouchScreen Controller(ADS7843)
    PropForth5.5
    
    2016/01/01 12:28:21
    
               ----------------             
        3V3-- |Vref         Vcc| -- 3V3     -----------
    P5 -----> |cs            X+| --------- |           |
    P6 -----> |clk           X-| --------- |TouchScreen|
    P7 -----> |din  ADS7843  Y+| --------- |           |
    P8 <----- |dout          Y-| --------- |           |
         3V3  |                |            -----------
          |   |                |
         10k  |                |
          |   |                |
    P9 <----- |PENIRQ          |  
    P10 <---- |busy            |
              |           GND  |
               ----------------
                           |
                          GND
    }
    
    
    \ -------------------------------------------------------
    \ Constants
    \ -------------------------------------------------------
    5 wconstant cs
    1 cs lshift constant csm
    6 wconstant clk
    1 clk lshift constant clkm
    7 wconstant din
    8 wconstant dout
    1 dout lshift constant doutm
    9 wconstant penirq
    1 penirq lshift constant penirqm
    d10 wconstant busy
    1 busy lshift constant busym
    \ A/D selection
    9 wconstant Ydata
    hD wconstant Xdata
    hA wconstant Aux1
    hE wconstant Aux2
    \ Mode
    0 wconstant 12bit
    1 wconstant 8bit
    \ Single/Differential
    0 wconstant diff
    1 wconstant single
    \ PowerDown selection
    0 wconstant enablePD
    3 wconstant disablePD
    8 wconstant average
    
    \ -------------------------------------------------------
    \ Variables
    \ -------------------------------------------------------
    wvariable cont_X
    wvariable cont_Y
    wvariable posX
    wvariable posY
    wvariable aveVal
    
    \ -------------------------------------------------------
    \ Main
    \ -------------------------------------------------------
    \ Output clk-pulse
    \ ( -- )
    : clk_pulse clk pinhi clk pinlo ;
    
    \ Set din to Hi
    \ ( -- )
    : din_h din pinhi ;
    
    \ Set din to Lo
    \ ( -- )
    : din_l din pinlo ;
    
    \ Set control byte(X and Y) for ADS7843 
    \ ( n1 n2 n3 -- ) n1:mode n2:single/differential n3:PowerDown
    : setTSC
    swap 2 lshift or
    swap 3 lshift or
    dup
    Ydata 4 lshift or cont_Y W!
    Xdata 4 lshift or cont_X W!
    ;
                
    \ Wait until busy fall down
    \ ( -- )
    : waitBusy
    begin ina COG@ busym and until
    begin ina COG@ busym and 0= until
    ;
    : waitBusy
    busym busym waitpeq           \ Wait until busy goes to Hi
    busym busym waitpne           \ Wait until busy goes to Lo
    ;
    
    \ Read A/D conversion data
    \ ( n1 -- n2 )  n1:8 or 12  n2:A/D conversion value
    : rdA/D
    0                             \ Initial value
    swap 0 do
         1 lshift
         clkm clkm waitpeq        \ Wait until clk go to Hi
         ina COG@ doutm and   
         if 1 or then
         clkm clkm waitpne        \ Wait until clk go to Lo
    loop
    ;
    
    \ Get average value
    \ ( -- n1 ) n1:average value
    : rdTS
    begin
         begin ina COG@ csm and 0= until    \ Wait until cs goes to Lo
         0                                  \ Initial average value
         average 0 do
              waitBusy                      \ Wait until busy fall down
              cont_X W@ 8 and               \ Check mode
              if 8 else d12 then
              rdA/D                         \ Get A/D value
              +
         loop
         8 u/ aveVal W!
         begin ina COG@ csm and until       \ Wait until cs goes to Hi
    0 until
    ;
    
    \ Send controlByte(8bit) and only clock-pulse
    \ ( n1 -- )  n1:control byte
    : sendData
    h80
    8 0 do
         2dup and
         if din_h else din_l then
         clk_pulse
         1 rshift
    loop
    2drop
    \ Send clock
    cont_X W@ 8 and               \ Check mode
    if 4 else 8 then
    0 do 
         clk_pulse 
         1 1 * drop               \ Dummy delay 
    loop                
    ;
    
    \ Send extra clock
    \ ( -- )
    : extraCLK  
    cont_X W@ 8 and               \ Check mode(8bit or 12bit)
    if d12 else d16 then
    0 do 
         clk_pulse 
         1 1 * drop               \ Dummy delay 
    loop                
    ;
    
    \ Display (X.Y)
    \ Cog6 send control-byte and extra clock and Cog0 read A/D conversion data
    \ ( -- )
    : demo
    \ Set data for TouchScrenn 
    12bit diff enablePD setTSC
    
    cs pinhi cs pinout clk pinout din pinout
    c" rdTS" 0 cogx
    
    begin
         penirqm penirqm waitpne                 \ Check touch
    
    \ --- X ---          
         cs pinlo                 \ Activate cs
         \ X
         average 0 do
              \ Send control-byte
              cont_X W@ sendData
         loop
         extraCLK
         aveVal W@ posX W!
         cs pinhi                 \ Deactivate cs
         
    \ --- Y ---          
         cs pinlo                 \ Activate cs   
         \ Y
         average 0 do
              \ Send control-byte
              cont_Y W@ sendData
         loop
         extraCLK
         aveVal W@ posY W!
         cs pinhi                 \ Deactivate cs
         
        ." X:" posX W@ . ." Y:" posY W@ . cr
         
    fkey? swap drop
    until
    0 cogreset
    ;
    
    \ Display time for X-position(sample:8 data) and (X.Y)
    \ ( -- )
    : demo1
    \ Set data for TouchScrenn 
    12bit diff enablePD setTSC
    
    cs pinhi cs pinout clk pinout din pinout
    c" rdTS" 0 cogx
    
    begin
         penirqm penirqm waitpne                 \ Check touch
    
    \ --- X ---  
    cnt COG@        
         cs pinlo                 \ Activate cs
         \ X
         average 0 do
              \ Send control-byte
              cont_X W@ sendData
         loop
         extraCLK
         aveVal W@ posX W!
         cs pinhi                 \ Deactivate cs
    cnt COG@ swap - .     
    \ --- Y ---          
         cs pinlo                 \ Activate cs   
         \ Y
         average 0 do
              \ Send control-byte
              cont_Y W@ sendData
         loop
         extraCLK
         aveVal W@ posY W!
         cs pinhi                 \ Deactivate cs
         
        ." X:" posX W@ . ." Y:" posY W@ . cr
         
    fkey? swap drop
    until
    0 cogreset
    ;
    

    Today is her Birthday.(January 2)
    She is 12 years old.
    600 x 1066 - 75K
  • I wrote code STTS751(Temp sensor).
    STTS751 is SMBus device.
    Prop0 Cog6 ok
    i2c_detect
         0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
    00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- -- <--- STTS751
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- <--- eeprom
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    i2c_device:2
    
    
    Prop0 Cog6 ok
    chipID
    Product ID:0
    ManufactureID:h53
    Revision ID:1
    
    Prop0 Cog6 ok
    disableEVENT RUN 12bit setConfig
    Prop0 Cog6 ok
    rdConfig
    EVENT is enabled
    Conversion mode
    12bits
    Prop0 Cog6 ok
    Temp
    23 .7500degree
    23 .7500degree
    23 .7500degree
    23 .8175degree
    23 .7500degree
    24 .2500degree
    24 .8175degree
    24 .7500degree
    24 .2500degree
    24 .1250degree
    Prop0 Cog6 ok
    
  • Hi,
    I have a GPS module with serial NMA0183 output ( 4800 8n1 ) and a propeller board with propforth installed
    My idea is to read the NMEA data from the propeller serial interface and display it on a LCD, but the serial port is normally used by the terminal session of propforth. Is it possible to detect a NMEA sentence like:
    $GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
    in the input stream and extract and store the data in table for example ?
    Any ideas ?

    Sven
  • Hi Sven98de.
    I don't have idea about GPS.
    I upload SerialCommunication documents to Github.
    https://github.com/caskaz/PropForth5.5
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2016-01-09 13:29
    sven98de wrote: »
    Hi,
    I have a GPS module with serial NMA0183 output ( 4800 8n1 ) and a propeller board with propforth installed
    My idea is to read the NMEA data from the propeller serial interface and display it on a LCD, but the serial port is normally used by the terminal session of propforth. Is it possible to detect a NMEA sentence like:
    $GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
    in the input stream and extract and store the data in table for example ?
    Any ideas ?

    Sven

    Alright then, closest I could help you here is a little bit that I did in Tachyon Forth in this post but have a look through the thread. Basically it involves telling Tachyon that the comma is a delimiter and to essentially post process the string.

  • Sal's serial demo on the old google code page is out of date, but caskaz's material is current.

    The only tricky bit is that the number we supply for baud rate gets multiplied by 4 (to allow a higher max baud rate without reworking the kernel)

    so to have baud 4800 using caskz's code you would change the line to :

    c" 26 27 d1200 serial" 5 cogx
  • I try to learn PID by using 12V-Fan.
    When PID-operating finish, PropForth don't reply prompt.

    I made FET-drive curcuit board and Photo-interupt sensor board.
    I put capatitor in 12V.
    This is caused by hardware or code?
     Prop0 Cog6 ok
     1200 200 50 10 PID_1
    1200 0 1080000 1080000 1080000 2731440
    1200 0 1080000 2160000 0 3256800
    1200 0 1080000 3240000 0 3782080
    1200 0 1080000 4320000 0 4000000
    1200 0 1080000 5400000 0 4000000
    1200 0 1080000 6480000 0 4000000
    1200 628 514800 6994800 -565200 4000000
    1200 846 318600 7313400 -196200 4000000
    1200 846 318600 7632000 0 4000000
    1200 1000 180000 7812000 -138600 4000000
    1200 1122 70200 7882200 -109800 3977120
    1200 1224 -21600 7860600 -91800 3779120
    1200 1390 -171000 7689600 -149400 3390720
    1200 1452 -226800 7462800 -55800 3166400
    1200 1498 -268200 7194600 -41400 2951360
    1200 1536 -302400 6892200 -34200 2734480
    1200 1590 -351000 6541200 -48600 2464480
    1200 1598 -358200 6183000 -7200 2275520
    1200 1608 -367200 5815800 -9000 2078560
    1200 1620 -378000 5437800 -10800 1872640
    1200 1610 -369000 5068800 9000 1711520
    1200 1600 -360000 4708800 9000 1554800
    1200 1586 -347400 4361400 12600 1411600
    1200 1568 -331200 4030200 16200 1283600
    1200 1550 -315000 3715200 16200 1163520
    1200 1518 -286200 3429000 28800 1083120
    1200 1498 -268200 3160800 18000 989440
    1200 1472 -244800 2916000 23400 918160
    1200 1446 -221400 2694600 23400 858320
    1200 1418 -196200 2498400 25200 814320
    1200 1364 -147600 2350800 48600 841840
    1200 1340 -126000 2224800 21600 824640
    1200 1312 -100800 2124000 25200 827120
    1200 1288 -79200 2044800 21600 832720
    1200 1266 -59400 1985400 19800 844240
    1200 1242 -37800 1947600 21600 870000
    1200 1220 -18000 1929600 19800 901680
    1200 1198 1800 1931400 19800 943040
    1200 1180 18000 1949400 16200 984880
    1200 1164 32400 1981800 14400 1030080
    1200 1152 43200 2025000 10800 1073120
    1200 1142 52200 2077200 9000 1116880
    1200 1132 61200 2138400 9000 1165040
    1200 1126 66600 2205000 5400 1208480
    1200 1124 68400 2273400 1800 1245440
    1200 1124 68400 2341800 0 1278720
    1200 1124 68400 2410200 0 1312000
    1200 1124 68400 2478600 0 1345200
    1200 1122 70200 2548800 1800 1383040
    1200 1128 64800 2613600 -5400 1403520
    1200 1136 57600 2671200 -7200 1416880
    1200 1142 52200 2723400 -5400 1431200
    1200 1144 50400 2773800 -1800 1452080
    1200 1146 48600 2822400 -1800 1472000
    1200 1154 41400 2863800 -7200 1477440
    1200 1164 32400 2896200 -9000 1474800
    1200 1174 23400 2919600 -9000 1467840
    1200 1180 18000 2937600 -5400 1465520
    1200 1184 14400 2952000 -3600 1465200
    1200 1188 10800 2962800 -3600 1463040
    1200 1188 10800 2973600 0 1468320
    1200 1188 10800 2984400 0 1473600
    1200 1188 10800 2995200 0 1478800
    1200 1188 10800 3006000 0 1484080
    1200 1188 10800 3016800 0 1489360
    1200 1188 10800 3027600 0 1494560
    1200 1188 10800 3038400 0 1499840
    1200 1188 10800 3049200 0 1505120
    1200 1190 9000 3058200 -1800 1505760
    1200 1192 7200 3065400 -1800 1505600
    1200 1196 3600 3069000 -3600 1500000
    1200 1198 1800 3070800 -1800 1497200
    1200 1200 0 3070800 -1800 1493520
    1200 1204 -3600 3067200 -3600 1484400
    1200 1204 -3600 3063600 0 1482720
    1200 1206 -5400 3058200 -1800 1476400
    1200 1206 -5400 3052800 0 1473760
    1200 1206 -5400 3047400 0 1471120
    1200 1206 -5400 3042000 0 1468480
    1200 1204 -3600 3038400 1800 1470400
    1200 1204 -3600 3034800 0 1468640
    1200 1202 -1800 3033000 1800 1471440
    1200 1202 -1800 3031200 0 1470640
    
    CON:Prop0 Cog0 RESET - last status: 0 ok
    
     <-- No prompt although hitting any key.
    
    fl
    
    {
    PID Excersize (Using 12VDC-FAN 2500rpm)
    PropForth5.5
    
    PWM control curcuit
                          12V      12V
                           |        |
                           |      12VDC-FAN
                          10kohm    |
                   12V     |        D
                    |      |--------G MOSFET 2N7002
                   10kohm  |        S
                    |      C        |
                    |------B        |
                    |      E        |
                    C      |        |      12V
    P0 -----1kohm---B      |        |       |
                    E      |        |      10uF 50V
                    |      |        |       |
                   GND    GND      GND     GND
                 2SC1815(NPN-Tr) 
                    x2
    
    PhotoInterupt Sensor curcuit
    
    3V3                      3V3
     |                        |
    100ohm                   10kohm
     |                        |
     -------        --------------------P1
            |      |
          Anode   Collector
             RPR220
          Cathode Emitter
            |      |
     -------        ----------
     |                        |
    GND                      GND
            
                    
                                 
    2016/01/17 19:39:25
    
    }
    
    \ -------------------------------------------------------
    \ Constants
    \ -------------------------------------------------------
    \ Special register
    h1F8	wconstant ctra
    h1F9	wconstant ctrb
    h1FA	wconstant frqa 
    h1FB	wconstant frqb 
    h1FC	wconstant phsa 
    h1FD	wconstant phsb 
    
    0 wconstant _pwm
    1 wconstant _sense
    d80000 constant pwmMax
    d20000 constant pwmMin
    \ Time during 1-rotation of DC12V-FAN
    variable T
    d900 wconstant scale 
    
    \ -------------------------------------------------------
    \ Variables
    \ -------------------------------------------------------
    
    wvariable Kp
    wvariable Ki
    wvariable Kd
    variable scaleSP
    variable scaleCP
    variable error
    variable errSum
    variable lastErr
    variable dErr
    variable output 
    variable pwmValue
    
    \ -------------------------------------------------------
    \ Main
    \ -------------------------------------------------------
    \ ---------------- Measurement for FAN's RPM -----------------------------------------
    
    \ Get state of _sense
    \ ( -- n1 )  n1:t/f
    : senseState 1 _sense lshift ina COG@ and ;
    
    \ Measure rotation time by PhotoInterrupt sensor
    \ ( -- )  
    : 1rotT
    1 frqa COG!
    1 frqb COG!
    h20000000 _sense or ctra COG!                \ POS detector
    h30000000 _sense or ctrb COG!                \ NEG detector
    
    \ Wait until _sense reach to high
    begin senseState until     
    0 phsb COG!                                  \ Clear phsa (low-pulse counter) 
    begin
         \ Wait until _sense become low
         begin senseState 0= until
         phsa COG@                          \ Read hi-pulse ticks
         0 phsa COG!                        \ Clear phsa (Hi-pulse counter)
         \ Wait until _sense reach to hi
         begin senseState until    
         phsb COG@                          \ Read lo-pulse ticks
         0 phsb COG!                        \ Clear phsb (lo-pulse counter)                                                     
         +                                  \ Hi-pulse + Lo-pulse
         T L!
    0 until 
    ;
    
    \ PID introduction
    \ ( n1 n2 n3 n4 -- ) n1:setpoint n2:kd n3:ki n4:kp 
    : PID_1
    Kp W!
    Ki W!
    Kd W!
    scale * scaleSP L!
    \ 0 error L!    
    0 errSum L!
    0 lasterr L!
    0 T L!
    
    _pwm pinout
    1 frqa COG!
    0 phsa COG!
    \ Set PWM/NCO mode on servo pin       
    _pwm h10000000 or ctra COG!
    0 pwmValue L!
    
    c" 1rotT" 0 cogx
    
    cnt COG@ d4000000 +                          \ cnt + 50msec  
                                           
    begin
         \ Get rpm
         T L@ dup                                \ Get ticks for 1rotation
         if 
              d30 clkfreq u* swap u/ 2 u*        \ (30sec_ticks/1rotation_ticks) * 2 
         then                                     
         scale * scaleCP L!                      \ Get scales current position
         
         scaleSP L@ scaleCP L@ - dup error L!    \ error
         errSum L@ + errSum L!                   \ error sum
         error L@ lastErr L@ - dErr L!           \ dErr
         Kp W@ error L@ * 
         Ki W@ errSum L@ * 
         Kd W@ dErr L@ * + +
         scale W@ /                              \ Get output 
         \ Convert output to pwm
         d80 *                                   \ 1usec
         
         dup 0< 
         if drop 0                               \ If minus, set 0 
         else dup d4000000 > 
              if drop d4000000                   \ If more than d4000000, set d4000000
         thens 
         dup
         \ Set negative value to phsa      
         negate phsa COG!
         pwmValue L!
         error L@ lasterr L@ - dErr L!
         error L@ lasterr L!     
                             scaleSP L@ scale / . scaleCP L@ scale / . error L@ . errSum L@ . dErr L@ . pwmValue L@ . cr
         d4000000 waitcnt                        \ cnt + 50msec
         0 phsa COG! 
         fkey? swap drop 
    until 
    drop       
    0 cogreset   
    0 ctra COG!
    ;
    
    \ 1200 200 50 10 PID_1
    
  • I'm going to write code of PID-control.
    Drawing graph by sending data from PropForth to Processing.


  • I wrote code for HT16K33-24.

  • hey Kaz! Pretty cool!

    Did you ever figure out the random issue with your PID demo?

    One thing I ran across (yet again) that causes random reset:

    If my diagnostic code (running on cog 6) prints too fast, it will choke the serial link.

    That is, if I am printing a page worth of characters to the terminal screen, but I don't leave enough time between pages, eventually something will crash. I had a delay of 10 ms (10 delms) between screens and it would randomly crash after several hours. I changed the diagnostic to display once every second, and it now runs for days and hasn't crashed again.

  • caskazcaskaz Posts: 957
    edited 2016-02-10 04:18
    Hi prof_braino.
    What is random reset?
    You try PID_test.f inside PID1_Exercize on github?
  • Tried position-control by PID.
    Position get from encoder by connecting motor and it.


  • caskazcaskaz Posts: 957
    edited 2016-03-18 03:54
    Reading rotary-encoder by i2c
    fl
    
    {
    PropForth 5.5(DevKernel)
    
    i2c_encoder by using 8bit I/O Expander(PCF8574)
    2016/03/18 12:50:01
    
         
    
    Propeller      PCF8574 module
    3.3V     -------  Vcc        Vcc
    GND      -------  GND         |
    P29(SDA) -------  SDA      10kohm
    P28(SCL) -------  SCL         |  A -----------
                      P0   -----------| Rotary    |
                              GND ----|  Encorder |
                      P1   -----------|           |
                  A2=A1=A0=GND   |  B -----------
                               10kohm
                                  |
                                 Vcc
                                 
         prev  current status
           0     0      stop           0
           0     1      CW             1
           0     2      CCW           -1
           0     3      invalid(=stop) 0
           4     0      CCW           -1
           4     1      stop           0
           4     2      invalid(=stop) 0
           4     3      CW             1
           8     0      CW             1
           8     1      invalid(=stop) 0
           8     2      stop           0
           8     3      CCW           -1
           C     0      invalid(=stop) 0
           C     1      CCW           -1
           C     2      CW             1
           C     3      stop           0
                                 
    }
    
    \ =========================================================================== 
    \ Constants 
    \ =========================================================================== 
    \ Slave addres h20 for PCF8574
    h40 wconstant PCF8574
    \ A2=A1=A0=0
    0 wconstant addr
    
    variable encoder_tbl -4 allot 
    0 l, 1 l, -1 l, 0 l, 
    -1 l, 0 l, 0 l, 1 l, 
    1 l, 0 l, 0 l, -1 l, 
    0 l, -1 l, 1 l, 0 l, 
    
    \ =========================================================================== 
    \ Variables 
    \ =========================================================================== 
    variable pos
    wvariable prev
    
    \ =========================================================================== 
    \ Main 
    \ =========================================================================== 
    \ --- i2c -------------------------------------------------------------------
    : err_msg ." I2C error" ;
    \ If error, print message
    \ ( n1 -- )   n1:t/f
    : err? if err_msg cr then ;
    
    \ Start i2c-commnication 
    \ This also can use SMBus device.
    \ ( -- )
    lockdict create _eestart forthentry
    $C_a_lxasm w, h122  h113  1- tuck - h9 lshift or here W@ alignl h10 lshift or l,
    z1[ixnW l, z1[ixnX l, z2WyP[U l, z20iPak l, z3ryPW0 l, z1bixnW l, z2WyP[V l, z20iPak l,
    z3ryPW0 l, z1bixnX l, z1SV01X l, zl0 l, zCW l, zW0000 l, zG0000 l,
    freedict
    
    \ Re-defined RepeatedStart
    \ ( -- )
    : Sr _eestart ;
    
    \ Stop i2c-commnication 
    \ ( -- )
    : _eestop
    _scli     \ Release scl 
    _sdai     \ Release sda
    ;
    
    \ _eewrite ( c1 -- t/f ) write c1 to the eeprom, true if there was an error
    \ Received acknowledge from i2c-device during scl is high
    \ scl/sda use pull-up resistor at hi
    \ clock:400kHz
    lockdict create _eewrite forthentry
    $C_a_lxasm w, h12C  h113  1- tuck - h9 lshift or here W@ alignl h10 lshift or l,
    z2WyPW8 l, z1YVPQ0 l, z1rixnd l, z1Sy\C] l, z1[ixne l, z1Sy\C] l, z1bixne l, zfyPO1 l,
    z3[yP[K l, z1[ixnd l, z1Sy\C] l, z1[ixne l, z1Sy\C] l, z1YF\Nl l, z1viPR6 l, z1bixne l,
    z1Sy\C] l, z1bixnd l, z1SV01X l, z2WyPc7 l, z20iPik l, z3ryPb0 l, z1SV000 l, zW0000 l,
    zG0000 l,
    freedict
    
    \ _eeread ( t/f -- c1 ) flag should be true is this is the last read
    \ scl/sda use pull-up resistor at hi
    \ clock:400kHz
    lockdict create _eeread forthentry
    $C_a_lxasm w, h12D  h113  1- tuck - h9 lshift or here W@ alignl h10 lshift or l,
    z2WiPZB l, z2WyPO0 l, z1[ixne l, z2WyPj8 l, z1Sy\Ka l, z1[ixnf l, z1Sy\Ka l, z1XF\Vl l,
    znyPO1 l, z1bixnf l, z3[yPnN l, z26VPW0 l, z1rixne l, z1Sy\Ka l, z1[ixnf l, z1Sy\Ka l,
    z1bixnf l, z1bixne l, z1Sy\Ka l, z1SV01X l, z2WyPc9 l, z20iPik l, z3ryPb0 l, z1SV000 l,
    zW0000 l, zG0000 l,
    freedict
    
    \ Read ports of PCF8574
    \ ( -- n1 )    n1:data
    : rd_PCF8574
    \ Start I2C 
    _eestart
    \ Write slave address[rd], then receive Acknowledge-bit(ACK:Lo  NACK:Hi) 
    PCF8574 addr 1 lshift or 1 or _eewrite       \ ( t/f ) 
    -1 _eeread                                   \ ( t/f n1 )
    \ Stop I2C
    _eestop
    swap err?                                    \ ( n1 )    
    ;
     
    \ ---------------------------------------------------------------------------
    
    \ Count up/down encorder's position
    \ ( -- )
    : i2c_encorder
    0 pos L!
    0 prev W!
    begin                  
         rd_PCF8574            
         3 and dup                                                         
         prev W@ or 4* encoder_tbl + L@               \ Get value 
         pos L@ + pos L!                              \ Update pos
         2 lshift prev W!                             \ Save prev to shift 2bit left 
    0 until
    ;
    
    \ Display position with RotaryEncoder without click 
    \ ( -- )
    : test1 
    c" i2c_encorder" 0 cogx
    5 delms                                           \ Delay because operating 'encorder' takes a little time.
    begin pos L@ . d10 delms fkey? swap drop until
    0 cogreset 
    ;
    
    
  • Reading 12-KeyPad by i2c
    fl
    
    {                       
    PropForth 5.5(DevKernel)
    
    i2c_12-KeyPad by using 8bit I/O ExpanderPCAL9554BPW)
    Using i2c_utility_0.4.1.f 
    2016/03/21 23:27:26
    
    Propeller        PCAL9554BPW       
    SDA     ------     SDA     
    SCL     ------     SCL                    -------------------
                        P0 ------------------| Row1              |
                        P1 ------------------| Row2    12-KeyPad |
                        P2 ------------------| Row3              |
                        P3 ------------------| Column1           |
                        P4 ------------------| Column2           |
                        P5 ------------------| Column3           |
                        P6 ------------------| Column4           |
                        A0 --- GND            -------------------
                        A1 --- GND            Row[1..3]:output
                        A2 --- GND            column[1..4]:input
    }
    \ =========================================================================== 
    \ Constants 
    \ =========================================================================== 
    \ Slave addres h20 for PCAL9554BPW      
    h40 wconstant PCAL9554BPW
    
    \ Top pin for 12KeyPad
    0 wconstant KeyPad
    hF KeyPad 3 + lshift constant mKeyPad
    d4000000 constant 50msec
    
    \ register  
    0 wconstant InPort
    1 wconstant OutPort
    3 wconstant Config
    h43 wconstant Pull_u/d_enb
    h44 wconstant Pull_u/d_sel
    
    wvariable key_table -2 allot 
    d10 c, 1 c, 4 c, 7 c, 0 c, 2 c, 5 c, 8 c, d12 c, 3 c, 6 c, 9 c, 
    
    \ =========================================================================== 
    \ Variables 
    \ =========================================================================== 
    wvariable swState        \ current sw-code
    wvariable lastswState    \ last sw-code
    wvariable debounce
    variable lastDebounceTime
    wvariable char     
    variable buffer 
    wvariable pointer  
    
    \ =========================================================================== 
    \ Main 
    \ =========================================================================== 
    
    \ Set initial
    \ ( -- )
    : init_sw
    \ Set initial values
    0 swState W!             
    0 lastDebounceTime L!
    0 lastswState W!         \ Switch state when no pushing switch
    0 debounce W!
    ;
    
    \ Read [Column1..Column4] to drive each Row
    \ ( -- ) 
    : swScan
    init_sw
    begin
         \ Read current sw and check if pushed or released
         mKeyPad InPort PCAL9554BPW i2c_rd and 3 rshift   \ 4bit-data(Column[1..4])
         dup lastswState W@ <>                      
         if
              \ If sw is under debouncong
              debounce W@ 0=
              if
                   cnt COG@ lastDebounceTime L!           
                   1 debounce W!
              then
         else
              0 debounce W!
         then
         
         debounce W@
         if
              cnt COG@ lastDebounceTime L@ - 50msec >    
              if
                   \ Update current swState and lastswState
                   dup
                   swState W! lastswState W!
                   \ Break loop 
                   1   
              else
                   drop
                   \ Continue loop
                   0
              then
         else
              drop
              \ Break loop
              1
         then
    until
    ;
    
    \ Get 1 character
    \ ( -- )
    : get1char
    \ [P6 P5 P4 P3]=Intput  [P2 P1 P0]=output
    h78 Config PCAL9554BPW i2c_wr
    \ Set pulldn resistor [P6..P3]
    0 Pull_u/d_sel PCAL9554BPW i2c_wr
    h78 Pull_u/d_enb PCAL9554BPW i2c_wr
    
    begin
         \ Scan 3Rows 
         1 KeyPad lshift
         3 0 do
              dup 
              OutPort PCAL9554BPW i2c_wr    \ Activate each Row-pin
              \ Read Column-data 
              swScan           
              swState W@ dup            
              if                                
                   1 rshift 
                   dup 4 = if drop 3 then   \ [1 2 4 8] -> [0 1 2 3] 
                   i 4 * +                  
                   key_table + C@ char W!   \ Get key-code
                   \ Wait until releasing sw
                   begin swScan swState W@ 0= until
              else
                   drop                          
              then 
              1 lshift                      \ Next Row pin
         loop 
         drop                   
    0 until
    ;
    
    \ Clear charcter buffer
    : charClr d255 char W! ;
    
    \ Print 1 character from 12-KeyPad to TeraTerm
    \ ( -- )
    : demo1
    charClr                                 \ Clear char buffer
    c" get1char" 0 cogx
    
    begin                                                    
         char W@ dup d255 <>                \ Check if there is key-input
         if                                                                 
              . cr                          \ Print 1 character
              charClr                       \ Clear char buffer
         else
              drop
         then
         fkey? swap drop
    until
    0 cogreset
    ;
    
    \ Print number to enter charcters from 12-KeyPad
    \ ( -- )
    : demo2
    0 buffer L!
    0 pointer W!
    charClr
    c" get1char" 0 cogx
    
    begin
         char W@ dup d255 <>                          \ Key input?
         if
              dup d10 <>                              \ Ignore "Cancel" key
              if
                   dup d12 =                          \ Check "Enter"key
                   if
                        drop
                        cr buffer L@ . cr
                        0 buffer L!
                        0 pointer W!
                        charClr 
                   else
                        dup h30 + emit                \ Print key input
                        pointer W@ 0=
                        if
                             buffer L!
                             1 pointer W!
                        else
                             \ Calculate number
                             buffer L@  d10 *                         
                             + buffer L!
                             pointer W@ 1+ pointer W!     
                        then
                        charClr
                   then
              else
                   drop
              then
         else
              drop
         then
         fkey? swap drop
    until
    0 cogreset
    ;
    
    
  • caskazcaskaz Posts: 957
    edited 2016-04-05 00:47
    Reading JoyStick by i2c
    fl
    
    {                       
    PropForth 5.5(DevKernel)
    
    i2c_JoyStick by PCF8591
    Using i2c_utility_0.4.1.f 
    PCF8591_0.3.f
    2016/04/05 9:41:37
    
            PCF8591                           Propeller
              AN0   ------- JoyStick Y-axis
              AN1   ------- JoyStick X-axis
              AN2   
              AN3   
              A0    ------- GND
              A1    ------- GND
              A2    ------- GND
              SDA   ------------------------  SDA
              SCL   ------------------------  SCL
              OSC   
              EXT   ------- GND (Selected internal OSC)
              AGND  ------- GND
              VREF  ------- 3.3V
              AOUT  
              VDD   ------- 3.3V
    }
    
    \ =========================================================================== 
    \ Main 
    \ =========================================================================== 
    
    : JoyStick_demo 
    ." X" 9 emit ." Y" cr
    begin
         0 h44 PCF8591 std_i2c_wr      \ Write contril byte
         3 PCF8591_rd                  \ Get A/D-value 
         . 9 emit . cr drop            \ drop previous A/D-value
         d200 delms
         fkey? swap drop
    until
    ;
    
Sign In or Register to comment.