Hi, the DSP Freq module looks very handy... I'm away from the office and scope so cant check on hardware but...
What determines the base frequency in your example, is it the 1ms delay, i.e. how fast you Generate the 'tick'
I would like to use the component as a quick way to output a pulse train.
I can't quite see how you assign the output from the DSP buffer to an actual output pin or another part of the system?
If I assigned the pulse to an output (or PWM channel??) would it continue to run whilst the program went off to other things like sample inputs and update displays.
This DSP stuff is all a bit new! But if I can get on top of it, it could solve quite a few tasks for me!
J.
DSP Frequency, Setting the output, Change base Frequency
Moderator: Benj
- Jay Dee
- Posts: 398
- Joined: Tue Aug 18, 2009 6:42 pm
- Has thanked: 121 times
- Been thanked: 154 times
- Contact:
DSP Frequency, Setting the output, Change base Frequency
- Attachments
-
- Pulse_Generator.fcfx
- PulseGen
- (13.91 KiB) Downloaded 341 times
- Jay Dee
- Posts: 398
- Joined: Tue Aug 18, 2009 6:42 pm
- Has thanked: 121 times
- Been thanked: 154 times
- Contact:
Re: DSP Frequency, Setting the output, Change base Frequency
Hi Guys,
MIAC, PIC, FC 7.2.
I have a simple DSP Frequency FC program attached.
The DSP frequency generator is run by an Interrupt and we get a nice neat squarewave output on the bench.
I would like to have the value from an AV input, control the SquareWave output frequency on the fly ????
Any ideas?
You can manually change the Period offset and get a change in output frequency but I cant see how to change this value in FC on the fly... Cheers, J.
For anyone following along, my interpretation of the DSPFreqGen properties for a squarewave are as follows.
- SquareWave output is a fixed 50% Duty.
Amplitude: This is the High Value for the Square Wave
OffSet: This is the Lo Value for the Square wave.
- The DSP output value will oscillate between these two discrete values.
Period: The number of data points in one period the Wave form (full cycle)
- I suspect you need a decent number of data points to do useful manipulation of the waveform but I'm not achieving much manipulation yet!
Phase: You can start the output waveform a given number of samples into the waveform
- This phase offset only applies to the first cycle of the wave form, its not a symmetry shift that is applied to all iterations of the waveform. To do that use the 'Pulse' Type of waveform.
Data: This is an auto-generated list of values, based on the number of samples set by the period parameter.
- You don't manually edit this list, for a squarewave its just 50/50 split, with the High Value repeated for the first half of the samples, followed by the Low values.
Period Offset: This seems to allow you to change the frequency and is the control of most interest....
- I can find a way to change this on the fly yet.
MIAC, PIC, FC 7.2.
I have a simple DSP Frequency FC program attached.
The DSP frequency generator is run by an Interrupt and we get a nice neat squarewave output on the bench.
I would like to have the value from an AV input, control the SquareWave output frequency on the fly ????
Any ideas?
You can manually change the Period offset and get a change in output frequency but I cant see how to change this value in FC on the fly... Cheers, J.
For anyone following along, my interpretation of the DSPFreqGen properties for a squarewave are as follows.
- SquareWave output is a fixed 50% Duty.
Amplitude: This is the High Value for the Square Wave
OffSet: This is the Lo Value for the Square wave.
- The DSP output value will oscillate between these two discrete values.
Period: The number of data points in one period the Wave form (full cycle)
- I suspect you need a decent number of data points to do useful manipulation of the waveform but I'm not achieving much manipulation yet!
Phase: You can start the output waveform a given number of samples into the waveform
- This phase offset only applies to the first cycle of the wave form, its not a symmetry shift that is applied to all iterations of the waveform. To do that use the 'Pulse' Type of waveform.
Data: This is an auto-generated list of values, based on the number of samples set by the period parameter.
- You don't manually edit this list, for a squarewave its just 50/50 split, with the High Value repeated for the first half of the samples, followed by the Low values.
Period Offset: This seems to allow you to change the frequency and is the control of most interest....
- I can find a way to change this on the fly yet.
- Jay Dee
- Posts: 398
- Joined: Tue Aug 18, 2009 6:42 pm
- Has thanked: 121 times
- Been thanked: 154 times
- Contact:
Re: DSP Frequency, Setting the output, Change base Frequency
Ah.. so I found the rather obvious Period Offset function in the DSPFreqGen Macros.
Attached is a very crude example of the system cycling through a few set values for the Period Offset and its tested on hardware. I hope to find some more time for this tomorrow so will post any further progress.
But in the mean time if anyone have any experience with the DSP waveform functions, please chip in any advice.
J.
Attached is a very crude example of the system cycling through a few set values for the Period Offset and its tested on hardware. I hope to find some more time for this tomorrow so will post any further progress.
But in the mean time if anyone have any experience with the DSP waveform functions, please chip in any advice.
J.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: DSP Frequency, Setting the output, Change base Frequency
Hello Jay,
Sorry for the delay in replying. Let me see if I can help you out.
Sorry for the delay in replying. Let me see if I can help you out.
Yes if you perform the DSP tick as part of an interrupt then essentially it will run in the background allowing you to do other things.If I assigned the pulse to an output (or PWM channel??) would it continue to run whilst the program went off to other things like sample inputs and update displays.
This DSP stuff is all a bit new! But if I can get on top of it, it could solve quite a few tasks for me!
Your latest program looks good. However the input to the SetOffset function is a Floating point value which might allow you to vary the output frequency even more. Here is a quick example where I do a floating point calculation to give you more adjustable range.I would like to have the value from an AV input, control the SquareWave output frequency on the fly ????
Any ideas?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Jay Dee
- Posts: 398
- Joined: Tue Aug 18, 2009 6:42 pm
- Has thanked: 121 times
- Been thanked: 154 times
- Contact:
Re: DSP Frequency, Setting the output, Change base Frequency
Ha ha, Yeah Thanks Ben,
My brain kicked in over night and I came to the same conclusion.
Attached is a simple working example for anyone following along.
A Variable pot on input 1, will vary the output frequency between roughly 0.5Hz to 150Hz. Again some of my learning process...
My FC programs DSP uses the 'Tick' method, so each time the DSP routine is evaluated (triggered by the interrupt TMR0) it processes one sample in the defined waveform.
In my example I chose a Period value of 100, thus 100 samples for a complete waveform.
So with an Interupt (TMR0 1:32) of ~1464Hz, My waveform is fully processed at around (1464 / 100) 14.6Hz
The 'SetOfset' component macro is then used to scale this base frequency.
The value used for SetOffset is a Float value, so there is a bit of int2float calculation to get the AV input value into something usable.
For display purposes an approximate frequency value is calculated and converted to an integer.
Notes on my example program:
I've generally found it easy to stick to Signed integer values for DSP Variables and use the appropriate SINT macros in my DSP calls. No great reasoning behind this, I just seem to get things working quicker this way!
Using an interupt to trigger the DSP calculation, made it much more regular, thus easier to play with and understand.
The calculated freq values shown on the MIAC display are approximate.
Remember, You need to stop Zero values getting into your calculations.
The chosen frequency output just happens to the the spark rate range for a four stoke engine, from cranking to 18K RPM and a handy test rig for checking RPM tachos!
At least some of the DSP stuff is starting to make a bit more sense!
Cheers, J.
My brain kicked in over night and I came to the same conclusion.
Attached is a simple working example for anyone following along.
A Variable pot on input 1, will vary the output frequency between roughly 0.5Hz to 150Hz. Again some of my learning process...
My FC programs DSP uses the 'Tick' method, so each time the DSP routine is evaluated (triggered by the interrupt TMR0) it processes one sample in the defined waveform.
In my example I chose a Period value of 100, thus 100 samples for a complete waveform.
So with an Interupt (TMR0 1:32) of ~1464Hz, My waveform is fully processed at around (1464 / 100) 14.6Hz
The 'SetOfset' component macro is then used to scale this base frequency.
The value used for SetOffset is a Float value, so there is a bit of int2float calculation to get the AV input value into something usable.
For display purposes an approximate frequency value is calculated and converted to an integer.
Notes on my example program:
I've generally found it easy to stick to Signed integer values for DSP Variables and use the appropriate SINT macros in my DSP calls. No great reasoning behind this, I just seem to get things working quicker this way!
Using an interupt to trigger the DSP calculation, made it much more regular, thus easier to play with and understand.
The calculated freq values shown on the MIAC display are approximate.
Remember, You need to stop Zero values getting into your calculations.
The chosen frequency output just happens to the the spark rate range for a four stoke engine, from cranking to 18K RPM and a handy test rig for checking RPM tachos!
At least some of the DSP stuff is starting to make a bit more sense!
Cheers, J.