搜索
bottom↓
回复: 2

用MEGA128做的航模用电调

[复制链接]

出0入0汤圆

发表于 2005-4-2 17:13:21 | 显示全部楼层 |阅读模式
这个电调是我用我公司实验室里的电路板飞线做的(那板是仪器里拆出来的),接收机的输出用信号发生器来模拟的,用信号发生器试验已成功,当然IRF管用的是16A的IRF530,实验后我打算买OURAVR里的MEGA8和MEGA16做一个真实放到船上试的,但不知为什么我的这个网上买的二个MEGA8都下载不到,MEGA16能下,但我移植了一下,不知为什么不行,近来公司又有新的项目所以无时间了,拿出来和大家分享一下算了,本了用AVR只是玩玩,所以可能有错的地方.用ICC写的,



//ICC-AVR application builder : 2005-3-23 10:23:44

// Target : M128

// Crystal: 16.000Mhz



#include <iom128v.h>

#include <macros.h>





unsigned int up,down,a;

unsigned int T;



void port_init(void)

{

PORTA = 0xFF;

DDRA  = 0x00;

PORTB = 0xFF;

DDRB  = 0xFF;

PORTC = 0xFF; //m103 output only

DDRC  = 0x00;

PORTD = 0x00;

DDRD  = 0x00;

PORTE = 0xFF;

DDRE  = 0x00;

PORTF = 0xFF;

DDRF  = 0x00;

PORTG = 0x1F;

DDRG  = 0x00;

}



//TIMER0 initialisation - prescale:64

// WGM: PWM Fast

// desired value: 1.5KHz

// actual value:  0.977KHz (-53.6%)

void timer0_init(void)

{

TCCR0 = 0x00; //stop

ASSR  = 0x00; //set async mode

TCNT0 = 0x00; //set count

OCR0  = 0xFF;

TCCR0 = 0x7C; //start timer

}







//TIMER1 initialisation - prescale:1

// WGM: 15) PWM fast, TOP=OCRnA

// desired value: 1uSec

// actual value:  1.000uSec (0.0%)

void timer1_init(void)

{

TCCR1B = 0x00; //stop

TCNT1H = 0xFF; //setup

TCNT1L = 0xF1;

OCR1AH = 0xFF;   //OCR1AH = 0x29;

OCR1AL = 0xFF;   //OCR1AL = 0xA9;

OCR1BH = 0x11;

OCR1BL = 0x11;

OCR1CH = 0x00;

OCR1CL = 0x00;

ICR1H  = 0x00;

ICR1L  = 0x00;

TCCR1A = 0x33;

TCCR1B = 0xD9; //start Timer

}



#pragma interrupt_handler timer1_capt_isr:12

void timer1_capt_isr(void)

{

  if((TCCR1B&0x40)==0)

  {

  

  down=ICR1L;            //Read low byte first (important)

  down|=(int)ICR1H << 8; //Read high byte and shift into top byte

   T=down/16;

   //OCR1B=T;

   //if(T>=1000)

   //{T=1000;}

    //OCR0  = 254;

          a=T;

        //T=T-994;

       

        if(T<=994)

        OCR0=0x00;

        else

        if(T>=1994)

        OCR0=0xFF;

        else

   OCR0  = (T/3.921);

  // a=T/4;

printf("T=%u,down=%u,a=%d
",T,down,a);

  TCCR1B^=0x40;

TIFR=(1<<ICF1);

/*



//TCNT1=0;

//timer 1 input capture event, read (int)value in ICR1 using;

down=ICR1L;            //Read low byte first (important)

down|=(int)ICR1H << 8; //Read high byte and shift into top byte

ICR1=0;

TCNT1=0;

  a=down-up;

  T=a/16;

OCR1B = T;

TCCR1B^=0x40;

TIFR=(1<<ICF1);

printf("T=%d,down=%d,up=%d
",T,down,up);





*/

}

else

{

TCNT1=0;

TCCR1B^=0x40;

TIFR=(1<<ICF1);



/*



up=ICR1L;            //Read low byte first (important)

up|=(int)ICR1H << 8; //Read high byte and shift into top byte

ICR1=0;



TCCR1B^=0x40;

TIFR=(1<<ICF1);





*/

}

}



//UART0 initialisation

// desired baud rate: 11520

// actual: baud rate:11520

// char size: 8 bit

// parity: Disabled



void uart0_init(void)

{

UCSR0B = 0x00; //disable while setting baud rate

UCSR0A = 0x00;

UCSR0C = 0x06;

UBRR0L = 0x08; //set baud rate lo

UBRR0H = 0x00; //set baud rate hi

UCSR0B = 0x18;

}



//call this routine to initialise all peripherals

void init_devices(void)

{

//stop errant interrupts until set up

CLI(); //disable all interrupts

XDIV  = 0x00; //xtal divider

XMCRA = 0x00; //external memory

port_init();

timer1_init();

uart0_init();

timer0_init();





MCUCR = 0x00;

EICRA = 0x00; //extended ext ints

EICRB = 0x00; //extended ext ints

EIMSK = 0x00;

TIMSK = 0x20; //timer interrupt sources

ETIMSK = 0x00; //extended timer interrupt sources

SEI(); //re-enable interrupts

//all peripherals are now initialised

}



void main(void)

{

int T,up,down,a;

  a='d';

init_devices();

  printf("ok!");

while(1)

{

   //printf("%u",T);

}



}

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

发表于 2005-4-2 17:58:48 | 显示全部楼层
电调用MEGA128太浪费了吧.

出0入0汤圆

 楼主| 发表于 2005-4-2 18:22:51 | 显示全部楼层
都说了那是在仪器板飞线出来做的,所以我才买MEAG8来做
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-27 20:14

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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