Shereef Sayed

how to properly configure the PIT for the 9S12XDP512?

Discussion created by Shereef Sayed on Nov 15, 2006
Latest reply on Nov 20, 2006 by Steve Mcaslan
I am trying to set up the Periodic Interrupt Timer for channel 0 so that every 1 sec. the cpu is interrupted. After pouring over documentation and online forums, I still cannot make it work. I believe that I understand how the PIT works, and how to set up interrupt vectors, but I can not understand what I am doing wrong. Below is my code, written with CodeWarrior 4.5:

/* PRM file */
VECTOR ADDRESS 0xFF7A DTYISR

/* ASM file */
XDEF Entry, main, DTYISR

; code section
MyCode: SECTION
main:
Entry:
LDS #__SEG_END_SSTACK ; initialize the stack pointer
CLI
; PORTA is connected to LEDs which helps me determine if the ISR was called
MOVB #$FF, DDRA  ; set PORTA as output
MOVB #$FF, PORTA ; turn on the LEDs
MOVB #$01, DDRP ; set PORTP[0] as output
Loop0:
MOVB #$70, INT_CFADDR ; point to the interrupt jump vector containing the PIT channels
MOVB #$04, INT_CFDATA5 ; set interrupt priority level 4 for vector $FF7A (PIT0)

MOVB #$01, PWMCLK ; set the PWM channel to use the scaled clock 
MOVB #$01, PWMPRCLK ; pre-scale the clock
MOVB #$0A, PWMSCLA ; scale the pre-scaled clock
MOVB #$A0, PWMPER0 ; set the PWM period
MOVB #$50, PWMDTY0 ; set the PWM duty cycle
MOVB #mPWME_PWME0, PWME ; enable PWM channel 0
LDAB #$50
STAB PWMDTY0 ; the PWM result is a 1250Hz square wave, 50% duty cycle

MOVB #$FF, PITMTLD0 ; set the micro timer value
MOVW #$F424, PITLD0 ; set the timer counter
MOVB #$00, PITMUX ; set the mux to use channel 0 (for completeness)
MOVB #$01, PITCE ; enable PIT channel 0
MOVB #$01, PITINTE ; enable interrupts for channel 0
MOVB #$80, PITCFLMT ; finally, enable the PIT module
Loop1: BRA Loop1

DTYISR:
ADDB #$30 ; I realize that AccB gets pushed onto the stack before the PC points to the ISR, but this is just a test
STAB PWMDTY0 ; update the duty cycle
CLR PORTA ; turn off PORTA[7..0]
MOVB #$01, PITTF ; clear the PIT interrupt flag for channel 0
RTI
/* END */
I have seen other similar posts on the forum, and I have applied some of those solutions to my problem, but nothing has worked. However, there is one that I don't understand, and I wonder if it might apply to my problem? What is the purpose of the Pull-Up Control Register (PUCR) and can it affect the behavior of interrupts?

Thanks for your help.

Outcomes