Send a sine wave out of matlab to arduino
조회 수: 15 (최근 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!