STM32F030F4P6输出互补正弦波

2019-10-15 06:09发布

在线正弦表生成 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 ");
fprintf(stderr,"Usage: ");
fprintf(stderr,"sinus_gen entries entries_per_2PI phase amplitude offset data_per_line >outputfile ");
fprintf(stderr,"entries : number of entries in sine table ");
fprintf(stderr,"entries_per_2PI : number of samples within full 360 degree ");
fprintf(stderr,"phase : phase offset in samples ");
fprintf(stderr,"amplitude : amplitude of sine wave, integer ");
fprintf(stderr,"offset : offset of sine wave, integer ");
fprintf(stderr,"data_per_line : number of samples per line in source file ");
fprintf(stderr,">outputfile : redirect output form terminal to file ");
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] = { ", 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(" ");
} else {
printf(" ");
}
j=0;
}
}
if (j !=0) printf(" ");

// footer
printf("}; ");

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, 下载次数: 115) 2017-1-19 22:31 上传 点击文件名下载附件


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
八度空间
1楼-- · 2019-10-15 06:37
靠,你这测试板子高大上啊,还是汇编的程序
八度空间
2楼-- · 2019-10-15 10:06
靠,你这测试板子高大上啊,还是汇编的程序

一周热门 更多>