狂郁闷,虽然是兴趣,但是这么一个小东西却把我整坏了,求助无门,只好到网上来碰碰运气了,希望有爱好者能帮我解决问题,那我回家就有望了,谢谢先
这个程序用AD模块采集电机电压,AD模块没什么大问题,用ECT模块通道1采集车速,当ECT通道1没有采集到上升沿时,不进入中断,则ECT模块发送00,表示没有车速,当进入中断又只有一个上升沿时,要判断时钟溢出几次,如果大于等于2次时,我们发送FF,表示车速很低,当溢出次数为0和1时分别进入不同的计算模块,把俩个上升沿之间的时钟计数算出来,然后发送,现在出现的问题是,我用PWM输出周期为40ms的占空比为50%的方波作为ECT通道1的输入,它输出的值居然有FF,00,还有251C,251C折算过来是38ms跟,40很贴近,可是为什么值会是不一样呢,我把那俩句LHLS都去掉的话,输出的值倒是非常稳定,都是251C,我现在也搞不清楚问题在哪,非常烦。
;**************************************************************
;* This stationery is serves as the framework for a *
;* user application. For a more comprehensive program that *
;* demonstrates the more advanced functionality of this *
;* processor, please see the demonstration applications *
;* located in the examples subdirectory of the *
;* Metrowerks CodeWarrior for the HC12 Program directory *
;**************************************************************
;//////////// export symbols
XDEF Entry, main
; we use export 'Entry' as symbol. This allows us to
; reference 'Entry' either in the linker .prm file
; or from C/C++ later on
;////////////////// include derivative specific macros
INCLUDE 'mc9s12dt128.inc'
; ////////////////variable/data section
MY_EXTENDED_RAM: SECTION
; //////////////////Insert here your data definition. For demonstration, temp_byte is used.
TIME1 ds.b 1
TIME2 ds.b 1
COUNT1 ds.b 1
COUNT2 ds.b 1
;//////////////// code section
MyCode: SECTION
main:
Entry:
SEI
MOVB #$01,DDRA
MOVB #$01,PORTA
LDS #$1100 ;SP=10FF
ECTInit:
MOVB #$0,TIOS
MOVB #$04,TCTL4 ;4
MOVB #$02,TIE ; 02
MOVB #$85,TSCR2 ;85
MOVB #$80,TSCR1 ;80
MOVB #$0,COUNT1
MOVB #$0,COUNT2
PWMInit:MOVB #$00,PWME
MOVB #$00,PWMCTL
MOVB #$66,PWMPRCLK ; 66
MOVB #$FF,PWMCLK ; FF
MOVB #$7D,PWMSCLA ; 7D
MOVB #$7D,PWMSCLB
MOVB #$FF,PWMPOL ;FF//PWM输出起始为高电平
MOVB #$00,PWMCAE
MOVB #$13,PWMPER0
MOVB #$09,PWMDTY0
MOVB #$01,PWME
ADInit:
MOVB #$0C0,ATD0CTL2
MOVB #$8,ATD0CTL3
MOVB #$83,ATD0CTL4
MOVB #$A0,ATD0CTL5
MOVB #$0,ATD0DIEN
SCI0Init:MOVB #$34,SCI0BDL
MOVB #$0,SCI0CR1
MOVB #$0C,SCI0CR2 ;If #$FC, enable send and receive interrupt
LDAA SCI0SR1
CLI
SENT:
LDD #$0
STD $100E
SENT10: BRCLR ATD0STAT1,#$1,SENT10
SENT11: BRCLR SCI0SR1,#$80,SENT11
MOVB ATD0DR0L,SCI0DRL
SENT12: BRCLR SCI0SR1,#$80,SENT12
MOVB ATD0DR0H,SCI0DRL
SENT51: BRCLR SCI0SR1,#$80,SENT51
MOVB $100E,SCI0DRL
SENT52: BRCLR SCI0SR1,#$80,SENT52
MOVB $100F,SCI0DRL
COM PORTA
N: JMP SENT
DELAY:
PSHA
PSHB
PSHX
PSHY
LDX #$500
DELAY1: LDY #$200
DELAY2: DEY
BNE DELAY2
DEX
BNE DELAY1
PULY
PULX
PULB
PULA
RTS
CNT_OVERFOLW: ;ECT通道1时钟溢出中断子程序
SEI
INC COUNT1 ;COUNT1用来记录溢出次数
MOVB #$80,TFLG2
CLI
RTI
ECT1INTERRUPT:
SEI
INC COUNT2 ;通道1上升沿次数
BRSET COUNT2,#$01,CACU1 ;通道1为1次时跳转到CACU1
BRSET COUNT2,#$02,CACU3 ;COUNT2不为1时跳转到CACU3
BRA RTN ;RTN返回子程序
CACU1:
LDD TC1
STD $100A
LDD COUNT1
SUBD #$02 ;
LBLS CACU2 ;判断通道1溢出次数是否大于2,大于等于2则跳转(本来用的是LBHS,但怎麽都不对),否则返回
BRA RTN
CACU2: ;当大于2时,把FFFF放到$100E和$100F单元中,待返回主程序时发送
LDD #$FFFF
STD $100E
MOVB #$0 ,COUNT1 ;把溢出次数和通道1扑捉到的上升沿次数清零,为下次中断做准备
MOVB #$0, COUNT2
BRA RTN
CACU3: ;当有俩个上升沿时进入该程序
LDD TC1
STD $100C ;把第二次上升沿到来时的TCNT中的值放入$100C以备计算
LDD COUNT1
SUBD #$02
LBLS CACU2 ;判断通道1溢出次数是否大于2,大于等于2则跳转(本来用的是LBHS,但怎麽都不对),否则继续
BRSET COUNT1,#$01,CACU4 ;当溢出次数为1次时放到CACU4中进行计算,当没有溢出时接下去运算
LDD $100C
SUBD $100A ;COUNT1=0
STD $100E
MOVB #$0 ,COUNT1
MOVB #$0, COUNT2
BRA RTN
CACU4: ;COUNT1=1
LDD #$FFFF
SUBD $100A
ADDD #$1
ADDD $100C
STD $100E
MOVB #$0 ,COUNT1
MOVB #$0, COUNT2
RTN:
MOVB #$02,TFLG1 中断子程序,进行清空标志位
CLI
RTI
ORG $FFEC
FDB ECT1INTERRUPT ;定义通道1上升沿中断入口
ORG $FFDE
FDB CNT_OVERFOLW ;定义通道1时钟计数器溢出中断入口
[此贴子已经被作者于2008-1-16 21:00:53编辑过]
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |