Flowcode v6 has new features designed to expose more information to the user in both a useful and meaningful way. Two of these new features are the scope window which is capable of displaying analogue and digital traces over time and the console window which is capable of displaying text based data.
Both these features are built into the DSP components as standard so in this blog post I want to take you through some of the fundamentals we have employed in the DSP components.
One of the first fundamentals we decided upon is that the DSP components should work on any target microcontroller device so the maths has to be as generic as possible. DSP stands for digital signal processing so pretty much any microcontroller is capable of this. There is an advantage to using a 16-bit dsPIC over a standard 8-bit device but only in that it has a inbuilt 16-bit multiplier which allows fairly complex calculations to be performed in a single instruction.
Generally for a DSP system some of the main concerns are the amount of RAM memory available and the maximum speed of the device. Take for example an audio application, you need to be able to sample the signal at least 2x the maximum frequency to collect all the data your interested in (CD quality maximum frequency: 22.05KHz, Nyquist sample frequency: 44.1KHz). This means that for every sample you have 22.675 micro seconds to process the data before you need to be back taking the next sample. Most embedded audio systems do not need full CD quality audio bandwidth so the upper frequency can be much lower.
The first DSP example we will look at is a basic on / off control system as used in a lot of modern appliances such as ovens, microwaves, irons etc. Essentially you have two inputs to the system which are the set point which controls what we want the output to be and the feedback which represents the current state of the output. If the feedback signal is lower then the set point then the output is switched on. If the feedback signal is higher then the set point then the output is switched off. When the feedback signal gets close to the setpoint there is the possibility for the output to toggle on and off at high speed which could potentially damage the output circuitry. The Hysterisis property of the DSPControl component allows a minimum value change before the output state change can occur therefore adding stability to the output and prevent oscillation.
To create the program I added a DSP System component to the panel and then edited the components properties to create 2 buffers, one called feedback and the other called output. We do not need too much precision in this example so I have used 8-bit unsigned buffers.
Next I added a DSP input component and configured it’s properties to point to the DSP System buffer manager and to pass it’s data to the buffer named Feedback. I then added a DSP control component and assigned the feedback buffer to the feedback buffer property and the output buffer to the output property. To finish off the system I used a DSP Output component and again connected this to the output buffer. Finally I added two ADC components and an LED component to the panel, renamed them to FeedbackADC, SetpointADC and LED1 then positioned them near to their respective portions of the DSP chain.
Each DSP component has certain macros to allow the behind the scenes mathematics to be called. The maths functions know where to get the incoming values and where to store outgoing calculated values because of the property buffer assignments we did above. This makes the program nice and easy and is only really a case of calling a component macro for each DSP icon we have on the panel in the correct order to allow the DSP chain to run correctly. Each macro call comes in a Standard and Tick format. The standard macros will process the entire buffer a segment at a time whereas the tick macros will only process a single segment of the buffer.
For the DSP chain we have created we have to call the functions in this order.
SetpointADC :: GetByte
FeedbackADC :: GetByte
DSPInput1 :: AddAsByte
DSPControl1 :: Process
DSPOutput1 :: ReadAsByte
If your using the tick versions of the functions then you will also need to use the DSPSystem1 :: TickAllBuffers function to move to the next segment of each buffer.
The console and scope windows are automatically populated with data from the DSP system buffers allowing very easy access to information to aid in developing and debugging DSP related programs and control systems.
The console window creates a tab for each buffer on the DSP System, each line on the console shows the values inside each of the DSP buffers. If the buffer has 8 segments then there will be 8 values on each line representing the value in each segment. This is very useful for checking that the mathematics is doing what it is suppost to be doing before downloading the program to a microcontroller device.
The scope window creates a DSP system group and adds each of the DSP buffers to the group as a trace allowing the data to be seen in a graphical format rather then a numeric format. Again this is useful for debugging and to ensure the system is going to be stable and respond correctly to the inputs provided. I have superimposed the set point value onto the trace to make it easier to see what is going on. By selecting the scope window and then scrolling down while hovering the mouse towards the right hand side of the scope window the scope will zoom out allowing you to see much more of the signal data over time.
Flowcode source available from here.
More DSP related posts to follow soon.
15,667 total views, 4 views today