Shop OBEX P1 Docs P2 Docs Learn Events
Two PropBASIC questions.... — Parallax Forums

Two PropBASIC questions....

JPTallmanJPTallman Posts: 7
edited 2011-12-05 22:58 in Propeller 1
I'm using PropBASIC with BST. Whenever I try to make a FOR...NEXT loop, it tells me that my variable (index, indx, idx, x, whatever I name it) is an "invalid parameter".

Also, I'd like to program on my MacBook Pro (I use my mom's laptop to program instead), but it can't find the port that I plug the Propeller into. When I try to choose a port manually, it does not come up with any ports.

Any help with either issue would be greatly appreciated. Thanks!!

Comments

  • JPTallmanJPTallman Posts: 7
    edited 2011-11-26 21:00
    DEVICE P8X32A, XTAL1, PLL16X
    XIN 5_000_000

    PROGRAM Start

    Start:
    FOR idx = 1 TO 10
    TOGGLE 0
    PAUSE 250
    NEXT


    GOTO Start

    END


    That's an example of what I'll code, and this is what it tells me:

    Screen shot 2011-11-26 at 10.58.28 PM.png
  • GerryKeelyGerryKeely Posts: 12
    edited 2011-11-26 22:40
    JPTallman wrote: »
    DEVICE P8X32A, XTAL1, PLL16X
    XIN 5_000_000
    idx VAR LONG <========= add this line, you must declare idx as a variable
    PROGRAM Start

    Start:
    FOR idx = 1 TO 10
    TOGGLE 0
    PAUSE 250
    NEXT


    GOTO Start

    END


    That's an example of what I'll code, and this is what it tells me:

    Screen shot 2011-11-26 at 10.58.28 PM.png
  • JPTallmanJPTallman Posts: 7
    edited 2011-11-27 12:27
    Thank you!

    Oh! Another thing I was wondering. Is there any way to do PWM commands using PropBASIC? I know that you can with BS2, but I haven't found the command in PropBASIC.
  • simonlsimonl Posts: 866
    edited 2011-11-28 00:01
    There is a PULSOUT command, so I guess that could be used with a loop?
  • BeanBean Posts: 8,129
    edited 2011-11-28 04:29
    PWM is best created using the hardware counters.
    Here is an example using an LED on pin 15 (change for your setup).
    ' PWM Example
    DEVICE P8X32A,XTAL1,PLL16X
    FREQ 80_000_000
    
    LED PIN 15 OUTPUT
    
    i    VAR LONG
    temp VAR LONG
    
    PROGRAM Main
    
    Main:
      COUNTERA 48, LED ' 48=DUTY mode
      DO
        FOR i = 0 TO 255
          temp = i << 24 ' Scale up to 32 bits
          FRQA = temp
          PAUSE 10
        NEXT 
      LOOP  
    END
    
    

    Bean
  • JPTallmanJPTallman Posts: 7
    edited 2011-12-04 19:34
    Is there a way to do this with multiple pins simultaneously?
  • BeanBean Posts: 8,129
    edited 2011-12-05 03:57
    JPTallman wrote: »
    Is there a way to do this with multiple pins simultaneously?

    Each cog has two counters (countera and counterb) so for two pins just use countera for one and counterb for the other.

    For more than two pins, you need to make additional TASKs to do it with the hardware counters. Let me know if you need more than two and I experiment with it.

    Bean
  • JPTallmanJPTallman Posts: 7
    edited 2011-12-05 22:29
    The goal is to be able to use all 24 pins I've got hooked up to LED channels. Thanks for your all your help!!
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-05 22:58
    You could translate this Spin / Assembly PWM driver from the ObEx to PropBasic. It's mostly assembly so you could just copy that.
Sign In or Register to comment.