这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 2407,AD 高手请帮我看看2407 自带AD采值程序的问题

共2条 1/1 1 跳转至

2407,AD 高手请帮我看看2407 自带AD采值程序的问题

院士
2006-09-17 18:14:16     打赏
2407,AD 高手请帮我看看2407 自带AD采值程序的问题



关键词: 高手     帮我     看看     自带     采值     程序     问题    

院士
2006-12-22 22:43:00     打赏
2楼
问 我现在用2407的自带AD采值
    思路是利用Timer1的周期中断,产生AD启动标志
    现在的问题是 采值移位后都是108左右(十进制)
    好像AD没有工作 真是奇怪
    请看看程序  提意见
    谢谢!




       /*  test.c */

#include "C2407.h"   

volatile unsigned int  *Pointer_AD;
unsigned int SampleAverage_ADvalue=0;
unsigned int Sample_Max=0;
unsigned int Sample_Min=0;
unsigned int First_Flag=0;
unsigned int start_ADC=0;  
void disable()
{
   asm(" setc INTM");
}  

void enable()
{
   asm(" clrc INTM");
}
  
void Sys_Init()
{
    asm(" clrc SXM");
    asm(" clrc OVM");
    asm(" clrc CNF");
    SCSR1=0x86FF;       /* system clcock is 10M */
    WDCR=0x00E8;
    IMR=0x0002;   /* time 1 period interrupt */
    IFR=0xFFFF;
    WSGR=0x0000;  
    First_Flag=0;
}   
void Delay(unsigned int x)
{
    unsigned int i,j;
    for(i=0;i<x;i++)
    {
        for(j=0;j<5;j++)
        {
            asm(" nop");
            asm(" nop");
            asm(" nop");
            asm(" nop");
            asm(" nop");
            asm(" nop");   
        }
    }   
}

void ADC_TIMER1_Init()
{
    /* EVA Timer 1 period IFR 1ms */
    EVAIMRA |=0x0080;
    EVAIFRA = 0xFFFF;   /*  */
    
    T1CON=0x160C;
    T1PER=0x061A;
    T1CNT=0x0000;
    
    GPTCONA = 0x0000;  /* EVA Timer 1 enable ADC */
    
    /**************************/
    
    /***************  ADC  ********/   
    ADCTRL1 = 0x4000;                 /* reset ADC module */
    asm(" nop");                   
    ADCTRL1 = 0x3010;                 /* configure ADCTRL1 register */
    asm(" nop");  
    ADCTRL2 = 0x4200;
    asm(" nop");
    ADCTRL2 = 0x2000;
    asm(" nop");      
    MAXCONV = 0x0000;                 
    asm(" nop");    
    CHSELSEQ1 = 0x0000;
    asm(" nop");  
   
    /******************************/
    
    
  Delay(1000);

}
     
void ADC_Enable()
{
    T1CON  |=0x0040;
}    

interrupt void INT2_ISR(void)
{   
       if(PIVR==0x0027)
       {
          start_ADC=1;
       }   
          T1CNT=0x0000;
          EVAIFRA =0xFFFF;
          ADCTRL2 |= 0x2000;      /* set SOC_SEQ1 bit to start ADC */
          enable();              
}            

                                     
void interrupt nothing()
{
    enable();
    return;
}
    
main()
{
   disable();
   Sys_Init();
   ADC_TIMER1_Init();
   enable();  
   ADC_Enable();
   
   while(1)
   {
     asm(" nop" );
     if(start_ADC==1)
       {  
          asm(" nop" );
          ADCTRL2 |= 0x2000;  
          asm(" nop" );
          asm(" nop" );
          asm(" nop" );
          while(ADCTRL2 &0x1000);
          Pointer_AD=&RESULT0;  
          asm(" nop" );
          asm(" nop" );
          asm(" nop" );
             
          SampleAverage_ADvalue=*Pointer_AD>>6;
          asm(" nop" );
          asm(" nop" );
          asm(" nop" );
          if(First_Flag==0) {Sample_Max=Sample_Min=SampleAverage_ADvalue; First_Flag=1;}  
          if(SampleAverage_ADvalue>=Sample_Max)    Sample_Max=SampleAverage_ADvalue;
          if(SampleAverage_ADvalue<Sample_Min)    Sample_Min=SampleAverage_ADvalue;
          ADCTRL2 |= 0x4000;    /* conv00 */  
          start_ADC=0;       

  
        }       
    }                                        
}

     
    .title    "vectors.asm"
    .ref    _c_int0,_nothing,_INT2_ISR
    .sect    ".vectors"


