Send a sine wave out of matlab to arduino
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to output the values from a sine wave to generate pulses for an h-bridge but don't know hot to send them one by one. is it possible for some help?
Code i did till now is attached below:
arduino=serial('COM2','BaudRate',9600);
fopen(arduino);
frequency = 1; % required frequency
period = 1/frequency; % required period
%amplitude = 127 ; % required amplitude
phase = 0; % required phase angle
offset = 127; % required DC offset
t = 0:0.00001:2*period;
output = 127 * sin(2*pi*frequency*t + phase) + offset;
0 Kommentare
Antworten (1)
Gautam Vallabha
am 9 Apr. 2012
I assume you want to output the sinusoid values to an "analog output" (PWM) pin.
Take a look at MATLAB Support Package for Arduino. It allows you to send commands from MATLAB to Arduino, e.g.
a = arduino('COM9');
a.pinMode(13,'output'); % digital output
a.pinMode(9,'output'); % "analog output" (PWM)
% output the digital value (0 or 1) to pin 13
a.digitalWrite(13, 0)
% ouptput value on digital (pwm) pin 5
a.analogWrite(9, 120)
(The above code is from examples/example_io.m in the support package).
0 Kommentare
Siehe auch
Kategorien
Mehr zu Arduino Hardware finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!