Several Digilent Forum Staff members will be out concurrently the week of August 5th. Responses may be delayed. ×
• 0

# MCC 152 and MCC 128

## Question

Hi,

I am trying to stack MCC152 and MCC128 together onto one RPI since my system has both analog output and analog input. May I know whether that's something doable? Will that mess up with the GPIOs?

Thanks.

Edited by Youmin

## Recommended Posts

• 0

Yes that is very do-able from the same app/script on one raspberry Pi.

No, it will not 'mess up' the GPIO.  Here is a link to the GPIO pin definitions for MCC RPI hats: https://kb.mccdaq.com/KnowledgebaseArticle50812.aspx

Regards,

Jeff

##### Share on other sites

• 0

Thank you Jeffrey! I am trying to run a continuous sinusoidal output from MCC152. May I ask whether there's any example code for that? I am thinking of using "sleep()" function achieving that but concerned it may slow the IO speed.

I also saw the maxumum output speed is 5kS/s for MCC152. Is there approaches if I want to output faster frequency signal? Thanks.

##### Share on other sites

• 0

Keep in mind, the MCC 152 is not capable of streaming output data at a uniform rate.  There is no analog output scan function for this device.  Instead you must manage the clock timing on your own.

The main algorithm for generating a sine wave and writing out each value as generated:

for i = 0 To (360- 1)
OutputValue = MaxAmplitude * Sin((i * (2 * PI / 360))) + DCOffset   //'# create a sine wave in 2PI radians .

Next

Where:

MaxAmplitude is the max voltage out for your sine wave, such as 5V peak to peak sine wave.

DCOffset is where you want the 'zero crossing' level to be.  Normally it is set to 0.

I ran some benchmarks of my own for the MCC 152, outputting alternating 0V and 5V as fast a possible. Or in other words, the app I used toggled between 0V and 5V on one channel, doing nothing more that that.  It did not display anything on the screen because that would slow down the output update rate.

My results:

C/C++:  56.4 k writes per second.

python 3.x:  33 k writes per second.

givens: Raspberry pi 3B

GNU C and CodeBlocks.

Having stated that, and using the C test result, the maximum sine wave you can output if you use 360 distinct points (of the sine wave):

Max Freq = 56,400 writes per second / 360 points per period

Max Freq = 151.6 Hz sine wave.

"Is it possible to output a higher frequency sine wave (ie make it go faster)?"  Yes, but the sine wave form may suffer.  You can decrease the number of points per period from 360 to 180:

for i = 0 To (180- 1)
OutputValue = MaxAmplitude * Sin((i * (2 * PI / 180))) + DCOffset   //'# create a sine wave in 2PI radians .

Next

Applying the same math, you can output a 303.3 Hz sine wave.  but keep in mind it will look a bit like a staircase.

Or, at 90 points per sine wave period : ~606 Hz.

You can continue to reduce the number of points per sine wave period, but when you get to < 60 points per period, it no longer looks much like a sine wave.

Note: the MCC 152 outputs values statically,  i.e. one at a time. if you look at the values on an oscilloscope, you will see individual DC levels.  Should you prefer a smooth sinewave you will need to add some filtering or smoothing.  Easiest way to do that is with RC filter.

While the MCC 152 is capable of outputting periodic signals, that was not the designed intent.  the designed intent was to just output DC level signals, it just so happens you can change the DC level at a fairly robust rate.  So if you want to acquire data using the MCC 128 AND output a sine wave, you will see lags in the sine wave when you are servicing the MCC 128 (to off load data or make decisions on the collected data).

Regards,

Jeff

## Create an account

Register a new account