MyCode: SECTIONmain:Entry: LDS #__SEG_END_SSTACK ; Initialise Stack Pointer BSET DDRT, #$01 ; Enable port T output BSET TIOS, #%00000010 ; Set TIOS (Set TC1 to output compare) BSET PTT, #$01 ; Set Port T to 1 MOVB #$80, TSCR1 ; Timer enable LDD TCNT ; Set TC1 to triger in 1ms ADDD #256 STD TC1 BSET TFLG1, #%00000010 ; Reset interrupt flag BSET TIE, #$02 ; Enable Interrupt for TC1 CLI SPIN: WAI ; Wait for interrupt then loop forever BRA SPIN ISR_TC1: LDAA PTT EORA #$01 STAA PTT ; Set output to 1 LDD TC1 ; Set TC1 to trigger in another 1ms ADDD #256 STD TC1 LDAA #$02 ; Reset the flag STAA TFLG1 RTI
; code sectionMyCode: SECTIONmain:Entry: LDS #__SEG_END_SSTACK ; Initialise Stack Pointer MOVB #$10, DDRB ; Enable port A and B output MOVB #$10, PORTB ; Set Port B to 1 and A to 0 MOVB #$01, DDRA MOVB #$00, PORTA BSET TIOS, #%00000010 ; Set TIOS (Set TC1 to output compare) MOVB #$80, TSCR1 ; Timer enable LDD TCNT ; Set TC1 to triger in 1ms ADDD #512 ; Start first sync in 64microS STD TC1 BSET TFLG1, #%00000010 ; Reset interrupt flag BSET TIE, #$02 ; Enable Interrupt for TC1 LDX #$0000 ; Set linenubmer to 240 STX LINENUMBER LDAA #$01 ; Set first sync to be STAA SYNCON LDAA #$00 STAA SYNCOFF LDAA #$01 ; Start with horizontal sync STAA DDRA LDAA #$00 STAA PORTA CLI ;************************ Loop Forever ************************ SPIN: BCLR FLAG, 1 BRCLR FLAG, 1, * ; Wait for interrupt ;********************* Output Video Data ********************* LDX LINENUMBER CPX #2 ; If line number is <= 2 ;22 BLE NOVIDEO ; or >= 5 display no video ;308 CPX #5 BGE NOVIDEO ; Else LDAB #$1E ; Wait for 375nSCOUNTER: DBNE B, COUNTER LDAA #$FF ; Display logic 1 (white) STAA PORTB LDAB #$2C ; Wait for 5.5uSCOUNTER2: DBNE B, COUNTER2 LDAA #$00 ; Display 0 again STAA PORTBNOVIDEO: BRA SPIN ; Loop forever ;**************************************************************ISR_TC1: ; ;************************************************************** LDD TC1 ; Set TC1 to trigger in another 64us ADDD #512 STD TC1 MOVB SYNCON, PORTA ; Start the sync pulse ;4 LDX LINENUMBER ;1 INX ; Increment line number ;1 STX LINENUMBER ;1 CPX #6 ; If the line number is 6 ;2 310 BNE DEC1 ;3/1 ;********** Create Vertical Sync Pulse ************************ LDAA #$01 ;1 STAA SYNCON ; Sync pulse will be short Hi ;1 LDAA #$00 ;1 STAA SYNCOFF ;1 BRA ENDISR ;3;************************************************************** DEC1: LDX LINENUMBER ; If line number is 9 create ;1 CPX #9 ; a horizontal sync ;2 313 BNE ENDISR ;3/1 ;********** Create Horizontal Sync Pulse *********************** HORSYNC: LDAA #$00 ;1 STAA SYNCON ; Sync pulse will be short Lo ;1 LDAA #$01 ;1 STAA SYNCOFF ;1 LDX #$0001 ; Set line number back to 0 ;1 STX LINENUMBER ;1 ;************************************************************** ENDISR: NOP ;1 NOP ; Add waits to create sync ;1 NOP ; pulse of about 5 microS ;1 NOP ;1 NOP ;1 NOP ;1 NOP ;1 MOVB SYNCOFF, PORTA ; End the sync pulse ;4 BSET FLAG, 1 ; Set the flag to keep main ; code in wait state. LDAA #$02 ; Reset the TC7 flag STAA TFLG1 RTI
Steve wrote:kef may have something. There may be other interrupts in the system.If this is IRQ or XIRQ then they will have a higher priority than the timer interrupt. Now since you set the time for the next timer interrupt based on the "last" output compare value there is the possibility that you may not reach the ISR before the "next" time that you store. If this happens the OC will have a "next" value that is actually "in the past". The timer ISR will not occur before until the timer loops round again.If this is the case the WAI is kind of a red-herring since it is simply adding a period where all interrupts are temporarily ignored which increases the possibility that a pending higher level interrupt can occur. Any other long instruction would have the same effect.Check that your IRQ and XIRQ pins are pulled to VDD by a suitable resistor.
;**************************************************************;* Set PLL *;* PLLCLK = 2*OSCFREQ*(SNYR+1)/(REFDV+1) *;* BUSFREQ = PLLCLK/2 *;* SYNR = 2 & REFDV = 1 to give busfreq = 24MHz *;************************************************************** MOVB #$02, SYNR ;Set values of registers MOVB #$01, REFDV MOVB #$00, CLKSEL MOVB #$D1, PLLCTL NOP ;Wait for clock to lock NOP PLLWAIT: LDAA CRGFLG BITA #$08 ;Check if clock has locked BEQ PLLWAIT LDAA CLKSEL ;If clock has locked set PLL ORAA #$E0 STAA CLKSEL;**************************************************************
LDD TC1 ; Set TC1 to trigger in another 1ms ADDD #256 STD TC1; We set fast clear mode, so don't need this either.