zhouzs 发表于 2010-8-4 12:52:51

关于max262的程序

本人是个菜鸟,但是很喜欢单片机,各种单片机的电路也做了很多,但是这次碰到钉子了,就是max262,我想制作一个滤波电路,可是程序我怎么编都是不对的,可能是我理解的有问题,希望各位大侠们能帮帮我,你们谁有max262的程序,给我一个,我参考一下,图就按照你的吧,我可以在你的程序上修改

xiaochun90188 发表于 2011-8-11 18:10:43

#include <reg52.h>

#define uintunsigned int
#define uchar unsigned char
#define ulong unsigned long

sbit wr=P2^0;

sbit a0=P2^1;
sbit a1=P2^2;
sbit a2=P2^3;
sbit a3=P2^4;

sbit d0=P2^5;
sbit d1=P2^6;


void del(char v)
{
while(v--);
}


address_262(uchar x)
{
x=(x&0x0f);
if((x&0x01)==0x01)a0=1;
else a0=0;
if((x&0x02)==0x02)a1=1;
else a1=0;
if((x&0x04)==0x04)a2=1;
else a2=0;
if((x&0x08)==0x08)a3=1;
else a3=0;
}

data_262(uchar x)
{
x=(x&0x03);
if(x&0x01)d0=1;
else d0=0;
if((x&0x02)==0x02)d1=1;
else d1=0;
}


send_data_262(uchar x,uchar y)//先地址,后数据
{
wr=1;
address_262(x);
del(2);
wr=0;
del(2);
data_262(y);
wr=1;
}

//函数功能: 设定max262的滤波器的工作模式
work_mod_262(uchar x,uchar y)//x表示工作模式(0--3),y表示哪个滤波器,滤波器0或者滤波器1
{
x=(x&0x03);
y=(y&0x01);
send_data_262((0x00+y*0x08),x);
}

set_fre_262(uchar x,uchar y)//x输入频率,y表示哪个滤波器,滤波器0或者滤波器1
{
uchar temp;
y=(y&0x01);

temp=(x&0x03);
send_data_262((0x01+y*0x08),temp);

temp=((x&0x0c)>>2);
send_data_262((0x02+y*0x08),temp);

temp=((x&0x30)>>4);
send_data_262((0x03+y*0x08),temp);
}


set_q_262(uchar x,uchar y)//x输入Q值,y表示哪个滤波器,滤波器0或者滤波器1
{
uchar temp;
y=(y&0x01);

temp=x&0x03;
send_data_262((0x04+y*0x08),temp);

temp=((x&0x0c)>>2);
send_data_262((0x05+y*0x08),temp);

temp=((x&0x30)>>4);
send_data_262((0x06+y*0x08),temp);

temp=((x&0x40)>>6);
send_data_262((0x07+y*0x08),temp);
}

main()
{
//uchar temp=2,y=1;
work_mod_262(0,0); //1
set_fre_262(24,0); //32
set_q_262(64,0);//64
//send_data_262((0x07+y*0x08),temp);
//data_262(2);
//work_mod_262(1,0);

//work_mod_262(0,1); //1
//set_fre_262(6,1); //32
//set_q_262(21,1);
while(1);
}

harryxp 发表于 2011-8-30 15:35:55

回复【1楼】xiaochun90188
-----------------------------------------------------------------------

请问这个程序可以用吗?

IGO_AVR 发表于 2011-8-30 16:11:03

这个可以

#include<avr/io.h>
#include<util/delay.h>
#include "MAX262.h"

#define PI 3.1415926

unsigned char cofficient_N_F0(unsigned int F0)
{
/***********************formula********************
fCLK/f0 = (26 + N)*π/2
=>N=2*fCLK/(f0*π)-26
***********************formula********************/
unsigned char temp;
temp=2*fCLK/(F0*PI)-26;
temp=1;
temp=2*fCLK/(F0*PI)-26;
return temp;
}

unsigned char cofficient_N_Q(unsigned char Q)
{
/*********************formula*********************
Q=64(128-N)
=>N=(128-Q/64)
*************************************************/
unsigned char temp;
temp=128-64/Q;
temp=1;
temp=128-64/Q;
return temp;
}


void set_add(unsigned char add)
{
if((add&0x08)==0x08)SET_A3;
else CLR_A3;

if((add&0x04)==0x04)SET_A2;
else CLR_A2;

if((add&0x02)==0x02)SET_A1;
else CLR_A1;

if((add&0x01)==0x01)SET_A0;
else CLR_A0;
}

