PWM 正玄波形 通过C语言生成

复制代码
#include <stdio.h>
#include <math.h>
#include <stdint.h>

#define SAMPLE_POINT_NUM            (200)        /* 需要生成的点的个数 */
#define SINE_MAX                    (255)       /* sin 函数幅值 */
#define PI                          (3.1415926) /* 数学中的常量:Π */
#define POINT_BUFFER_LEN            (400)

int generate_data[POINT_BUFFER_LEN]; /* 生成的数据放在此数组中 */

void get_sin_data(unsigned int point)
{
    unsigned int i = 0;
    float step = 0.0;
    float data = 0.0;
    int tem = 0;

    step = 1 * PI / point; /* 将 sin 函数从 [0-2Π] 等分为 N 个点,则每个点的步长为 2Π/point_num */

    for (i = 0; i < point; i++)
    {
        data = SINE_MAX * sin(step * i);
        tem = (int)data;
        generate_data[i] = tem;
    }
}

int main(int argc, char *argv[])
{
    get_sin_data(SAMPLE_POINT_NUM);

    for (int i = 0; i < SAMPLE_POINT_NUM; i++)
    {
        printf("%d ,", generate_data[i]);
    }

    printf("\r\n");

    return 0;
}
相关推荐
Navigator_Z23 分钟前
LeetCode //C++ - 1226. The Dining Philosophers
c语言·算法·leetcode
源代码•宸30 分钟前
前置准备:定时微服务背景和现状
开发语言·经验分享·后端·微服务·云原生·架构·golang
2601_9673387131 分钟前
C#上位机开发零基础入门到精通全套视频
开发语言·c#
小白学大数据1 小时前
超简单:用 Python 让 Excel 飞起来:用 openpyxl 把重复报表整理交给脚本
开发语言·数据库·python·excel
旧梦95271 小时前
Java SortedMap 接口详解:从入门到实战
java·开发语言
莫陌尛.2 小时前
Java_this构造方法
java·开发语言
Persistent的粽子!2 小时前
C++:类与对象(二)
开发语言·c++
Dreams°1232 小时前
【Java后端+Vue前后端分离:内网正常、公网访问异常|5个高频经典踩坑完整复盘】
java·开发语言·vue.js
思麟呀2 小时前
嵌入式入门(一)宏观生态到首次烧录
c语言·嵌入式硬件
小雪崩2 小时前
嵌入式学习 day39:TCP并发服务器模型
linux·服务器·c语言·网络·学习·tcp/ip