Motorola 6840 Programmable Timer Module (PTM)

User avatar
Michael
Posts: 36
Joined: Thu Jun 20, 2024 10:34 am
Location: New Zealand / Australia
Contact:

Re: Motorola 6840 Programmable Timer Module (PTM)

Post by Michael »

Editor wrote: Tue Jul 16, 2024 4:59 am I just thought I'd check-in with the Forum, to see what I've missed, before I dive back into some more KiCAD fun. :geek:

I'm glad to see you're making great progress, and solving those ever-arising challenges!
Thanks Greg.

I just uploaded my tutorial videos documenting the process we went through over the last few days (with some creative edits .. :-) )
Thanks again to Emil and Lenzjo for helping to figure out the M6804.
https://www.youtube.com/watch?v=WaJQsC9 ... ApoGQvyBzm
User avatar
epaell
Posts: 150
Joined: Mon Jan 08, 2024 10:06 pm
Location: Sydney

Re: Motorola 6840 Programmable Timer Module (PTM)

Post by epaell »

Fantastic!

It's funny(?) how a single character (added or missing) can cause so much woe! Glad you found it in the end!
User avatar
lenzjo
Posts: 32
Joined: Mon May 06, 2024 11:30 am

Re: Motorola 6840 Programmable Timer Module (PTM)

Post by lenzjo »

Michael wrote: Mon Jul 15, 2024 9:15 pm I appreciate that. Thanks. I plan on doing a few tutorials on this in order to make it easier for the next person. This will be good for the one where I add the 3rd I/O component (the ACIA : real time clock output to the serial port).

Who should I credit? "Lenzjo"?