reset:        b    _c_int0
int1:        b    _nothing
int2:        b    _INT2_ISR
int3:        b    _nothing
int4:        b    _nothing
int5:        b    _nothing
int6:        b    _nothing
reserved:    b    _nothing
sw_int8:    b    _nothing
sw_int9:    b    _nothing
sw_int10:    b    _nothing
sw_int11:    b    _nothing
sw_int12:    b    _nothing
sw_int13:    b    _nothing
sw_int14:    b    _nothing
sw_int15:    b    _nothing
sw_int16:    b    _nothing
trap:        b    _nothing
nmint:        b    _nothing
emu_trap:    b    _nothing
sw_int20:    b    _nothing
sw_int21:    b    _nothing
sw_int22:    b    _nothing
sw_int23:    b    _nothing
1: 上述程序的更正:我现在用2407的自带AD采值
    思路是利用Timer1的周期中断,产生AD启动标志
    现在的问题是 采值移位后都是108左右(十进制)
    好像AD没有工作 真是奇怪
    请看看程序  提意见
    谢谢!




       /*  test.c */

#include "C2407.h"   

volatile unsigned int  *Pointer_AD;
unsigned int SampleAverage_ADvalue=0;
unsigned int Sample_Max=0;
unsigned int Sample_Min=0;
unsigned int First_Flag=0;
unsigned int start_ADC=0;  
void disable()
{
   asm(" setc INTM");
}  

void enable()
{
   asm(" clrc INTM");
}
  
void Sys_Init()
{
    asm(" clrc SXM");
    asm(" clrc OVM");
    asm(" clrc CNF");
    SCSR1=0x86FF;       /* system clcock is 10M */
    WDCR=0x00E8;
    IMR=0x0002;   /* time 1 period interrupt */
    IFR=0xFFFF;
    WSGR=0x0000;  
    First_Flag=0;
}   
void Delay(unsigned int x)
{
    unsigned int i,j;
    for(i=0;i<x;i++)
    {
        for(j=0;j<5;j++)
        {
            asm(" nop");
            asm(" nop");
            asm(" nop");
            asm(" nop");
            asm(" nop");
            asm(" nop");   
        }
    }   
}

void ADC_TIMER1_Init()
{
    /* EVA Timer 1 period IFR 1ms */
    EVAIMRA |=0x0080;
    EVAIFRA = 0xFFFF;   /*  */
    
    T1CON=0x160C;
    T1PER=0x061A;
    T1CNT=0x0000;
    
    GPTCONA = 0x0000;  /* */
    
    /**************************/
    
    /***************  ADC  ********/   
    ADCTRL1 = 0x4000;                 /* reset ADC module */
    asm(" nop");                   
    ADCTRL1 = 0x3010;                 /* configure ADCTRL1 register */
    asm(" nop");  
    ADCTRL2 = 0x4200;
    asm(" nop");
    ADCTRL2 = 0x2000;
    asm(" nop");      
    MAXCONV = 0x0000;                 
    asm(" nop");    
    CHSELSEQ1 = 0x0000;
    asm(" nop");  
   
    /******************************/
    
    
  Delay(1000);

}
     
void ADC_Enable()
{
    T1CON  |=0x0040;
}    

interrupt void INT2_ISR(void)
{   
       if(PIVR==0x0027)
       {
          start_ADC=1;
       }   
          T1CNT=0x0000;
          EVAIFRA =0xFFFF;
          enable();              
}            

                                     
void interrupt nothing()
{
    enable();
    return;
}
    
main()
{
   disable();
   Sys_Init();
   ADC_TIMER1_Init();
   enable();  
   ADC_Enable();
   
   while(1)
   {
     asm(" nop" );
     if(start_ADC==1)
       {  
          asm(" nop" );
          ADCTRL2 |= 0x2000;  
          asm(" nop" );
          asm(" nop" );
          asm(" nop" );
          while(ADCTRL2 &0x1000);
          Pointer_AD=&RESULT0;  
          asm(" nop" );
          asm(" nop" );
          asm(" nop" );
             
          SampleAverage_ADvalue=*Pointer_AD>>6;
          asm(" nop" );
          asm(" nop" );
          asm(" nop" );
          if(First_Flag==0) {Sample_Max=Sample_Min=SampleAverage_ADvalue; First_Flag=1;}  
          if(SampleAverage_ADvalue>=Sample_Max)    Sample_Max=SampleAverage_ADvalue;
          if(SampleAverage_ADvalue<Sample_Min)    Sample_Min=SampleAverage_ADvalue;
          ADCTRL2 |= 0x4000;    /* conv00 */  
          start_ADC=0;       

  
        }       
    }                                        
}

     
    .title    "vectors.asm"
    .ref    _c_int0,_nothing,_INT2_ISR
    .sect    ".vectors"


reset:        b    _c_int0
int1:        b    _nothing
int2:        b    _INT2_ISR
int3:        b    _nothing
int4:        b    _nothing
int5:        b    _nothing
int6:        b    _nothing
reserved:    b    _nothing
sw_int8:    b    _nothing
sw_int9:    b    _nothing
sw_int10:    b    _nothing
sw_int11:    b    _nothing
sw_int12:    b    _nothing
sw_int13:    b    _nothing
sw_int14:    b    _nothing
sw_int15:    b    _nothing
sw_int16:    b    _nothing
trap:        b    _nothing
nmint:        b    _nothing
emu_trap:    b    _nothing
sw_int20:    b    _nothing
sw_int21:    b    _nothing
sw_int22:    b    _nothing
sw_int23:    b    _nothing

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]