ECT Input for hcs12dp256

Started by punning_clan August 18, 2003
Hi everyone.
I am trying to write some simple polling code to read a PWM signal on
any of the PT0 to PT7 Input capture lines on my hcs12dp256.
I have searched this archive and have tried a few suggestions but to
no avail.

Does anyone have some C or asm code (preferably C) that sets all PT0
to PT7 pins to input capture and then sits in an infinate loop
polling those pins for any voltage change (high or low) and then
simply records the fact or perhaps the TC4 value.

I have been banging my head against a wall trying to get this working.

My setup include Imagecraft and NoICE using a P&E Multisink USB BDM.

I am going to use interupt code to write my app after this, I just
need to see this thing reading a signal.

All the best.

-Ian



Here is a code that I used to capture PWM duty and then display that
value

Capture part:
;---------------------------------
IC4Int
ldd TC4
pshd ;Save momentarily

ldaa cap4Flag ;Check if 1st or 2nd capture
bne Second4Cap ;If flag is set then it is
2nd falling edge

puld
std IC4Var1 ;1st Capture
movb #1,cap4Flag ;Set flag for 2nd capture

;Change capture edge to capture from high to low
ldaa TCTL3
anda #%11111100 ;masked lower 2 bits
adda #%00000010
staa TCTL3
bra IC4ex ;Wait until next capture

Second4Cap
puld
subd IC4Var1 ;Subtract from 1st Capture
std IC4Var2 ;Result in Var2
clr cap4Flag

;Change capture edge to capture from low to high
ldaa TCTL3
anda #%11111100 ;masked lower 2 bits
adda #%00000001
staa TCTL3

IC4ex
movb #%00010000,TFLG1 ;clear input interrupt flag
rti

;---------------------------------
IC5Int
ldd TC5
pshd ;Save momentarily

ldaa cap5Flag ;Check if 1st or 2nd capture
bne Second5Cap ;If flag is set then it is
2nd falling edge

puld
std IC5Var1 ;1st Capture
movb #1,cap5Flag ;Set flag for 2nd capture

;Change capture edge to capture from high to low
ldaa TCTL3
anda #%11110011 ;masked lower 2 bits
adda #%00001000
staa TCTL3
bra IC5ex ;Wait until next capture

Second5Cap
puld
subd IC5Var1 ;Subtract from 1st Capture
std IC5Var2 ;Result in Var2
clr cap5Flag

;Change capture edge to capture from Low to high
ldaa TCTL3
anda #%11110011 ;masked lower 2 bits
adda #%00000100
staa TCTL3

IC5ex
movb #%00100000,TFLG1 ;clear input interrupt flag
rti

END

Display Part:

DispVelocity
ldx delay_timer
bne DispVelex

;Display IC4 captured value
; sei
ldx #IC4Var2
jsr HTOD ;Convert 16 bit to ASCII
; cli

ldx #MotorMSG3
jsr OutStr0
jsr P5DEC ;Display ASCII value to
Terminal
ldx #MotorMSG5
jsr OutStr0 ;Display IC5 captured value
; sei
ldx #IC5Var2
jsr HTOD ;Convert 16 bit to ASCII
; cli

ldx #MotorMSG4
jsr OutStr0
jsr P5DEC ;Display ASCII value to
Terminal
ldx #MotorMSG5
jsr OutStr0

ldaa #$D ;Send CR character
jsr SerOutput0

movw #122*2,delay_timer

DispVelex
rts --- In , "punning_clan" <punning_clan@y...>
wrote:
> Hi everyone.
> I am trying to write some simple polling code to read a PWM signal
on
> any of the PT0 to PT7 Input capture lines on my hcs12dp256.
> I have searched this archive and have tried a few suggestions but
to
> no avail.
>
> Does anyone have some C or asm code (preferably C) that sets all
PT0
> to PT7 pins to input capture and then sits in an infinate loop
> polling those pins for any voltage change (high or low) and then
> simply records the fact or perhaps the TC4 value.
>
> I have been banging my head against a wall trying to get this
working.
>
> My setup include Imagecraft and NoICE using a P&E Multisink USB BDM.
>
> I am going to use interupt code to write my app after this, I just
> need to see this thing reading a signal.
>
> All the best.
>
> -Ian