Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Concept of sampling and scaling using DSPIC microcontrollers

Status
Not open for further replies.

gary36

Full Member level 4
Full Member level 4
Joined
Mar 31, 2018
Messages
231
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,981
I am newbie in DSP and starting from ground up. I have basic questions

1. I have an analog input 1Vpp AC sine wave (1.5v offset) connected to DSPIC 10 bit ADC. I have corrected for offset by subtracting 512 counts corresponding to 1.5v. Now I have to scale the digital counts to field value ( 1vpp). What should the scaling factor? Should it be 1/1023*adc value?
2.What would be the impact if scaling factor is increased to some large value (say 10)?
3. What should be the datatype in performing these operations, should it be UINT16 or double?
4. How should we decide sampling rate (above the nyquist rate)? Is it dependent on the execution time of the algorithms?
5. Finally any good resources that explains with examples , the time budget calculations.
 

Hi,

You urgently need to read the microcontroller datasheet.

1) Impossible to be anwered without ADC specifications. Mainly input voltage range.
Usually the correct factor is something with 1024 and not 1023. --> datasheet

2) the same as with any 10 bit value multiplied with a factor.
ADC output may be right aligned or left aligned -> datasheet.
If you want 10 (integer) or you may want 10.0 (float)...integer needs less processing power thus it's preferred

3) You need to know what resolution you need. It simply depends on application. And how the values are processed.
16 bit usually is sufficient for linear operations like +, -, ×, ÷....but for squaring or square root often you need a highe bit width.

4) again it depends on your application. You should take care about nyquist in any case. But still it depends on input frequency range of interest and the used analog anti aliasing filter.
You need to decide if you want real time processing of a contionous (sample) data stream... or you sample / process in discontinous mode.

5) There are more than enough around. If you focus on the microcontroller, then look at the nanufacturer's internet pages, there you will find basic informations as well as design- and application notes.
If you are looking for special algorithms, then look for reliable informations. You may recognize them by*
* given author, maybe with contact
* good documented code
* additional scientific description with reference to other sources of information and explained formulas.

Klaus
 

Hi

1. Referring to my query No.2 from #1, scaling factor. Please clarify what is the impact if I convert adc value to 1/1024*adcval (same as 1vpp input) or provide a gain (10/1024)*adcval

2. You have recommended integer multiplication to be the best. But what if I have to multiply two sine signals which are float in nature in real life. How to convert these float values to fixed point (Q15?)
 

Hi,

2)
No. I didn´t say that integer multiplication is the best.
To save processing power: try to use integer arithmetic.
But if you really need the huge dynamics then use float. (this is relatively seldom)

Don´t consider a sine shape is only -1...0...1.
You may also use integer values: x = integer ( 32767 * sin(phi))...for full scale int16

Often people use float, because they don´t understand "range", "resolution" and "error". Or they are simply too lazy to do the - in my eyes - simple calculations.
For example if your input is a 10 bit (ADC) value .. then there is no significant benefit of using "float" or "INT16" against a 10 bit value.
The input with the "least resolution" usually determines "result resolution".
--> in detail it depends on your application.

Almost all of my designed precision industrial measurement applications do without float.

Klaus
 

I want to multiply the incoming sine wave signal (1vpp) 50 Hz with 1.25 dc offset with internally generated sine function. The software sine function generates output in the -1 to +1. Hence I need to convert the incoming adc data in the similar range before multiplication. What is the right method. There are so many views on the web. I want to converge with the right understanding
 

Hi,

I´ve already told you how to generate a sinewave with INT16 range....

I want to multiply the incoming sine wave signal (1vpp) 50 Hz with 1.25 dc offset with internally generated sine function.
This is a vague description, because you can´t multiply a single ADC value with a sinewave.

I assume indeed you want to to a correlation or a DFT.
To safe processing power this usually isn´t done in "voltage" level and float values, instead they claculate on binary level (LSB) with integer values.
And then - after the calculation - the result may be multiplied with a float value - if really needed.
A DFT as well as a correlation works with a window of n samples. n ADC samples, n table values (in your case the sine values).
This needs to be specifed first.

I strongly recommend to do first things first. Decide the specifiactions of your system:
* What is the input signal: voltage range of interest, frequency range of interest....I assume your input frequency may vary and your input voltage may vary (at least a bit). Also: is it a pure sinewave with 0% distortion? If not, then you need to specify the distortions (waveform or overtones, amplitude range of overtones)
* specify your output signal: What value(s) do you want to calculate? How often, with what resolution, with what precision?

I know this are a lot of "annoying" questions. But without some technical informationns about your application I will not be able to help.

Klaus
 

It is mini assignment to find the magnitude and phase of the incoming signal. What I need to do is the multiply the incoming signal(50Hz) to quadrature signals(internally generated) and then determine the magnitude and phase. It is a sort of low profile lockin system. But this is an educational assignment. In this connection things are not clear about data conversion of incoming signal vs internally generated data type of sine signal
 

Hi,

In this connection things are not clear about data conversion of incoming signal vs internally generated data type of sine signal
I´m not asking about data conversion.

You need to specify the input signal first, then you can decide about data conversion.

Without a specification of the input signal all you can do is: trial and error.
But for trial and error you don´t need a calcualtor, you don´t need an engineer ... simply do it.

***
Now we know:
You want to measure magnitude - Still unknown: how often, what range and ... Sorry, Im repeating me.
..
phase...

****

If you have a pure sine input, then follow nyquist. It says the sampe rate needs to be higher than twice the input signal frequency.
And to avoid fluctuations .. it should be an integer multiple.
Thus 50Hz is off nyquist, 100Hz is off nyquist, 150Hz is the first you can use. Three samples per full wave.

It gives perfect results, but as already said: only if input is undistorted sine.
And only with perfect integer multiple of input frequency: A sample rate of 150Hz on a 50.2Hz (for example) input signal will cause fluctuations.

Klaus
 

Hi FvM,

Too many new concepts for novice like me.
1.First, please provide a workable model for implementing oversampling/filter- What could be the group delay?
2. What is the meaning of using INT16 of ADC and sine table, do you mean converting 0-65535 to sine function?
3. What is meant by filter accumulator?
 

A low sampling frequency slightly above Nyquist rate involves a high order anti-aliasing filter to suppress interferences with mains harmonics. Better implement oversampling and a simple filter.

Float arithmetic has the advantage that you don't need to think about rescaling of intermediate results, but it's slow. I would use int16 for the ADC value and sine table and int32 for the filter accumulator.

- - - Updated - - -

Considering this is an exercise problem, we can expect that the necessary methods have been provided in your lectures. Suggestions made in this thread may be beyond their scope.

1. Anti-aliasing filters are analog filters in front of the ADC. There are two requirements for it:
- Sufficient attenuation above the Nyquist frequency according to the level of high frequent signal components in the input signal
- Low attenuation for the signal of interest

Increasing the sampling frequency relaxes the filter requirements. My idea was to use a sampling frequency of e.g. 1 - 10 kHz and perform the signal processing with this frequency without downsampling.

2. int16 refers to signed number format. AC voltage must be represented by signed quantity for correct processing.

3. Regarding filter accumulator. How do you determine input phase und magnitude. I expect a number of input samples (usually over one or multiple sine periods) to be multiplied with the reference sine and cosine signal and the products summed up.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top