Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic and QuickStart board — Parallax Forums

PropBasic and QuickStart board

Below is a base program for usage with the QuickStart (QS) board. Basically it is, or will be a menu driven program, meaning touch a pad, from a menu selection list, on the LCD display, and it starts a specific function.

The below program, touching of the pad just fires up an associated LED. I guess that is the best starting point for the base program. Now I have to acquire the necessary peripherals. Probably would be nice to get an appropriate LCD, something that could display the eight pad selections, and only use a couple of pins. My count of the available usable pins is seven, maybe use P27 and P28 as the I2C bus. I consider P0-7 and P16-23, as permanently assigned pins.

Just as a reminder I am using Linux and Geany+PropBasic+BSTC setup, somewhat cumbersome, but it gets the job done. Once openspin can deal with "@@@" functionality, then I will replace BSTC with openspin. But hopefully Propeller IDE, by then, will have PropBasic integrated, and working with "@@@".

Ray
' QS_base.pbas
' Feb 3,2016
'
' Start of a base system using the touch pads.
''''''''''''''''''''
DEVICE P8X32A, XTAL1, PLL16X
FREQ 80_000_000

' Pin assign for touch pads.
' Multiple assignment is for usage with the existing lib.
T_pads1 PIN 0..7 INPUT
T_pads2 PIN 0..7 INPUT
T_pads3 PIN 0..7 INPUT
T_pad0 PIN 0 INPUT
T_pad1 PIN 1 INPUT
T_pad2 PIN 2 INPUT
T_pad3 PIN 3 INPUT
T_pad4 PIN 4 INPUT
T_pad5 PIN 5 INPUT
T_pad6 PIN 6 INPUT
T_pad7 PIN 7 INPUT 


''''''''''''''''''''
PROGRAM Start
''''''''''''''''''''
LOAD "/home/ray/propbasic/Tch_pads_lib.pbas"

' This sets up a forever loop for touch pad usage.
' The action is around the touch pads, which will
' be driving specific functions. In this case it
' is working an LED.
Start:
	DO
		Chk_pads
		IF T_pad0 <> 1 THEN
			HIGH 16
			PAUSE 1000
			LOW 16
		ELSEIF T_pad1 <> 1 THEN
			HIGH 17
			PAUSE 1000
			LOW 17
		ELSEIF T_pad2 <> 1 THEN
			HIGH 18
			PAUSE 1000
			LOW 18
		ELSEIF T_pad3 <> 1 THEN
			HIGH 19
			PAUSE 1000
			LOW 19
		ELSEIF T_pad4 <> 1 THEN
			HIGH 20
			PAUSE 1000
			LOW 20
		ELSEIF T_pad5 <> 1 THEN
			HIGH 21
			PAUSE 1000
			LOW 21
		ELSEIF T_pad6 <> 1 THEN
			HIGH 22
			PAUSE 1000
			LOW 22
		ELSEIF T_pad7 <> 1 THEN
			HIGH 23
			PAUSE 1000
			LOW 23
		ENDIF
	LOOP

END

''''''''''''''''''''
' SUBs FUNCs TASKS
'
«1

