Sample rate in Analog Input/Output blocks in Simulink
Mostrar comentarios más antiguos
I am preparing a class assignment with NI myDAQ where the sample rate should be a variable to be defined by the students.
Sample rate should be a variable in the workspace so students can change it according to results from previous computations on the system itself.
If I try to insert a variable, defined in the workspace as a positive number, I get error. Is there a workarounf for it?
2 comentarios
Manikanta Aditya
el 12 de Feb. de 2025
What is the error you encountered?
Anna
el 12 de Feb. de 2025
Respuestas (1)
Avni Agrawal
el 20 de Mzo. de 2025
0 votos
Hi Anne,
I understand that you are trying to use NI myDAQ with Simulink, setting the sample rate as a variable from the MATLAB workspace can sometimes cause issues. Here's how you can work around this:
1. Define the Variable Before running your model, ensure the variable is defined in the workspace. For example:
N = 50; % Sample rate, can be changed by students
2. Use a Constant Block: Instead of directly entering the variable into block parameters, use a Constant block:
- Drag a Constant block into your model.
- Set its value to `N`.
- Connect it to the block where the sample rate is needed.
3. MATLAB Function Block: If you need more flexibility, use a MATLAB Function block:
- Add a MATLAB Function block to your model.
- Inside the function, use `N` to set the sample rate.
function y = setSampleRate(N)
y = N; % Use N as the sample rate
end
4. Parameterize the Model: Ensure your model is set up to use workspace variables:
- Go to `Simulation` > `Model Configuration Parameters`.
- Check the `Data Import/Export` settings to allow workspace variables.
By following these steps, you can successfully use a workspace variable as the sample rate in your Simulink model with NI myDAQ.
I hope this helps!
Categorías
Más información sobre Communications Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!