Shop OBEX P1 Docs P2 Docs Learn Events
sweep effect with PropBasic — Parallax Forums

sweep effect with PropBasic

LMSLMS Posts: 19
edited 2021-10-30 21:28 in General Discussion

I am looking for advice or an example using propBasic to generate sign wave values with a center value being 128 and plus to minus 50, not looking for high speed but just to change values over around 2 seconds so it would be a slow sweep, perfect would be a to smooth the peaks out too so that it would form very rounded waves. I will send this out to an 8Bit DAC

I want to stick this in a cog as TASK that just sits running forever.

Sorry I am not sure how to best describe it so I have attached an image.

70 - 128 - 178

Comments

  • Hi

    Show us what you've tried so far and maybe we can help.
    It seems like you want a slowly changing voltage to be out put on a D/A set by using 8 prop pins.
    The voltage is NOT a sin wave ( if it were the prop has a table of sin values built in) so how do you want to generate that? You could make a lookup table. How frequently do you want to send values to the D/A?

    Dave

  • LMSLMS Posts: 19
    edited 2021-10-31 15:47

    @tritonium said:
    Hi

    Show us what you've tried so far and maybe we can help.
    It seems like you want a slowly changing voltage to be out put on a D/A set by using 8 prop pins.
    The voltage is NOT a sin wave ( if it were the prop has a table of sin values built in) so how do you want to generate that? You could make a lookup table. How frequently do you want to send values to the D/A?

    Dave

    Hi Dave, thanks for responding,

    I have only got as far as toggling the pins so far and Just grasping PropBasic and finding it really fast and nice so I do not want to bother with spin at all. Updated ( also reading/writing to the PCF8574 )

    seams that are very few propbasic users here.

    Anyway, using 8 pins directly could work for a DAC but I also use a i2C PCF8574, I am just not sure how to go about the math part. SIN I will look at, A lookup table would be fixed I suppose.

    Not looking for anyone to give me the code, Just a pointer or two to what way would be best using propbasic, of course a code snipet would be welcome.

    I would be happy even if I could generate data going to the terminal, this I suspect could be done with a loop that has some internal scaling so when nearing the peaks of the wave, the values are decremented/incremented.

    It is the type of thing where I can draw what I need, but not sure how to program it.

    Ultimately I would like to be able to adjust the frequency and pitch of the wave but not by much, I am assuming that I could add some delay in the loop and some peak values as adjustments.

    It is an application to drive an applicator that will give smooth swirls to a type of rudder in liquids at variable rates.

  • JonnyMacJonnyMac Posts: 9,159
    edited 2021-10-31 19:33

    Since you're using an external DAC, does that mean you're using a P1? If that's the case, there is a sine table in ROM that you can access.

    I don't use PropBASIC, but I have done this in Spin (hopefully, this won't be hard to translate). The sine_table() method returns a signed 16-bit value; you'll need to scale this.

    pri scale_angle(angle)
    
    '' Converts angle (0_0 to 359_9) to 13-bit value for sine_table()
    '' -- angle specified in 0.1 degree units
    
      return (angle // 360_0) * 8192 / 360_0
    
    
    pri sine_table(sa) | flags
    
    '' Sine of the 13-bit scaled angle
    '' -- 0 to 359.95 degrees as $0000 to $1FFF
    '' -- returns -65535 (-1) to 65535 (+1)
    
      flags := (sa >> 11) & %11                                     ' extract quadrant info
    
      if (flags & %01)                                              ' if quadrant 2|4, negate angle
        -sa
    
      result := word[(sa | $7000) << 1]                             ' read from sine table
    
      if (flags & %10)                                              ' if quadrant 3|4, negate value  
        -result
    
  • @JonnyMac said:
    Since you're using an external DAC, does that mean you're using a P1? If that's the case, there is a sine table in ROM that you can access.

    Yes Sir, thank you for your reply, I am using a P1

  • Hi

    If you haven't already read this you might find it interesting
    https://forums.parallax.com/discussion/118611/download-propbasic-here-00-01-14-last-version-for-bst/p1
    Here is some propbasic code to use a task to output values for a sawtooth shape from a table to the serial port that can be viewed in a terminal using the programming serial port. You will have to replace the print routines with your I2C code- propbasic has functions for that.
    Hope it helps

    Dave

Sign In or Register to comment.