Code:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clc; | |
clear; | |
sample_bits = 12;#smaple bits | |
fs = 10000; #sample frequency | |
f = 60; #target frequency | |
amp= 2^(sample_bits-1); | |
t = 0:1/fs:1/f; | |
x = amp*(1+sin(2*pi*f*t));#avoid negative part | |
pwm_duty = x/(amp*2); | |
bar (pwm_duty); |
Avoid the negative part cause normally MCU didn't have negative voltage output ability.
Ref:
1.http://bugworkshop.blogspot.tw/2011/04/blog-post_12.html
沒有留言:
張貼留言