OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3126|回复: 2

STM32F030F4P6输出互补正弦波

[复制链接]

26

主题

55

帖子

1

精华

中级会员

Rank: 3Rank: 3

积分
432
金钱
432
注册时间
2013-6-3
在线时间
49 小时
发表于 2017-1-19 22:42:25 | 显示全部楼层 |阅读模式
在线正弦表生成 http://www.daycounter.com/Calculators/Sine-Generator-Calculator.phtml
在线RC滤波计算http://www.sengpielaudio.com/calculator-RCpad.htm
在线低通滤波器计算  http://www.beis.de/Elektronik/Filter/ActiveLPFilter.html


正弦表生成C源代码
[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(int argc,char *argv[])
{
int entries, entries_2PI, phase, amplitude, offset, data_per_line;
int i, j;
int max, min, max_digits;

if (argc != 7) {
fprintf(stderr,"Generate C source code for sine table\n");
fprintf(stderr,"Usage:\n");
fprintf(stderr,"sinus_gen entries entries_per_2PI phase amplitude offset data_per_line >outputfile\n\n");
fprintf(stderr,"entries : number of entries in sine table\n");
fprintf(stderr,"entries_per_2PI : number of samples within full 360 degree\n");
fprintf(stderr,"phase : phase offset in samples\n");
fprintf(stderr,"amplitude : amplitude of sine wave, integer\n");
fprintf(stderr,"offset : offset of sine wave, integer\n");
fprintf(stderr,"data_per_line : number of samples per line in source file\n");
fprintf(stderr,">outputfile : redirect output form terminal to file\n");
return 1;
}

entries = atoi(argv[1]);
entries_2PI = atoi(argv[2]);
phase = atoi(argv[3]);
amplitude = atoi(argv[4]);
offset = atoi(argv[5]);
data_per_line = atoi(argv[6]);

min = abs(offset - amplitude);
max = abs(offset + amplitude);

max_digits=2;
if (min > 99 || max > 99) max_digits=3;
if (min > 999 || max > 999) max_digits=4;
if (min > 9999 || max > 9999) max_digits=5;

// header
printf("const int sinus[%d] = {\n\t", entries);

for (i=0, j=0; i<entries; i++) {
switch(max_digits) {
case 2: printf("%3d", (int)(offset + amplitude*sin((phase+i)*2*3.1415927/entries_2PI))); break;
case 3: printf("%4d", (int)(offset + amplitude*sin((phase+i)*2*3.1415927/entries_2PI))); break;
case 4: printf("%5d", (int)(offset + amplitude*sin((phase+i)*2*3.1415927/entries_2PI))); break;
case 5: printf("%6d", (int)(offset + amplitude*sin((phase+i)*2*3.1415927/entries_2PI))); break;
}
if (i < (entries-1)) {
printf(", ");
}
j++;
if (j==data_per_line) {
if (i < (entries-1)) {
printf("\n\t");
} else {
printf("\n");
}
j=0;
}
}
if (j !=0) printf("\n");

// footer
printf("};\n");

return 0;
}[/mw_shl_code]

截图_2017-01-19_22-28-44.png

图片 007.jpg

图片 001.jpg

图片 003.jpg

图片 008.jpg


程序很简单,主要就是DMA和定时器部分

dmachushihua:
    @+0=LSR,+4=IFCR,
    @+8=CCR1,+c=CNDTR1,+10=CPAR1+14=CMAR1,
    @+1c=CCR2,+20=CNDTR2,+24=CPAR2,+28=CMAR2
    @+30=CCR3,+34=CNDTR3,+38=CPAR2,+3c=CMAR3
    @+44=CCR4,+48=CNDTR4,+4c=CPAR4,+50=CMAR4
    @+58=CCR5,+5c=CNDTR5,+60=CPAR5,+64=CMAR5
    @+6C=CCR6,+70=CNDTR6,+74=CPAR6,+78=CMAR6
    @+80=CCR7,+84=CNDTR7,+88=CPAR7,+8c=CMAR7
    ldr r0, = 0x40020000
    ldr r1, = 0x40012c3c @ 外设地址
    str r1, [r0, # 0x60]
    ldr r1, = zhengxianbiao @ 储存器地址
    str r1, [r0, # 0x64]
    ldr r1, = 180      @ 正弦点数
    str r1, [r0, # 0x5c]
    ldr r1, = 0x21b1         @ 21b1 8位到16位
                         @ 25B1 16位到16位
                             @储存到外设
    str r1, [r0, # 0x58]

tim1chushiha:
    ldr r0, = 0x40012c00 @ tim1_cr1
    movs r1, # 0
    str r1, [r0, # 0x28] @ psc
    ldr r1, = 40        
    str r1, [r0, # 0x2c] @ ARR
    ldr r1, = 0x60
    str r1, [r0, # 0x1c] @ ccmr2  CC3
    ldr r1, = 0xd00    @  CC3 互补
    str r1, [r0, # 0x20] @ ccer
    ldr r1, = 0x8000
    str r1, [r0, # 0x44] @ BDTR
    ldr r1, = 0x800 @ CC3 DMA
    str r1, [r0, # 0x0c] @ DIER
    ldr r1, = 0x81
    str r1, [r0]

stm32f030f4p6正弦波.zip (4.86 KB, 下载次数: 211)
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

120

主题

7878

帖子

13

精华

资深版主

Rank: 8Rank: 8

积分
12012
金钱
12012
注册时间
2013-9-10
在线时间
427 小时
发表于 2017-1-20 12:37:30 | 显示全部楼层
靠,你这测试板子高大上啊,还是汇编的程序
回复 支持 反对

使用道具 举报

120

主题

7878

帖子

13

精华

资深版主

Rank: 8Rank: 8

积分
12012
金钱
12012
注册时间
2013-9-10
在线时间
427 小时
发表于 2017-1-20 12:37:36 | 显示全部楼层
靠,你这测试板子高大上啊,还是汇编的程序
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-7 10:57

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表