How to pulse generator block generate a pulse 40khz? - matlab

I tried to generate a 40khz pulse to the GPIO pin of my ultrasonic sensor in raspberry pi. I used the pulse generator instrumentation, but the pulse is not accurate: the oscilloscope displays only 10khz.
I modified configuration parameters:
fixed-step
sample time is auto/1e-08
solver is auto/discrete
I also have tried various ways to create a square pulse: function sign(sin(2*pi*40000t)), PLL block, repeating sequence, signal generator combined with sum, compare to zero, etc.
All of these display correctly on the scope, but do not deploy accurately.
I doubted the raspberry pulse generatior, so I used python to drive the GPIO pin; results are very accurate. I worry that the Simulink complier doesn't properly support raspberry or the sample time.
Any suggestions?
This is the model I used to generate 40khz pulse.
with period is 0.000025s,pulse width 50%, Solver type is fixed-step.
The oscilloscope display as the following figure:

Related

Reading 4-20ma transmitter stm32 adc

I try to use 4-20 ma pressure transmitter
With stm32 internal adc
Problem reading is flacuating too much I have to take average for 128-256 reading to take stable reading
Is that normal solution or there is other way to filter data and transmitter signal ??
Many reasons can affect the reading stability. Basically grounding, PCB layout, input cables, noise on the uController supply pins, input RC filter, the ADC code...
I have a similar application using a current resistor of 162R from input connector to the same ground of the ADC input. Than a series resistor of 22k and a ceramic capacitor of 47nF to ground, placed close to the ADC pin.
With that I take 10 ADC measures and make an average. Signal is stable.
Please, share your code and circuit diagram...

DAC Output on Arduino MKR Zero in Simulink

I am trying to use the Arduino MKR Zero in Simulink using the Simulink Support Package for Arduino Hardware. So far I have been successful at get a led to blink using a pulse wave in Simulink and the Digital output of the Arduino. I have also been able to vary a potentiometer connected to the Analog input of the Arduino and see the voltage plotted on a scope.
Now I am trying to output a sine wave from the DAC and then view that sine wave back through the ADC. The image below shows my setup. I know that the DAC takes value between 0 and 1023 and converts it to a voltage with reference 3.3V for the Arduino MKR Zero. So I have set up the sine wave block with Amplitude 307 and bias of 307 to get a 2V pk to pk waveform with offset of 1V. I have also included the Byte pack to convert this value to a Unit16 value for the DAC.
Now for the output I have done a similar setup to what I had for the potentiometer experiment. In this section, K = 3.3/4095. However, when looking at the scopes for the input and output, they are completely different. The input scope shows a sine wave with a 2V pk to pk waveform with offset of 1V while the output doesn't make any sense.
I should point out, for the physical setup, I have simple connected the DAC pin to the A6 pin on the Arduino. Any advice on what I am doing wrong is welcome.
Simulink Setup:
This is an image of the waveforms on the scopes:

how to simulate Sent_Protocl_signal?

I wanted to simulate the Sent_Protocol with an STM32 μC emulate as if I had a sensor. and represent this with an oscilloscope . I have to simulate this on Matlab and then connect with STM32. so i thought the signal should be like a normal PWM Signal look like.
So I wanted to ask if it is possible to generate a different pulse width in the same signal as in the above picture ?

What is the most appropriate clock/time source for software-based signal processing?

Let's say I want to sample a pair of GPIO pins of my Raspberry Pi* with a frequency around 10kHz to feed a software-based signal analyzer (written in C for instance). What is the most appropriate method to obtain an accurate timestamp for each sample? Accurate means, the delay between acqiring the sample and reading the clock/time source should be at least constant or negligible at best. The signal analyzer does not necessarily operate in realtime.
I am aware that the sampling quality may also be affected by other circumstances (e.g. preemptive mulititasking), but the question is only about acuqiring an accurate timestamp for each sample.
*) In general: any signal like a pulse wave (high/low) or an audio signal (quantized). The Raspberry Pi is only an example, since it has everything to acquire the signal already built-in.

generating a waveform in matlab for rohde and schwarz signal generator

We are doing a test which consists in sending a waveform from Matlab to the signal generator SMB100A and sending it through a cable to the r&s spectrum analyzer just to have a channel. We set the trigger manually in the signal generator in the restart mode, then we set the frequency and the chip rate in our Matlab code as well as the buffer size and the connections. Finally, we read the waveform, which is already stored in the signal generator , and we set ARB state ON: we are using the arbitrary customized digital modulation. However, the channel impulse response is different every time that we run the test: there is a portion of the signal that looks like an offset; we think the signal is shifted because of an inversion in the phase. Any clue about why this happens?