sweep effect with PropBasic
LMS
Posts: 19
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
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.
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.
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