Comments

  • What am I missing here? I thought I would try putting the touch pad do...loop into a task and do a cogstart on it. What I was expecting is the touch pads to be functional, meaning you touch one and the LED lights up.

    So far the program compiles, but I do not get any activity on the touch pads. I guess I need an explanation from one of the experts. My logic seems to be valid, but I am definitely missing something.

    Ray
    ' QS_base.pbas
    ' Feb 3,2016
    '
    ' Start of a base system using the touch pads.
    ''''''''''''''''''''
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    STACK 8
    
    ' Pin assign for touch pads.
    ' Multiple assignment is for usage with the existing lib.
    T_pads1 PIN 0..7 INPUT
    T_pads2 PIN 0..7 INPUT
    T_pads3 PIN 0..7 INPUT
    T_pad0 PIN 0 INPUT
    T_pad1 PIN 1 INPUT
    T_pad2 PIN 2 INPUT
    T_pad3 PIN 3 INPUT
    T_pad4 PIN 4 INPUT
    T_pad5 PIN 5 INPUT
    T_pad6 PIN 6 INPUT
    T_pad7 PIN 7 INPUT
     
    
    T_pads TASK
    
    ''''''''''''''''''''
    PROGRAM Start
    ''''''''''''''''''''
    'LOAD "/home/ray/propbasic/Tch_pads_lib.pbas"
    
    ' This sets up a forever loop for touch pad usage.
    ' The action is around the touch pads, which will
    ' be driving specific functions. In this case it
    ' is working an LED.
    Start:
    COGSTART T_pads
    DO
    
    LOOP
    
    END
    
    ''''''''''''''''''''
    ' SUBs FUNCs TASKS
    '
    TASK T_pads
    LOAD "/home/ray/propbasic/Tch_pads_lib.pbas"
    	DO
    		Chk_pads
    		IF T_pad0 <> 1 THEN
    			HIGH 16
    			PAUSE 1000
    			LOW 16
    		ELSEIF T_pad1 <> 1 THEN
    			HIGH 17
    			PAUSE 1000
    			LOW 17
    		ELSEIF T_pad2 <> 1 THEN
    			HIGH 18
    			PAUSE 1000
    			LOW 18
    		ELSEIF T_pad3 <> 1 THEN
    			HIGH 19
    			PAUSE 1000
    			LOW 19
    		ELSEIF T_pad4 <> 1 THEN
    			HIGH 20
    			PAUSE 1000
    			LOW 20
    		ELSEIF T_pad5 <> 1 THEN
    			HIGH 21
    			PAUSE 1000
    			LOW 21
    		ELSEIF T_pad6 <> 1 THEN
    			HIGH 22
    			PAUSE 1000
    			LOW 22
    		ELSEIF T_pad7 <> 1 THEN
    			HIGH 23
    			PAUSE 1000
    			LOW 23
    		ENDIF
    	LOOP
    ENDTASK
    
  • Doing some further investigation as to why QS_base.pbas compiles buts does not run as expected, I was looking at the below code as Propeller IDE sees it, and what the PropBasic .spin code looks like.

    First, the .spin file produced by PropBasic, it looks like it has added three 'SUB Chk_pads', not sure why that would be occurring or does it even have a final result on the .spin file.

    Second, in the .spin file that Propeller IDE works with, I do not see any functional code for the TASK and I do not see any functional code for the 'SUB Chk_pads'. Now, I do not even try to pretend that I know anything about PASM, but that does look suspicious to me. It could be that the code is in there, but I just do not recognize it. Should I be suspect about using the PropBasic COGSTART a TASK? Or what do I have to really do to get my program to work in a TASK?

    Ray

    Propeller IDE:
    ''  *** COMPILED WITH PropBasic VERSION 00.01.42  Aug 25, 2013 ***
                                                                 '' QS_base.pbas
                                                                 '' Feb 3,2016
                                                                 ''
                                                                 '' Start of a base system using the touch pads.
                                                                 '''''''''''''''''''''
    
    
    CON                                                          'DEVICE P8X32A, XTAL1, PLL16X
      _ClkMode = XTAL1 + PLL16X                                 
    
      _XInFreq =   5000000                                       'FREQ 80_000_000
    
    
    
                                                                 '' Pin assign for touch pads.
                                                                 '' Multiple assignment is for usage with the existing lib.
    
    ' T_pads1 PIN 0..7 INPUT                                     'T_pads1 PIN 0..7 INPUT
    
    ' T_pads2 PIN 0..7 INPUT                                     'T_pads2 PIN 0..7 INPUT
    
    ' T_pads3 PIN 0..7 INPUT                                     'T_pads3 PIN 0..7 INPUT
    
    ' T_pad0 PIN 0 INPUT                                         'T_pad0 PIN 0 INPUT
    
    ' T_pad1 PIN 1 INPUT                                         'T_pad1 PIN 1 INPUT
    
    ' T_pad2 PIN 2 INPUT                                         'T_pad2 PIN 2 INPUT
    
    ' T_pad3 PIN 3 INPUT                                         'T_pad3 PIN 3 INPUT
    
    ' T_pad4 PIN 4 INPUT                                         'T_pad4 PIN 4 INPUT
    
    ' T_pad5 PIN 5 INPUT                                         'T_pad5 PIN 5 INPUT
    
    ' T_pad6 PIN 6 INPUT                                         'T_pad6 PIN 6 INPUT
    
    ' T_pad7 PIN 7 INPUT                                         'T_pad7 PIN 7 INPUT
    
    
    
    OBJ T_pads: "T_pads.spin"                                    'T_pads TASK
    
    
                                                                 '''''''''''''''''''''
    PUB __Program | __VarsPtr                                    'PROGRAM Start
      __VarsPtr := 0                                            
      T_pads_COG:=T_pads.Init(@__DataStart, 0)                  
      CogInit(0, @__Init, __VarsPtr)                            
                                                                
    DAT                                                         
                      org           0                           
    __Init                                                      
    __RAM                                                       
                      mov           dira,__InitDirA             
                      mov           outa,__InitOutA             
                      jmp           #Start                      
    
                                                                 '''''''''''''''''''''
                                                                 ''LOAD "/home/ray/propbasic/Tch_pads_lib.pbas"
    
                                                                 '' This sets up a forever loop for touch pad usage.
                                                                 '' The action is around the touch pads, which will
                                                                 '' be driving specific functions. In this case it
                                                                 '' is working an LED.
    Start                                                        'Start:
    
                      mov           __temp1,T_pads_COG           'COGSTART T_pads
                      add           __temp1,#8                  
                      coginit       __temp1                     
    
    __DO_1                                                       'DO
    
    
                      jmp           #__DO_1                      'LOOP
    __LOOP_1                                                    
    
    
                      mov           __temp1,#0                   'END
                      waitpne       __temp1,__temp1             
    
    
                                                                 '''''''''''''''''''''
                                                                 '' SUBs FUNCs TASKS
                                                                 ''
    
    '**********************************************************************
    __InitDirA       LONG %00000000_00000000_00000000_00000000
    __InitOutA       LONG %00000000_00000000_00000000_00000000
    T_pad0           LONG 1 << 0
    T_pad1           LONG 1 << 1
    T_pad2           LONG 1 << 2
    T_pad3           LONG 1 << 3
    T_pad4           LONG 1 << 4
    T_pad5           LONG 1 << 5
    T_pad6           LONG 1 << 6
    T_pad7           LONG 1 << 7
    T_pads3         
    T_pads1         
    T_pads2          LONG 255 << 0
    _FREQ            LONG 80000000
    
    ____STRING_adr   LONG 0
    __clkfreq_adr    LONG 0
    T_pads_COG       LONG 0-0
    
    __remainder
    __temp1          RES 1
    __temp2          RES 1
    __temp3          RES 1
    __temp4          RES 1
    __temp5          RES 1
    __param1         RES 1
    __param2         RES 1
    __param3         RES 1
    __param4         RES 1
    __paramcnt       RES 1
    
    FIT 492
    
    CON
      LSBFIRST                         = 0
      MSBFIRST                         = 1
      MSBPRE                           = 0
      LSBPRE                           = 1
      MSBPOST                          = 2
      LSBPOST                          = 3
    
    ' TASK T_pads                                                'TASK T_pads
    
    
    
    
    DAT
    __DATASTART
    
    
    PropBasic:
    1  ' QS_base.pbas
       2  ' Feb 3,2016
       3  '
       4  ' Start of a base system using the touch pads.
       5  ''''''''''''''''''''
       6  DEVICE P8X32A, XTAL1, PLL16X
       7  FREQ 80_000_000
       8  STACK 8
       9  
      10  ' Pin assign for touch pads.
      11  ' Multiple assignment is for usage with the existing lib.
      12  
      13  T_pads1 PIN 0..7 INPUT
      14  T_pads2 PIN 0..7 INPUT
      15  T_pads3 PIN 0..7 INPUT
      16  T_pad0 PIN 0 INPUT
      17  T_pad1 PIN 1 INPUT
      18  T_pad2 PIN 2 INPUT
      19  T_pad3 PIN 3 INPUT
      20  T_pad4 PIN 4 INPUT
      21  T_pad5 PIN 5 INPUT
      22  T_pad6 PIN 6 INPUT
      23  T_pad7 PIN 7 INPUT
      24  
      25  
      26  T_pads TASK
      27  
      28  ''''''''''''''''''''
      29  PROGRAM Start
      30  ''''''''''''''''''''
      31  'LOAD "/home/ray/propbasic/Tch_pads_lib.pbas"
      32  
      33  ' This sets up a forever loop for touch pad usage.
      34  ' The action is around the touch pads, which will
      35  ' be driving specific functions. In this case it
      36  ' is working an LED.
      37  Start:
      38  COGSTART T_pads
      39  DO
      40  
      41  LOOP
      42  
      43  END
      44  
      45  ''''''''''''''''''''
      46  ' SUBs FUNCs TASKS
      47  '
      48  
      49  TASK T_pads
      50  
      51  LOAD "/home/ray/propbasic/Tch_pads_lib.pbas"
      52  ' Tch_pads_lib.pbas
      53  
      54  Chk_Pads SUB 0
      55  
      56  ''''''''''''''''''''''''''
      57  ' Check the touch pad for a touch.
      58  ' Chk_pad pad_number
      59  '  Usage - Chk_pads
      60  SUB Chk_pads
      61  	'OUTPUT __param1 ' Set pin to output
      62  	HIGH T_pads1 
      63  	HIGH T_pads2 
      64  	HIGH T_pads3  ' Charge pin
      65  	INPUT T_pads1 
      66  	INPUT T_pads2 
      67  	INPUT T_pads3  ' Switch pin capacitance
      68  	PAUSE 30       ' Wait the delay time
      69  ENDSUB
      70  '''''''''''''''''''
      71  
      72  
      73  	DO
      74  		Chk_pads
      75  		IF T_pad0 <> 1 THEN
      76  			HIGH 16
      77  			PAUSE 1000
      78  			LOW 16
      79  		ELSEIF T_pad1 <> 1 THEN
      80  			HIGH 17
      81  			PAUSE 1000
      82  			LOW 17
      83  		ELSEIF T_pad2 <> 1 THEN
      84  			HIGH 18
      85  			PAUSE 1000
      86  			LOW 18
      87  		ELSEIF T_pad3 <> 1 THEN
      88  			HIGH 19
      89  			PAUSE 1000
      90  			LOW 19
      91  		ELSEIF T_pad4 <> 1 THEN
      92  			HIGH 20
      93  			PAUSE 1000
      94  			LOW 20
      95  		ELSEIF T_pad5 <> 1 THEN
      96  			HIGH 21
      97  			PAUSE 1000
      98  			LOW 21
      99  		ELSEIF T_pad6 <> 1 THEN
     100  			HIGH 22
     101  			PAUSE 1000
     102  			LOW 22
     103  		ELSEIF T_pad7 <> 1 THEN
     104  			HIGH 23
     105  			PAUSE 1000
     106  			LOW 23
     107  		ENDIF
     108  	LOOP
     109  ENDTASK
     110  
     111  
     112  ' Tch_pads_lib.pbas
     113  
     114  Chk_Pads SUB 0
     115  
     116  ''''''''''''''''''''''''''
     117  ' Check the touch pad for a touch.
     118  ' Chk_pad pad_number
     119  '  Usage - Chk_pads
     120  SUB Chk_pads
     121  	'OUTPUT __param1 ' Set pin to output
     122  	HIGH T_pads1 
     123  	HIGH T_pads2 
     124  	HIGH T_pads3  ' Charge pin
     125  	INPUT T_pads1 
     126  	INPUT T_pads2 
     127  	INPUT T_pads3  ' Switch pin capacitance
     128  	PAUSE 30       ' Wait the delay time
     129  ENDSUB
     130  '''''''''''''''''''
     131  
     132  ' Tch_pads_lib.pbas
     133  
     134  Chk_Pads SUB 0
     135  
     136  ''''''''''''''''''''''''''
     137  ' Check the touch pad for a touch.
     138  ' Chk_pad pad_number
     139  '  Usage - Chk_pads
     140  SUB Chk_pads
     141  	'OUTPUT __param1 ' Set pin to output
     142  	HIGH T_pads1 
     143  	HIGH T_pads2 
     144  	HIGH T_pads3  ' Charge pin
     145  	INPUT T_pads1 
     146  	INPUT T_pads2 
     147  	INPUT T_pads3  ' Switch pin capacitance
     148  	PAUSE 30       ' Wait the delay time
     149  ENDSUB
     150  '''''''''''''''''''
     151  
    
    PropBasic Version 00.01.42 Aug 25, 2013
    Finished Compile. 151 Lines Read, 244 Lines Generated,  0 Warnings, 0 Errors.
    
    
    ------------------
    (program exited with code: 0)
    Press return to continue
    
  • BeanBean Posts: 8,129
    TASK code is in a seperate file. If you look in "T_pads.spin" you will see the TASK code.

    Bean
  • Thanks Bean, but you can just about guess what my next question is. If PropBasic produces a separate .spin file of the TASK code, how do you get BSTC or Propeller IDE to run QS_base.spin with T_pads.spin included? Do I have to insert an INCLUDE command, for the future T_pads.spin, in the QS_base.pbas program just to have it be able to run the program as one unit?

    Ray
  • BeanBean Posts: 8,129
    It is included with this line
    OBJ T_pads: "T_pads.spin"                                    'T_pads TASK
    

    Bean
  • It is included with this line

    OBJ T_pads: "T_pads.spin" 'T_pads TASK
    And the plot thickens. I missed that line in the QS_base.spin, so that takes PropBasic of the hook. But the problem still remains, the program does not run as expected.

    As I mentioned earlier, I have a Linux system that I have Geany+PropBasic+BSTC, and Propeller IDE setup. Now the finger can be pointed at Propeller IDE and/or BSTC, why aren't they including T_pads.spin when I do a run?

    I have QS_base.spin and T_pads.spin in the same directory(folder) as BSTC, so why doesn't BSTC come back with an error telling me that it could not find T_pads.spin, same goes for Propeller IDE, no errors are posted. I am almost tempted to go to the other thread and start pushing for PE-BASIC. Get rid of this crazy scenario.

    This also means that I should set up in a Windows environment, hopefully I would get ahead of this crazy scenario, unless of course the same thing occurs with that setup. I can see now why only the very committed users are actually using PropBasic in a BST IDE setup. And here I was trying to move away from Windows.

    More to come, I am not done yet.

    Ray
  • Following with great interest.
  • This is starting feel like some kind of endurance or tolerance test. I setup on a Windows 7 64 bit box, downloaded PropBasic 1.42, and BSTC for Windows, I already have Geany for Windows installed.

    So, I run my test1.pbas with PropBasic, so far so good. Run test1.spin with BSTC : '0 - Unable to locate top file 0'. Since BSTC is not cooperating, I will not be able to do any LMM stuff.

    Propeller IDE seems to like test1.spin, it runs and lights up P16 on the QuickStart board. But if I test out any LMM stuff, it will complain and throw up errors. Now I will try my QS_base.pbas file and see what happens.

    Yes, I am now really considering lobbying for PE-BASIC, maybe if PE-BASIC had a scripting option, and you were not totally locked into the interpreter...

    Ray
  • jmgjmg Posts: 15,148
    Rsadeika wrote: »
    Yes, I am now really considering lobbying for PE-BASIC, maybe if PE-BASIC had a scripting option, and you were not totally locked into the interpreter...
    My understanding is these are different solutions, so PropBASIC is preferable in many cases.
    Others appreciate your patience, if that helps :)


  • Ray,

    Why not take ViewPort for a "spin". It's all I use. I copied my link from your other thread so it should be good. If not, you can find the original over there.

    https://www.dropbox.com/s/2sonsg7n9yzj0oc/viewport482.zip?dl=0
  • Only niggle that I ever come across is that I frequently find that I have to do a Prop reset prior to loading updated code.
  • Thanks for the suggestion Mickster, but I am not going to hook up with anther dead ender.

    Sorry folks, but I just hit a brick wall with PropBasic. After installing a setup on my Windows 7 box, and running the QS_base.spin with Propeller IDE, which compiles with no errors, but there is no activity on the QuickStart board. So, the same thing is occurring with a Windows setup. I double checked to make sure that the spin file had 'OBJ T_pads : "T_pads.spin"', yes , it was there. For some reason Propeller IDE is not including it in the QS_base.spin program, when compiled, but the worst part, it is not throwing up an error.

    What I might try is the hard core option, do everything from the command line, and batch files, no no no, I have to go and lie down for a while before...

    Ray
  • Rsadeika wrote: »
    It is included with this line

    OBJ T_pads: "T_pads.spin" 'T_pads TASK
    And the plot thickens. I missed that line in the QS_base.spin, so that takes PropBasic of the hook. But the problem still remains, the program does not run as expected.

    As I mentioned earlier, I have a Linux system that I have Geany+PropBasic+BSTC, and Propeller IDE setup. Now the finger can be pointed at Propeller IDE and/or BSTC, why aren't they including T_pads.spin when I do a run?

    I have QS_base.spin and T_pads.spin in the same directory(folder) as BSTC, so why doesn't BSTC come back with an error telling me that it could not find T_pads.spin, same goes for Propeller IDE, no errors are posted.

    Not sure how you can blame PropellerIDE... BTW: I was able to build your code with PropellerIDE (as well as SimpleIDE. Both use OpenSpin and compiled the resultant .spin files without issue as there is no '@@@' within the PropBasic output in this case). I don't see the problem as PropellerIDE not including/compiling the T_pads.spin source. It actually does! As a test, I added some code to a second version of T_pads.spin to increase its size and changed the the OBJ line in the main source to point to that version. On compile, the size of the binary changes with any additions or deletions that I make to T_pads.spin file, so yes its binary is included within the overall program binary... You just need to debug why your loop is not executing.

    dgately
  • dgatelydgately Posts: 1,621
    edited 2016-02-04 20:47
    As a test, I modded Tch_pads_lib.pbas to:
    ' Tch_pads_lib.pbas
    Chk_Pads SUB 0
    ''''''''''''''''''''''''''
    '...
    SUB Chk_pads
    	'OUTPUT __param1 ' Set pin to output
    	HIGH T_pads1 
    	HIGH T_pads2 
    	HIGH T_pads3    ' Charge pin
    	INPUT T_pads1 
    	INPUT T_pads2 
    	INPUT T_pads3  ' Switch pin capacitance
    	PAUSE 30       ' Wait the delay time
    
            HIGH 22        ' blink one of the QuickStart's LEDS to test that this code gets executed
            PAUSE 200
            LOW 22
    ENDSUB
    

    And, the Quickstart's LED on P22 blinks each time when Chk_pads gets called from the main program. It seems that the code is getting executed.

    dgately
  • I wanted to see if I could find out what the problem is with the last bit of code that I had. It seems like either there is a bit of quirkiness with PropBasic or some undocumented no nos.

    I had created a SUB called Chk_pads, which when added in the beginning of the T_pads TASK, it compiles without any errors and when run on the QS board, the touch of the pads does not respond. When you take the code out of the SUB and add it to start of the DO...LOOP, like the program below, then the touch pads become active.

    I also added an LMM to the PROGRAM Start command just to see if there were any side affects from that. The program seems to run fine when used with BSTC, but it will not work with Propeller IDE.

    Now I am wondering if I can move LED on/off that is associated with a touch pad out of the TASK and try do that within the Start:. I am guessing that I cannot because of this global verses local code and variable stuff. That means that when you do a TASK you may have to have some sort of special setup to have communication between the COGSTARTed TASK and the main code, just guessing here. Have to do some more fooling around.

    Ray


    ' LMM_base_t1.pbas
    '
    '
    '
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    T_pads1 PIN 0..7 INPUT
    T_pads2 PIN 0..7 INPUT
    T_pads3 PIN 0..7 INPUT
    T_pad0 PIN 0 INPUT
    T_pad1 PIN 1 INPUT
    T_pad2 PIN 2 INPUT
    T_pad3 PIN 3 INPUT
    T_pad4 PIN 4 INPUT
    T_pad5 PIN 5 INPUT
    T_pad6 PIN 6 INPUT
    T_pad7 PIN 7 INPUT
    
    
    'Chk_Pads SUB 0
    
    
    T_pads TASK
    
    PROGRAM Start LMM
    
    
    Start:
    	COGSTART T_pads
    	DO
    
    	LOOP
    
    END
    
    
    ' SUBs FUNCs TASKS
    '
    TASK T_pads
    
    	DO
    		HIGH T_pads1 
    		HIGH T_pads2 
    		HIGH T_pads3  ' Charge pin
    		INPUT T_pads1 
    		INPUT T_pads2 
    		INPUT T_pads3  ' Switch pin capacitance
    		PAUSE 30       ' Wait the delay time
    		IF T_pad0 <> 1 THEN
    			HIGH 16
    			PAUSE 1000
    			LOW 16
    		ELSEIF T_pad1 <> 1 THEN
    			HIGH 17
    			PAUSE 1000
    			LOW 17
    		ELSEIF T_pad2 <> 1 THEN
    			HIGH 18
    			PAUSE 1000
    			LOW 18
    		ELSEIF T_pad3 <> 1 THEN
    			HIGH 19
    			PAUSE 1000
    			LOW 19
    		ELSEIF T_pad4 <> 1 THEN
    			HIGH 20
    			PAUSE 1000
    			LOW 20
    		ELSEIF T_pad5 <> 1 THEN
    			HIGH 21
    			PAUSE 1000
    			LOW 21
    		ELSEIF T_pad6 <> 1 THEN
    			HIGH 22
    			PAUSE 1000
    			LOW 22
    		ELSEIF T_pad7 <> 1 THEN
    			HIGH 23
    			PAUSE 1000
    			LOW 23
    		ENDIF
    	LOOP
    	
    ENDTASK
    
    
  • LMM is pretty much transparent in my experience - the code can be much larger and is much slower (5x? - SWAG). If you want to pass data between cogs/tasks you have to use a wrlong/rdlong or wrword/rdword or wrbyte/rdbyte mechanism. Data visible to all cogs has to reside in hub and get copied to local long vars in each desired cog. I think PropellerIDE use openspin which does not support @@@ which your test code does generate. See lines 28 and 35 in the very partial listing below. I have a QS somewhere and will try to find it later today or tomorrow and see if i can help.
    |===========================================================================|
    Objects : -
    test
      |
      +-T_pads.spin
    
    Object Address : 0010 : Object Name : test
    Object Address : 017C : Object Name : T_pads.spin
    
    Binary Image Information :
    PBASE : 0010
    VBASE : 0424
    DBASE : 042C
    PCURR : 0164
    DCURR : 0434
    |===========================================================================|
    |===========================================================================|
    Object test
    Object Base is 0010
    |===========================================================================|
    Object Constants
    |===========================================================================|
    Constant _ClkMode = 00000408 (1032)
    Constant _XInFreq = 004C4B40 (5000000)
    Constant LSBFIRST = 00000000 (0)
    Constant MSBFIRST = 00000001 (1)
    Constant MSBPRE = 00000000 (0)
    Constant LSBPRE = 00000001 (1)
    Constant MSBPOST = 00000002 (2)
    Constant LSBPOST = 00000003 (3)
    |===========================================================================|
    Object DAT Blocks
    |===========================================================================|
    001C(0000)             |                   org           0                           
    001C(0000)             | __Init                                                      
    001C(0000)             | __RAM                                                       
    001C(0000) 38 EC BF A0 |                   mov           dira,__InitDirA             
    0020(0001) 39 E8 BF A0 |                   mov           outa,__InitOutA             
    0024(0002) 26 4C BC 08 |                   rdlong        __PC,__PC                   
    0028(0003) 2C 00 00 00 |                   long          @@@Start                    
    002C(0004)             | Start                                                        'Start:
    002C(0004) 46 8E BC A0 |                   mov           __temp1,T_pads_COG           '        COGSTART T_pads
    0030(0005) 08 8E FC 80 |                   add           __temp1,#8                  
    0034(0006) 02 8E 7C 0C |                   coginit       __temp1                     
    0038(0007)             | __DO_1                                                       '        DO
    0038(0007) 26 4C BC 08 |                   rdlong        __PC,__PC                    '        LOOP
    003C(0008) 38 00 00 00 |                   long          @@@__DO_1                   
    0040(0009)             | __LOOP_1                                                    
    0040(0009) 00 8E FC A0 |                   mov           __temp1,#0                   'END
    
    *****************************************************************************************************************
    *************** Metric crapload (28 kB) of listing deleted due to forum code length restriction*******************
    *****************************************************************************************************************
    
  • LMM is pretty much transparent in my experience - the code can be much larger and is much slower (5x? - SWAG).
    I think I have to address this, it has come up before, the thing about LMM mode, that is. I do not know about everybody else, but I anticipate some of the programs that I would be coming up with would be on the larger size.

    My experience, when using PropGCC, having a lot of code overhead built in, I expected the programs to be memory hungry. The reason I am testing PropBasic is to see if similar programs that I have done in PropGCC, can be much smaller, in memory usage, with the same functionality, when using PropBasic.

    I guess a quick example, the SD driver, in PropGCC I believe the code size is ~11KB, in Spin the size ~9KB, in PropBasic ???, plus, if there was one, would it be, what 100x faster.

    Which brings up the point of "5x", actually what does that really mean, in real terms? If that is such limiting factor, maybe the Propeller should be running in the FREQ 100_000_000 mode, that would negate that "5x" handicap :-). And I am sure that that would be a very visible attribute.

    Now, back to the subject at hand, if I were to pursue using PropBasic, which has not been determined just yet, I would be pushing Bean to come up with a CMM equivalent.

    I guess everybody must be thinking, what the heck kind of program is he thinking about. Actually if you take an ActivityBot and create a program that uses the servos, SD, Ping, Compass, IR, ADC, maybe throw in an XBee, just for starters. I suppose for PropBasic, it would be a breeze.

    Now I am really thinking that maybe PropBasic is not the right choice, only because that most of the drivers do not exist, and than, after all is said and done, the program would still would not be able to run because it ran out of memory space. But it would really be fast, if it did fit in the memory available.

    Ray
  • jmgjmg Posts: 15,148
    Rsadeika wrote: »
    The reason I am testing PropBasic is to see if similar programs that I have done in PropGCC, can be much smaller, in memory usage, with the same functionality, when using PropBasic.

    I guess a quick example, the SD driver, in PropGCC I believe the code size is ~11KB, in Spin the size ~9KB, in PropBasic ???, plus, if there was one, would it be, what 100x faster.
    One fundamental edge PropBASIC has over PropGCC, is
    PropGCC is somewhat forced to use a limited-register model.
    How much that helps, will depend on the program.

    Any language forced into interpreted mode will be slower, so the real question for speed is, what can be packed into a COG in native PASM ?
  • Which brings up the point of "5x", actually what does that really mean, in real terms? If that is such limiting factor, maybe the Propeller should be running in the FREQ 100_000_000 mode, that would negate that "5x" handicap :-). And I am sure that that would be a very visible attribute.
    Sorry, Ray, I didn't intend on stating such a specific number. My point is that LMM is somewhat slower and for time sensitive routines, that slower speed does make a difference. I just benchmarked code that receives 8K bytes of serial data then calcs a CRC32 of the data. Native code gets me 230400 bps and a 30ms CRC loop, the LMM version breaks at anything faster than 38400 and the CRC loop takes 172 ms. Oddly enough I am running it at 100_000_000! :-) Oh, also, the binaries are native 10188 , LMM 10596 but that's not a fully direct, objective comparison as some of that is occupied by another task which I left as native.

    -Mike
  • BeanBean Posts: 8,129
    -Mike, those numbers sound about right.

    The LMM core that runs in the COG will runs code 4x slower, but IT needs to loop and then it loses the HUB window. So it ends up being about 5x slower for code with no jumps. Jumps are really slow because two HUB reads are required (one to read the instruction, then one to read the address that follows it).

    As I've said, most of my programs use LMM for the main code because it is usually larger. Then native mode for all the TASKs because they are usually small and sometimes need to run fast (video output for example).

    This works really well for me, and if you look at the PE-BASIC source code (PE-BASIC is written in PropBASIC) you will see that you can write quite a large program in LMM.

    CMM ??? Is that the 8-bit token thing ??? If so, I don't see implementing that in PropBASIC.

    Bean
  • In my previous post, I had moved the T_pads functionality into a COGSTART TASK. I keep looking at the code, and I am finding it hard to figure out how to get the COGed TASK to work for me from within the main program, especially as it applies to this program.

    What I would like to do is have the T_pads running all the time, which I have done so far, by putting into a COGed TASK, but how do get it to do some meaningful work, from within the main code. Like I mentioned, maybe moving the LED on/off association to the main area would be a good start.

    I still do not know for sure the concept of using the HUB space as the device between a COG and main program for the this bit of code. Any help would be appreciated.

    Ray
  • kwinnkwinn Posts: 8,697
    Have the COGed task read one or two variables in hub ram. Using one variable would allow you to set a blink frequency, two variables would allow setting frequency and pulse width or on/off times for the led.
  • I guess it works, but the concept of moving the variable data around, I guess you would have to be very careful, or you will run into some big hidden problems.

    Well any way, I guess I got the one touch pad to behave, so now I can move the other ones to the main. After I am done with that then I will have the touch pads active, waiting for a touch, and I can build from there. Open for code improvement.

    Are there any drivers for a servo, a high speed one, just like they use for the ActivityBot? Does anybody know how to go about creating the driver? I think the next experiment should be, attach a servo to the QuickStart board, and then use the T_pads to control the servo. This would be a good real example of touch pads and servo control, if that is possible with PropBASIC of course.

    Ray
    ' LMM_base_t1.pbas
    ' Feb 7,2016
    '
    '
    
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    T_pads1 PIN 0..7 INPUT
    T_pads2 PIN 0..7 INPUT
    T_pads3 PIN 0..7 INPUT
    T_pad0 PIN 0 INPUT
    T_pad1 PIN 1 INPUT
    T_pad2 PIN 2 INPUT
    T_pad3 PIN 3 INPUT
    T_pad4 PIN 4 INPUT
    T_pad5 PIN 5 INPUT
    T_pad6 PIN 6 INPUT
    T_pad7 PIN 7 INPUT
    
    
    'Chk_Pads SUB 0
    Chk_Pads HUB LONG
    
    T_pads TASK
    
    PROGRAM Start LMM
    
    
    Start:
    	COGSTART T_pads
    	temp2 VAR LONG
    	
    	DO
    	'            HUB     VAR
    		RDLONG Chk_pads,temp2
    		IF temp2 = 1 THEN
    			HIGH 16
    			PAUSE 1000
    			LOW 16
    			temp2 = 0     ' Set Chk_pads HUB back to 0
    			WRLONG Chk_pads,temp2
    			'         HUB    VAR
    		ENDIF
    	LOOP
    
    END
    
    
    ' SUBs FUNCs TASKS
    '
    TASK T_pads
    	temp1 VAR LONG
    	DO
    		HIGH T_pads1 
    		HIGH T_pads2 
    		HIGH T_pads3  ' Charge pin
    		INPUT T_pads1 
    		INPUT T_pads2 
    		INPUT T_pads3  ' Switch pin capacitance
    		PAUSE 30       ' Wait the delay time
    		
    		
    		IF T_pad0 <> 1 THEN
    			temp1 = 1
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 1
    		'             HUB     VAR
    		ELSEIF T_pad1 <> 1 THEN
    			HIGH 17
    			PAUSE 1000
    			LOW 17
    		ELSEIF T_pad2 <> 1 THEN
    			HIGH 18
    			PAUSE 1000
    			LOW 18
    		ELSEIF T_pad3 <> 1 THEN
    			HIGH 19
    			PAUSE 1000
    			LOW 19
    		ELSEIF T_pad4 <> 1 THEN
    			HIGH 20
    			PAUSE 1000
    			LOW 20
    		ELSEIF T_pad5 <> 1 THEN
    			HIGH 21
    			PAUSE 1000
    			LOW 21
    		ELSEIF T_pad6 <> 1 THEN
    			HIGH 22
    			PAUSE 1000
    			LOW 22
    		ELSEIF T_pad7 <> 1 THEN
    			HIGH 23
    			PAUSE 1000
    			LOW 23
    		ENDIF
    		
    	LOOP
    	
    ENDTASK
    
    
  • Cleaned up the code a bit, seems like the T_pads TASK is working as expected, and now you can add functionality to the touch pads from within the main(Start:).

    Ray
    ' LMM_base_t1.pbas
    ' Feb 7,2016
    '
    ' Set up touch pad TASK.
    ' Associate some functionality.
    '
    ''''''''''''''''''''
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    ''''''''''''''''''''
    
    ''''''''''''''''''''
    T_pads1 PIN 0..7 INPUT
    T_pads2 PIN 0..7 INPUT
    T_pads3 PIN 0..7 INPUT
    T_pad0 PIN 0 INPUT
    T_pad1 PIN 1 INPUT
    T_pad2 PIN 2 INPUT
    T_pad3 PIN 3 INPUT
    T_pad4 PIN 4 INPUT
    T_pad5 PIN 5 INPUT
    T_pad6 PIN 6 INPUT
    T_pad7 PIN 7 INPUT
    ''''''''''''''''''''
    
    
    'Chk_Pads SUB 0
    Chk_Pads HUB LONG
    
    T_pads TASK
    
    ''''''''''''''''''''
    PROGRAM Start LMM  ' Main is LMM mode
    ''''''''''''''''''''
    
    ''''''''''''''''''''
    Start:
    	COGSTART T_pads  ' Start T_pads in a COG
    	temp2 VAR LONG
    
    ' Associate a function with a touch pad, in this case LED on/off.
    ' Using only two pads, Pad0 and Pad1.	
    	DO
    	'            HUB     VAR
    		RDLONG Chk_pads,temp2
    		IF temp2 = 10 THEN   ' Pad0
    			HIGH 16
    			PAUSE 1000
    			LOW 16
    		ELSEIF temp2 = 11 THEN  ' Pad1
    			HIGH 17
    			PAUSE 1000
    			LOW 17
    		ELSE
    			temp2 = 0     ' Set Chk_pads HUB back to 0
    			WRLONG Chk_pads,temp2
    			'         HUB    VAR
    		ENDIF
    			temp2 = 0     ' Set Chk_pads HUB back to 0
    			WRLONG Chk_pads,temp2
    			'         HUB    VAR
    	LOOP
    
    END
    ''''''''''''''''''''
    
    ' SUBs FUNCs TASKS
    '
    ''''''''''''''''''''
    TASK T_pads
    	temp1 VAR LONG
    	DO
    	' Check the touch pad for activity.
    		HIGH T_pads1 
    		HIGH T_pads2 
    		HIGH T_pads3  ' Charge pin
    		INPUT T_pads1 
    		INPUT T_pads2 
    		INPUT T_pads3  ' Switch pin capacitance
    		PAUSE 30       ' Wait the delay time
    		' Associate the pad taouch.		
    		IF T_pad0 <> 1 THEN
    			temp1 = 10   ' Pad0
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 10
    		'             HUB     VAR
    		ELSEIF T_pad1 <> 1 THEN
    			temp1 = 11   ' Pad1
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 11
    		'             HUB     VAR			
    		ELSEIF T_pad2 <> 1 THEN
    			temp1 = 12   ' Pad2
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 12
    		'             HUB     VAR
    		ELSEIF T_pad3 <> 1 THEN
    			temp1 = 13   ' Pad3
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 13
    		'             HUB     VAR
    		ELSEIF T_pad4 <> 1 THEN
    			temp1 = 14   ' Pad4
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 14
    		'             HUB     VAR
    		ELSEIF T_pad5 <> 1 THEN
    			temp1 = 15   ' Pad5
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 15
    		'             HUB     VAR
    		ELSEIF T_pad6 <> 1 THEN
    			temp1 = 16   ' Pad6
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 16
    		'             HUB     VAR
    		ELSEIF T_pad7 <> 1 THEN
    			temp1 = 17   ' Pad7
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 17
    		'             HUB     VAR
    		ENDIF
    		
    	LOOP
    	
    ENDTASK
    ''''''''''''''''''''
    
  • I added some code to the main part of the program, just to make sure that all the pads are working as expected. I am getting some strange things occurring.

    I have two QuickStart Rev A boards and a Human Interface Board (HIB), that I use to test the program. First, when I run the below program in LMM mode, some of the pads are not responsive, especially pads P4,P5,P6,and P7. When I remove the LMM mode then they seem to be more responsive.

    Now when I add the HIB, the LED associated with pad P2, starts to blink, that is not part of the code. So, I guess I am wondering why the program acts differently when it is using LMM and a COGSTARTed TASK. The second part is, why is it working in a strange way when the HIB is added.


    Ray

    ' LMM_base_t1.pbas
    ' Feb 7,2016
    '
    ' Set up touch pad TASK.
    ' Associate some functionality.
    '
    ''''''''''''''''''''
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    ''''''''''''''''''''
    
    ''''''''''''''''''''
    T_pads1 PIN 0..7 INPUT
    T_pads2 PIN 0..7 INPUT
    T_pads3 PIN 0..7 INPUT
    T_pad0 PIN 0 INPUT
    T_pad1 PIN 1 INPUT
    T_pad2 PIN 2 INPUT
    T_pad3 PIN 3 INPUT
    T_pad4 PIN 4 INPUT
    T_pad5 PIN 5 INPUT
    T_pad6 PIN 6 INPUT
    T_pad7 PIN 7 INPUT
    ''''''''''''''''''''
    
    
    'Chk_Pads SUB 0
    Chk_Pads HUB LONG
    
    T_pads TASK
    
    ''''''''''''''''''''
    PROGRAM Start 
    ''''''''''''''''''''
    
    ''''''''''''''''''''
    Start:
    	COGSTART T_pads  ' Start T_pads in a COG
    	temp2 VAR LONG
    
    ' Associate a function with a touch pad, in this case LED on/off.
    ' Using only two pads, Pad0 and Pad1.	
    	DO
    	'            HUB     VAR
    		RDLONG Chk_pads,temp2
    		IF temp2 = 10 THEN   ' Pad0
    			HIGH 16
    			PAUSE 1000
    			LOW 16
    		ELSEIF temp2 = 11 THEN  ' Pad1
    			HIGH 17
    			PAUSE 1000
    			LOW 17
    		ELSEIF temp2 = 12 THEN  ' Pad2
    			HIGH 18
    			PAUSE 1000
    			LOW 18
    		ELSEIF temp2 = 13 THEN  ' Pad3
    			HIGH 19
    			PAUSE 1000
    			LOW 19
    		ELSEIF temp2 = 14 THEN  ' Pad4
    			HIGH 20
    			PAUSE 1000
    			LOW 20
    		ELSEIF temp2 = 15 THEN  ' Pad5
    			HIGH 21
    			PAUSE 1000
    			LOW 21
    		ELSEIF temp2 = 16 THEN  ' Pad6
    			HIGH 22
    			PAUSE 1000
    			LOW 22
    		ELSEIF temp2 = 17 THEN  ' Pad7
    			HIGH 23
    			PAUSE 1000
    			LOW 23		
    		ELSE
    			temp2 = 0     ' Set Chk_pads HUB back to 0
    			WRLONG Chk_pads,temp2
    			'         HUB    VAR
    		ENDIF
    			temp2 = 0     ' Set Chk_pads HUB back to 0
    			WRLONG Chk_pads,temp2
    			'         HUB    VAR
    	LOOP
    
    END
    ''''''''''''''''''''
    
    ' SUBs FUNCs TASKS
    '
    ''''''''''''''''''''
    TASK T_pads
    	temp1 VAR LONG
    	DO
    	' Check the touch pad for activity.
    		HIGH T_pads1 
    		HIGH T_pads2 
    		HIGH T_pads3  ' Charge pin
    		INPUT T_pads1 
    		INPUT T_pads2 
    		INPUT T_pads3  ' Switch pin capacitance
    		PAUSE 30       ' Wait the delay time
    		' Associate the pad taouch.		
    		IF T_pad0 <> 1 THEN
    			temp1 = 10   ' Pad0
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 10
    		'             HUB     VAR
    		ELSEIF T_pad1 <> 1 THEN
    			temp1 = 11   ' Pad1
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 11
    		'             HUB     VAR			
    		ELSEIF T_pad2 <> 1 THEN
    			temp1 = 12   ' Pad2
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 12
    		'             HUB     VAR
    		ELSEIF T_pad3 <> 1 THEN
    			temp1 = 13   ' Pad3
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 13
    		'             HUB     VAR
    		ELSEIF T_pad4 <> 1 THEN
    			temp1 = 14   ' Pad4
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 14
    		'             HUB     VAR
    		ELSEIF T_pad5 <> 1 THEN
    			temp1 = 15   ' Pad5
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 15
    		'             HUB     VAR
    		ELSEIF T_pad6 <> 1 THEN
    			temp1 = 16   ' Pad6
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 16
    		'             HUB     VAR
    		ELSEIF T_pad7 <> 1 THEN
    			temp1 = 17   ' Pad7
    			WRLONG Chk_pads, temp1 ' Set Chk_pads HUB to 17
    		'             HUB     VAR
    		ENDIF
    		
    	LOOP
    	
    ENDTASK
    ''''''''''''''''''''
    
  • Just trying to follow on my phone. Can't help with the question but why not eliminate the redundancy?

    If Temp2 > 9 Then Temp2 = Temp2 + 6
    High Temp2.......
  • Also, it looks like one of the Temp2 = 0 and subsequent hub writes is redundant.
  • Never dealt with the Quickstart before so I'm not sure exactly how to handle the pads but it looks like you set the pins high to charge but then immediately set them to inputs. Shouldn't there be a charging delay there?
  • I did some quick tests, again, when there is no LMM, the QuickStart touch pads work as expected. When I add the Program Start: LMM, then only half of of the touch pads work, in a consistent manner. When I have Program Start: LMM and I make COGSTART T_pads LMM, then none of the touch pads work.

    A quick assessment, when you have an LMM program trying to work with a COGSTARTed TASK, timing takes a beating? I thought that when I made both an LMM, then it would be better, but it was even worse. So, I guess you have to be very careful how you intend to use an LMM program with a COGSTARTed TASK. But, I probably do not know what I speak of.

    Ray
  • pmrobertpmrobert Posts: 669
    edited 2016-02-10 14:28
    Each cog, whether it's running LMM or native, is completely independent of the others and they only are able to interact by shared hub variables or other external-to-all-cogs methods. The LMM code in that cog only runs slower than native but is not limited to the 496 instruction limit. I'm pretty sure your problem is that you're charging all the pads then turning them into inputs then reading them sequentially - but, due to LMM executing ~5x slower, the charge dissipates by the time the code gets to the higher numbered pads. Try making them all high then, for each pin/pad change direction to input, pausing 30 ms or whatever, then reading. I know that's clear as mud but hope you get my drift. typing on phones is not my forte for sure.. :-)
Sign In or Register to comment.