unsigned int allocate(unsigned char MODE,unsigned char F0,unsigned char Q)
{
/***********************temp allocate**********************************
|0|Q7|Q6|Q5|Q4|Q3|Q2|Q1|Q0|F6|F5|F4|F3|F2|F1|F0|M1|M0|
*********************************************************/

unsigned int temp=0;
temp|=Q;
temp=temp<<6;

temp|=F0;
temp=temp<<2;

temp|=MODE;

return temp;
}

void set_MAX262_A(unsigned char M,unsigned int f0,unsigned char Q)
{
unsigned char i;
unsigned int paramter=0;
//paramter=allocate(M,cofficient_N_F0(f0),cofficient_N_Q(Q));
paramter=allocate(M,f0,Q);
        for(i=0;i<8;i++)
        {
    SET_WR;
        set_add(i);
        //_delay_us(1);
        CLR_WR;
        if((paramter>>(i*2)&0x01)==1)
    SET_D0;
        else
        CLR_D0;
    if(paramter>>(i*2+1)&0x01)SET_D1;
    else CLR_D1;

       
       
//        _delay_us(1);
        SET_WR;
        }

}

void set_MAX262_B(unsigned char M,unsigned int f0,unsigned char Q)
{
unsigned char i;
unsigned int paramter=0;
paramter=allocate(M,cofficient_N_F0(f0),cofficient_N_Q(Q));
        for(i=8;i<16;i++)
        {
    SET_WR;
        set_add(i);
        CLR_WR;
        if((paramter>>((i-8)*2)&0x01)==1)
    SET_D0;
        else
        CLR_D0;
    if(paramter>>((i-8)*2+1)&0x01)SET_D1;
    else CLR_D1;


        SET_WR;
        }

}

262.h
#ifndef _MAX262_H_
#define _MAX262_H_

#include "MAX262.h"
/***************************config start***************************/
#define fCLK 150000

#define D1 7
#define D0 6
#define A3 5
#define A2 4
#define A1 3
#define A0 2
#define WR 1

#define DDRXDDRA
#define PORTX PORTA


#define SET_D1 PORTX|=(1<<D1)
#define CLR_D1 PORTX&=~(1<<D1)

#define SET_D0 PORTX|=(1<<D0)
#define CLR_D0 PORTX&=~(1<<D0)

#define SET_A3 PORTX|=(1<<A3)
#define CLR_A3 PORTX&=~(1<<A3)

#define SET_A2 PORTX|=(1<<A2)
#define CLR_A2 PORTX&=~(1<<A2)

#define SET_A1 PORTX|=(1<<A1)
#define CLR_A1 PORTX&=~(1<<A1)

#define SET_A0 PORTX|=(1<<A0)
#define CLR_A0 PORTX&=~(1<<A0)

#define SET_WR PORTX|=(1<<WR)
#define CLR_WR PORTX&=~(1<<WR)

/****************************config over**************************/

/********************function statementstart********************/
extern void set_MAX262_A(unsigned char M,unsigned int f0,unsigned char Q);
extern void set_MAX262_B(unsigned char M,unsigned int f0,unsigned char Q);


#endif

wzz951 发表于 2011-8-31 13:59:56

en

mdq123 发表于 2012-8-2 16:18:02

一个51,一个avr,用哪个呢?

raxb 发表于 2012-8-2 16:27:35

mdq123 发表于 2012-8-2 16:18 static/image/common/back.gif
一个51,一个avr,用哪个呢?

我也很纠结.........{:mad:}

mdq123 发表于 2012-8-6 15:02:09

raxb 发表于 2012-8-2 16:27 static/image/common/back.gif
我也很纠结.........

我的程序计算一直不对啊

raxb 发表于 2012-8-6 16:21:06

mdq123 发表于 2012-8-6 15:02 static/image/common/back.gif
我的程序计算一直不对啊

神马情况,MAX262俺没玩过

mdq123 发表于 2012-8-8 03:57:27

raxb 发表于 2012-8-6 16:21 static/image/common/back.gif
神马情况,MAX262俺没玩过

谢谢,弄好了

guwu454 发表于 2013-2-23 14:18:06

mdq123 发表于 2012-8-8 03:57 static/image/common/back.gif
谢谢,弄好了

请教一下,您这个最好是怎么弄的呢?能共享一下代码吗?我现在不知道是怎么回事,没有输出。驱动完全按照这个帖子写的,只是我用的是stm32,输出电平是3.3V

guwu454 发表于 2013-2-25 10:06:51

mdq123 发表于 2012-8-8 03:57 static/image/common/back.gif
谢谢,弄好了

在吗?您最后是怎么解决的?我一直在弄,都没出波形
页: [1]
查看完整版本: 关于max262的程序