共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网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |