How to find analog voltage period and average value of connected signal? - stm32

I'm using STM32 and i need to find analog voltage period and average value of connected signal which is connected to PC0. I need to read the analog voltage and find the period of signal. I need to write a c code.

Related

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:

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.

Correct way to use switch and voltage sensor in Simulink Simscape

I am trying to use a switch in Simulink Simscape. I want to see what voltage appears on both sides of the switch. The switch should close when the applied physical signal is greater than the threshold of the switch. It should be open otherwise. The switch is connected to a voltage source on one side and is an open circuit on the other side.
The voltage on the side connected to the voltage source is the voltage of the voltage source (as expected). However, I find that when the switch is open, the voltage on the other side is not zero, it is the voltage of the voltage source.
The only way to get this to work (to get a near zero value for the output voltage) is to apply a non-infinite resistance between the terminal on the left hand side of the switch.
What's going on here?
In the real world, the voltage between ground and the left hand side switch terminal should be zero, not 12.
In your simscape model there is problem of connection of voltage sensor because always voltage is measure across variable and current us measure through variable.
In your model Voltage Sensor3 is connected across variable but Voltage sensor4 is connected through variable (means connected through voltage source).
In shown figure I modeled your circuit Voltage Sensor3 should be connected like that way

Connect models in Matlab Simulink

Good day everyone!
I tried to make a circuit in matlab simulink, with an AC voltage, Resistor and Voltage measurement. AV voltage and Resistor connect quite well but voltage measurement can't connect the resistor connection.
how may I connect the voltage measurement to the resistor? Please help me thanks!
this is the circuit i want to simulate
I used different types of resistor, and Ac voltage but same results
In my opinion, your diode is from a different library (Simscape\Foundation Library\Electrical) than the voltage source, the resistance and the voltage measurement block (Power Systems...). Try to use blocks from the same Library.
See following picture for when I only use blocks from Simscape\Foundation Library\Electrical

Frequency issues in simulink interface with arduino

I'm trying to generate 6 PWM signals by comparing sine and triangular waves on simulink.In the scope I'm getting the frequency of PWM signals as 50 HZ. But when I deploy the model onto arduino, the frequency of the PWM signal is getting reduced to around 15 HZ .How to fix this ?
whether you've downloaded arduino library for matlab simulink? PWM output later on arduino digital pins are connected to the scope matlab