Nice set of vids, just finished watching them. IRL I'm Clive, online I'm slowly "re-branding" to TLCStuff. Lenzjo was created almost 30yrs ago but it stuck. As you like the 6522 (don't we all?), this afternoon I shall be starting to bring up my MECB SYS-IO card. It has a PS2 kybd port, RTC chip with battery backup, dual uart and a 6522 onboard.
User avatar
Michael
Posts: 36
Joined: Thu Jun 20, 2024 10:34 am
Location: New Zealand / Australia
Contact:

Re: Motorola 6840 Programmable Timer Module (PTM)

Post by Michael »

lenzjo wrote: Tue Jul 16, 2024 1:32 pm MECB SYS-IO card. It has a PS2 kybd port, RTC chip with battery backup, dual uart and a 6522 onboard.
Sounds like a good board. Schematic?
User avatar
lenzjo
Posts: 32
Joined: Mon May 06, 2024 11:30 am

Re: Motorola 6840 Programmable Timer Module (PTM)

Post by lenzjo »

Michael wrote: Tue Jul 16, 2024 1:36 pm Sounds like a good board. Schematic?
I should have the Kicad stuff, inc. gerbers, uploaded to my Github by Friday once I know it's working. In the meantime here's a render:
My-Motorola-IO.jpg
User avatar
Editor
Posts: 225
Joined: Fri Nov 17, 2023 10:36 pm
Contact:

Re: Motorola 6840 Programmable Timer Module (PTM)

Post by Editor »

lenzjo wrote: Tue Jul 16, 2024 9:53 pm In the meantime here's a render:
Looking good! Nice layout. Looks like a great addition to the MECB Card family. :ugeek:
User avatar
djrm
Posts: 42
Joined: Wed Aug 21, 2024 9:40 pm
Location: Rillington / UK
Contact:

Re: Motorola 6840 Programmable Timer Module (PTM)

Post by djrm »

epaell wrote: Mon Jul 15, 2024 11:11 am After a lot of head-scratching (mainly me fighting with the 6840 documentation, fighting with how to do things with a 6502, and then fighting with SMON) I finally got something that works:
Greetings Emil,
I took your PTM code and massaged it to work with Assis09 in MAIM.

I actually built it into the Assis09 / DISASM rom i've built with the verified version of Assist09 and the stock DISASM (No alternative trace) that been testing. This has one small change to move the second command table into the DISASM code area.

I'm using the VCTRSW function to override the ASSIS09 IQR service routine but leaving the PTM initialisation and overwriting it with my own.
Terminal output uses the OUTCH service, Output can be paused with ctrl-x

Notable discovery was that some of Assist09 SWI services actually clear the interrupt mask.
The clocks input of the simulation causes some other interrupt flag bit to be set (I think)
Now that I know that IRQ is working I'll switch my attention to the NMI testing.

The code should be self contained apart from using some Assis09 definitions.
It uses two org statements one for code, the other for ram data.

I'll take this as a starting place to build some code which drives the NMI via the o1 pin
I know a bit more about the PTM now ...
Kind regards, David.

Code: Select all

; 6840 PTR Interrupt demo for Assis09 rom
; demo to generate cyclic interrupt from 6840 and bump a counter in memory
; after initialisation a separate function display the memory content value increasing

timer_val       equ    $f000      ; timer 1 count setting
timer_set       equ    $0142      ; Preset all timers a=$01, b=$42 CRX6=1 (interrupt); CRX1=1 (enable clock)

       org $b100  
;
timer1  equ     *
        org     *+2
timer2  equ     *
        org     *+2                           
timer3  equ     *
        org     *+4
;
tick0   equ     *
        org     *+1
tick1   equ     *
        org     *+1
tick2   equ     *
        org     *+1
tick3   equ     *
        org     *+1


        
        ORG     $Ec00

        LEAX    isr,PCR ; LOAD NEW IRQ HANDLER ADDRESS
        lda     #_IRQ
        swi
        fcb     VCTRSW
        
        lda     #'S'
        jsr     outch       ; Write an "S" to indicate program started
        jsr     ptm_init    ; Initialise the PTM
        andcc   #~$10       ; Enable interrupts
;                rts
loop            
;        andcc   #~$10       ; Enable interrupts
        lda     #$0d
        jsr     outch
        lda     #$0a
        jsr     outch
        lda     #'0'        ; Write the current tick count
        jsr     outch
        lda     #'x'
        jsr     outch
        lda     tick3
        ldb     tick2
        jsr     out4h
        lda     tick1
        ldb     tick0
        jsr     out4h
        lda     #'<'        ; Write the current tick count
        jsr     outch
        pshs    cc
        swi                 ; clobbers irq mask
        fcb 11              ; check for ctrl-x
        tfr     cc,a
        puls    cc
        anda    #1
        beq     loop        ; unless ctrl-x pressed
        swi2
        bra loop
        rts                 ; then return to assis09
        
ptm_init        
        ldd     #timer_val
        std     PTMTM1
        ldd     #timer_set      ; Preset all timers a=$01, b=$42 CRX6=1 (interrupt); CRX1=1 (enable clock)
        sta     PTMC2       ; Write to CR1
        stb     PTMC13 
        clr     PTMC2 
                
        CLR     tick0       ; Reset the tick counter
        CLR     tick1
        CLR     tick2
        CLR     tick3

        lda     PTMSTA      ; Read the interrupt flag from the status register
        lda     #$40
        sta     PTMC13      ; enable interrupt and start timer
        rts 
                            
isr             
        lda     PTMSTA      ; Read the interrupt flag from the status register
        ldx     PTMTM1      ; clear timer interrupt flag
        stx     timer1
        lda     PTMSTA      ; Read the interrupt flag from the status register
        ldx     PTMTM2
        stx     timer2
        lda     PTMSTA     ; Read the interrupt flag from the status register
        ldx     PTMTM3
        stx     timer2
                
        lda     tick0
        adca     #$01
        sta     tick0
        lda     tick1
        adca     #$00
        sta     tick1
        lda     tick2
        adca     #$00
        sta     tick2
        lda     tick3
        adca     #$00
        sta     tick3
        rti

out4h                   ; output as hex digits contents of D register
ZF90E   PSHS D         ; pr xxxx      
        BSR     ZF91A                   
        EXG     B,A                     
        BSR     ZF91A                   
        PULS    PC,D                    

ZF91A   PSHS A         ; pr aa                   
        ASRA                           
        ASRA                           
        ASRA                           
        ASRA                            
        BSR     ZF924                  
        PULS A                         

ZF924   ANDA    #$0F   ; pr x             
        CMPA    #$0A                 
        BCS     ZF92C                
        ADDA    #$07                  
ZF92C   ADDA    #$30                 

outch
        pshs  cc                ; preserve irq mask which is set by assis09
        SWI                     ; Call ASSIST09 monitor function
        FCB     OUTCH           ; Service code byte
        puls  cc
        RTS

User avatar
epaell
Posts: 150
Joined: Mon Jan 08, 2024 10:06 pm
Location: Sydney

Re: Motorola 6840 Programmable Timer Module (PTM)

Post by epaell »

That's great to hear :-)
Post Reply