共2条
1/1 1 跳转至页
2407,AD 高手请帮我看看2407 自带AD采值程序的问题

问
我现在用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
思路是利用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 跳转至页
回复
有奖活动 | |
---|---|
【EEPW电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
“我踩过的那些坑”主题活动——第001期 | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【我踩过的那些坑】STM32的硬件通讯调试过程的“坑”被打赏50分 | |
【我踩过的那些坑】晶振使用的问题被打赏100分 | |
【我踩过的那些坑】电感选型错误导致的处理器连接不上被打赏50分 | |
【我踩过的那些坑】工作那些年踩过的记忆深刻的坑被打赏10分 | |
【我踩过的那些坑】DRC使用位置错误导致的问题被打赏100分 | |
我踩过的那些坑之混合OTL功放与落地音箱被打赏50分 | |
汽车电子中巡航控制系统的使用被打赏10分 | |
【我踩过的那些坑】工作那些年踩过的记忆深刻的坑被打赏100分 | |
分享汽车电子中巡航控制系统知识被打赏10分 | |
分享安全气囊系统的检修注意事项被打赏10分 |