智能车制作
标题:
ad 问题 在线等答案。
[打印本页]
作者:
memorygarden
时间:
2008-7-16 19:21
标题:
ad 问题 在线等答案。
ATD0CTL5_SCAN = 1; 开ad连续采集以后,程序就无故跳出了。不知道是怎么回事。请高手指点。谢谢!<br>
作者:
whut_wj
时间:
2008-7-16 20:48
标题:
Re:ad 问题 在线等答案。
把AD程序发上来
作者:
memorygarden
时间:
2008-7-16 20:53
标题:
Re:ad 问题 在线等答案。
ATD0CTL2=0xC0;<br>ATD0CTL3=0x08<br>ATD0CTL4=0x81; <br> <br>ATD0CTL5=0xA0;<br>ATD0DIEN=0x00; <br><br><br>现在ad能跑了。。。可是转换又出毛病了。。。郁闷。。。。。出来的都不知道是什么东西。。。。<br>
作者:
whut_wj
时间:
2008-7-16 20:59
标题:
Re:ad 问题 在线等答案。
<
>#include <hidef.h> /* common defines and macros */<BR>#include <mc9s12dg128.h> /* derivative information */<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"</P><P>void ADCInit()<BR>{<BR> ATD0CTL2=0xC0; //AD模块上电, 快速清零, 无等待模式, 禁止外部触发, 中断禁止<BR> ATD0CTL3=0x20; // 每个序列4次转换, No FIFO, Freeze模式下继续转换<BR> ATD0CTL4=0x83; // 8位精度, 2个时钟, ATDClock=[BusClock*0.5]/[PRS+1] ; PRS=3, divider=8<BR> ATD0CTL5=0xA0; //右对齐无符号,单通道采样,通道0 <BR> ATD0DIEN=0x00; // 禁止数字输入<BR>}</P><P><BR>void main(void) { <BR> ADCInit(); //AD初始化<BR> DDRB = 0xFF;<BR> PORTB = 0x00; <BR> /* put your own code here */<BR> EnableInterrupts;</P><P> for(;;) { <BR> while(!ATD0STAT1_CCF0); //等待转换结束 <BR> PORTB = (byte)ATD0DR0; //在B口显示转换值<BR> } /* wait forever */<BR> /* please make sure that you never leave this function */<BR>}<BR></P><P><FONT face=黑体 size=3>你找个恒压信号,比如3V,看看稳定情况先.</FONT></P>
作者:
memorygarden
时间:
2008-7-16 21:34
标题:
Re:ad 问题 在线等答案。
#include <hidef.h> /* common defines and macros */<br>#include <mc9s12dg128.h> /* derivative information */<br>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"<br><br> /*pin connect <br> pin_PT0 = row_AYNS row fresh after 59.4us <br> pin_PT1 = frame_AYNS frame fresh after 19.75ms or 19.80ms<br> */ <br>byte frame[40][60], ATDResult;<br>int row=0,colum=0;<br>int rowcount = 0 ,res = 0 ,width=0,height=0, xx, xxrow = 0;<br>int frameNum = 0 ;<br>int sendCounter=0;<br>int mg = 0;<br><br>void Init_SCI(void)<br>{<br> SCI0BD=208;<br> SCI0CR1=0x00;<br> SCI0CR2=0x0C;<br>}<br><br>void delay(int t){<br> int i, j;<br> for(i = 0; i < t; i++)<br> for(j = 0; j < 125; j++);<br>}<br><br>void tx_sci(char tx_d)<br>{<br> while(SCI0SR1_TC!=1);<br> while(SCI0SR1_TDRE!=1);<br> SCI0DRL=tx_d;<br>}<br><br>void sendframe(){<br> int i, j;<br> for(i = 0; i < 40; i++)<br> for(j = 0; j < 60; j++)<br> tx_sci(frame<i>[j]);<br> <br> for(i = 0; i < 60; i++)<br> tx_sci(0xff); <br>}<br><br>void higherFreqence(void) //×ü??3??μμ?32M<br>{<br> REFDV=3;//2<br> SYNR=7; //5<br> while(0==CRGFLG_LOCK);<br> CLKSEL=0x80;<br>}<br><br>void setATD(void){<br> ATD0CTL2=0xC0; //AD?£?éé?μ?, ?ì?ù??á?, ?Tμè′y?£ê?, ???1ía2?′¥·¢, ?D?????1<br> ATD0CTL3=0x20; // ????DòáD4′?×a??, No FIFO, Freeze?£ê????ìD?×a??<br> ATD0CTL4=0x83; // 8?????è, 2??ê±?ó, ATDClock=[BusClock*0.5]/[PRS+1] ; PRS=3, divider=8<br> ATD0CTL5=0xA0; //óò?????T·?o?£?μ¥í¨μà2é?ù£?í¨μà0<br> ATD0DIEN=0x00; // ???1êy×?ê?è?<br> } <br> void set_ic0(void) {<br> TIOS_IOS0=0; <br> TCTL4_EDG0B=1;<br> TCTL4_EDG0A=0; //capture falling edge<br> TIE_C0I=1;<br> TSCR1_TEN=1;<br> TSCR2_PR = 0;<br> } <br> void set_ic1(void) {<br> TIOS_IOS1=0; <br> TCTL4_EDG1B=1;<br> TCTL4_EDG1A=0; //capture falling edge<br> TIE_C1I=1;<br> TSCR1_TEN=1;<br> TSCR2_PR = 0;<br> }<br>void Init_frame(){<br> int i, j;<br> for(i=0;i<40;i++)for(j=0;j<60;j++)frame<i>[j] = 0;<br>}<br>void main(void) {<br> Init_frame();<br> DisableInterrupts; <br> DDRB = 0XFF;<br> PORTB = 0Xff;<br> higherFreqence();<br> Init_SCI();<br> set_ic0();<br> set_ic1();<br> setATD();<br> EnableInterrupts; <br> TIE_C0I = 0X00;<br> TIE_C1I = 0X01;<br> for(;;) { <br> if(mg){<br> //HERE DO GAO();<br> sendframe();<br> mg = 0;<br> xxrow = row = 0;<br> Init_frame();<br> TIE_C1I = 0X01;<br> }<br> }<br>}<br><br><br>void interrupt rowFresh(void){ // enter this interrupt function after per 64us later<br> xxrow++;<br> if(xxrow >= 40 && xxrow <= 200){<br> rowcount++;<br> if(rowcount == 4){<br> rowcount = 0;<br> for(xx = 0; xx < 60; xx++){<br> while(!ATD0STAT1_CCF0);<br> frame[row][xx] = (byte)ATD0DR0L; <br> }<br> row++;<br> }<br> } <br> // tx_sci(0); <br> if(xxrow > 200){<br> mg = 1;<br> TIE_C0I = 0X00; //1?DD?D??<br> } <br>}<br><br>void interrupt frameFresh(void){ // enter this interrupt funtioin per 20ms later<br> // tx_sci(1);<br> TIE_C1I = 0X00; //1?3??D??<br> TIE_C0I = 0X01; //?aDD?D?? <br>} <br><br><br><br><br><br><br><br><br><br><br><br>这个是我的程序。麻烦您看一下,为什么发出来的东西乱七八糟的呢。还有3场的空白。<br>
作者:
memorygarden
时间:
2008-7-16 21:58
标题:
Re:ad 问题 在线等答案。
这是我得到的 二进制的图<br><br><br><br>0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 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 0 0 0 0 0 0 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 <br>0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 <br>0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <br>0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <br>0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <br>0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 <br>1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 <br>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 <br><br><br><br><br><br><br><br><br>乱的不成样子。。。。。。<br>
作者:
memorygarden
时间:
2008-7-16 23:01
标题:
Re:ad 问题 在线等答案。
自己d。。。。着急中。。请高人指点
作者:
whut_wj
时间:
2008-7-17 04:15
标题:
Re:ad 问题 在线等答案。
<
> for(xx = 0; xx < 60; xx++){<BR> while(!ATD0STAT1_CCF0);<BR> frame[row][xx] = (byte)ATD0DR0L; <BR> }</P><P>取不到这些点的,取点要用示波器看.</P>
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2