Send a sine wave out of matlab to arduino
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Gautam Vallabha
2012 年 4 月 9 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Arduino Hardware についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!