6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 8:35 am

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Thu Nov 22, 2012 7:06 am 
Offline

Joined: Thu Nov 22, 2012 6:32 am
Posts: 7
Hi, I'm currently hooked up an ATMega 1284P to a R6522AP. The clock is generated by another ATMega producing 200kHz. I tried several variants of syncronizing R/W and PHI_2 to actually write at the very moment at least one time. Some work, some don't. All neccessary lines are controlled by software. What I reached up to now:

ORA, ORB, AUX and the Peripheral Register can be read and written without errors repeatedly. Timers can be read reliably. Written, too? Not sure. A big prob is that the Interrupt Enable and Interrupt Flag Register bouncing round. Occasionally the values agree with what I wrote in, sometimes not. It seems that the bits are virtually clued on the registers and sometimes cannot be changed at all. Do I write in the wrong address? I made a dump of 12 addresses and found nothing.

Question is: Why do some registers work fine and some others, especially controlling CA1+2, CB1+2 do what they want? I have too little experience in 6502 stuff answering this question. Any help is highly appreciated.

http://img10.imageshack.us/img10/2159/i ... 00x600.jpg




Joachim, Germany


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 22, 2012 7:16 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
Welcome!

Make sure you have the 6522's chip selects (also R/W\) valid and stable before phase 2 goes up. If they don't go true before phase 2 rises, you'll have problems. The 6522 needs to know while phase 2 is still low that its attention will be requested in that cycle.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 22, 2012 8:19 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Transistorfips wrote:
A big prob is that the Interrupt Enable and Interrupt Flag Register bouncing round. Occasionally the values agree with what I wrote in, sometimes not.
Welcome, Transistorfips.

In addition to what Garth said, also be aware that the Interrupt Enable Register (IER) and Interrupt Flag Register (IFR) do not read/write in a "normal" fashion -- for example, not the same as ORA and ORB.

When a write occurs to IER, it will either set one or more bits or it will clear one or more bits. If the value written has bit 7 set then some or all of bits 6-0 will be set. If the value written has bit 7 cleared then some or all of bits 6-0 will be cleared.

That probably seems "clear as mud," and I won't try to explain it fully. Also IFR has its own unique behavior. Really my message is that you need to refer to a 6522 data sheet. IFR and IER don't behave as one might expect. Right now you're maybe wondering if there's a hardware problem, but I have a hunch the h/w is fine.

have fun, & hope this helps
Jeff
Attachment:
6522 IER and IFR.gif
6522 IER and IFR.gif [ 165.93 KiB | Viewed 1383 times ]

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 22, 2012 6:09 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8507
Location: Midwestern USA
Dr Jefyll wrote:
Transistorfips wrote:
A big prob is that the Interrupt Enable and Interrupt Flag Register bouncing round. Occasionally the values agree with what I wrote in, sometimes not.
Really my message is that you need to refer to a 6522 data sheet.

6522 data sheet.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 22, 2012 9:08 pm 
Offline

Joined: Thu Nov 22, 2012 6:32 am
Posts: 7
Data shite says Tcy (clock cycle) > min 0.5us which is 100kHz. But when I go down to 195kHz (50% duty cycle) all registers start square-dancing.

On R6522AP I started a test series:
0 48kHz
1 109kHz
2 195kHz
3 308kHz
4 500kHz
5 800kHz
6 1.0MHz
7 1.3MHz
Even 800k cycles are not reliable during a register dump. With 1MHz all regs are steady now (except timer regs of course).
-> Is that beast totally out of spec?


When I write 0xF0 in the IER, read returns 0xF0 on the display. 0x03 produces 0xFC (which is 0xFF - 0x03) on the display and so on. It is always inverted. This funny game works until 255-128.


Hmmm...
Data sheet says:
Notes:
3. If a read of this Register is done, bit 7 will be "1" and all other bits will reflect their enable/disable state.
Hmm... It seems this fit together to my tests. So... is my biggest foe my greeness?


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 22, 2012 9:37 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Transistorfips wrote:
Is that beast totally out of spec?
Hello again, Transistorfips. I don't fully understand the experiments you're doing. Still, I think it'd be a good idea to stick with 1 Mhz as your operating frequency. That's a value that's within specification for the 6522, and (as far as I know) there's no need to try other frequencies. BTW I think you made a typo. Tcy (clock cycle) = 0.5us would be 2 MHz. But 1 MHz will be OK for you.

The fact that you can reliably read and write ORA and ORB is a very good sign. I suggest you familiarize yoursef with the counters next (and leave IFR and IER for later).

cheers,
Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 22, 2012 9:43 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
Quote:
Data shite says Tcy (clock cycle) > min 0.5us which is 100kHz. But when I go down to 195kHz (50% duty cycle) all registers start square-dancing.

0.5µs cycle time is 2MHz, which is probably the maximum guaranteed speed on the part you're looking at. The NMOS R6522 has a maximum cycle time of 10µs which makes for 100kHz. Are you feeding it a regular clock, or do you stop its phase-2 input when you're not accessing the 6522? The CMOS ones have no minimum speed. They can be run all the way down to 0Hz. I always strongly recommend CMOS over NMOS.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 22, 2012 10:46 pm 
Offline

Joined: Thu Nov 22, 2012 6:32 am
Posts: 7
>0.5µs cycle time is 2MHz

Uups.
I meant 10us, the othe end of the scale which gives us 100kHz.
I cranked down the clock cycle because I was unsure how to start this project. The ATMega runs with 4MHz only and I wanted to be sure I can handle that sync stuff by software. I NORed R/W and clk by hardware but without success.

>The CMOS ones have no minimum speed. They can be run all the way down to 0Hz. I always strongly recommend CMOS over NMOS.
Yep, this is what I read for the 6502. But haven't found this for the 6522l.

I bought two identical chips from ebay:
R6522AP
R6522-33
Mexico
9738 S11565-3
I thought this is one from newer designs... but maybe not.



Will continue my research.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 23, 2012 1:31 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Quote:
I tried several variants of syncronizing R/W and PHI_2 to actually write at the very moment at least one time.
Quote:
I NORed R/W and clk by hardware but without success.
Based on these comments I suspect there may be a misunderstanding. A typical bus cycle (a read or write access) for the 6522 should proceed as follows:

  • when PHI_2 is low, this is the time to prepare for the read or write access. By "prepare" I mean that certain signals need to go high or low as necessary to define what's about to happen. R/W must go high (for read) or low (for write). CS1 (pin 24) must be set high and /CS2 (pin 23) must be set low. RS3, RS2, RS1 and RS0 must be set according to the register you wish to access.
  • after all these signals are stable, PHI_2 can be brought high. If it's a read access, the read data (the contents of the register you selected) will now appear on D7-D0. If it's a write access, you need to apply the desired write data to D7-D0 if you haven't already.
  • following a brief delay, PHI_2 can be brought low again. This concludes the access.

Because you're not using a CMOS 6522, a limit for minimum clock speed (maximum cycle time) applies. That means you need to keep cycling PHI_2 even during times when you have no desire to access the 6522 registers. During the dummy cycles simply ensure that CS1 is low and/or /CS2 is high. BTW the cycling of PHI_2 is what serves to drive the 6522 Timers and Shift Register, so for that reason it's nice if you can keep the cycling continuous and regular.

Finally, remember that /Reset should be brought low to initialize the chip; otherwise keep it high at all times. Ciao for now; let us know how you're getting along! :D

Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 23, 2012 2:42 am 
Offline

Joined: Thu Nov 22, 2012 6:32 am
Posts: 7
IT WORKS!!!


Man.
It was a misunderstanding of the interrupt concept + error in reasoning.

The timing is less complicated than I thought earlier before since the writing covers at least 3 clock cycles (I set some of the infamous Intel wait-states here... ;-) now. It's a bit a botchy solution, maybe I do a little more in depth resarch to fix it tomorrow.
All I have is a minor issue now when reloading T2 counter. Occasionally it's not relaoding but this might be a software thing.

Anyway, thank you guys!


Last edited by Transistorfips on Wed Dec 05, 2012 11:02 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sat Nov 24, 2012 12:12 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
I add a code snippet to this subject to demonstrate, how an ATMega can do IO with devices requiring a phi2 clock.

The macros use timer 2 in ctc mode with OC2 pin set to toggle. Overflow compare is set to 7 and results in 1/16 of the ATMega clock being present on the OC2 pin, 1Mhz at 16MHz AVR clock.

Code:
;phase 2 synchronisation macro
;  next instruction after macro is at tcnt=7, OC2=1
;
;           you are here | at end of macro
;           _ _ _ _ _ _ _V_                 _ _
; Phi2  _ _|               |_ _ _ _ _ _ _ _|
;
; tcnt  6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1
;
; 500ns/phase, 62.5ns/count

.macro   phi2_sync
phi2_syncloop:
      in    zl,tcnt2     
      sbic  pind,7            ;wait for phi2 low
   rjmp  phi2_syncloop
   clr   zh
   subi  zl,low(-phi2_synctable) ;calculate offset cycles
   sbci  zh,high(-phi2_synctable)             
   ijmp

phi2_synctable:            ;delay -1 cycle for each count in tcnt
   nop                     ;0/1 - tcnt=0/OC2=1                 
   nop                     ;1/1
   nop                     ;2/1
   nop                     ;3/1
   nop                     ;4/1
   nop                     ;5/1
   nop                     ;6/1
;  next                     7/1 - output to next cycle, input from previous cycle
.endmacro

.macro   nop2              ;2 cycle nop
   rjmp  pc+1
.endmacro

;macro phase 2 synchronized read
;
;
;              data latched 1/2 clock ahead of IN +
;      address valid +                            |
;     after sync +   |                            |
;                |   |    _ _ _ _ _ _ _ _ _ _ _ _ | _ _
; chip select _ _|_ _|_ _|                        |    |_ _
;         _ _ _ _V_  |              _ _ _ _ _ _ _ V       
; Phi2             |_V_ _ _ _ _ _ _|               |_ _ _ _
;
; tcnt    3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3
;
.macro   phi2_rd
   phi2_sync
   sbi   abuslo,7          ;7/1 generate R/-W - tcnt=7/OC2=1
   sbi   cbus,io_select    ;1/0 CS strobe high >300ns before phi2
   nop2                    ;3/0
   nop2                    ;5/0
   nop2                    ;7/0
   nop2                    ;1/1
   nop2                    ;3/1
   nop2                    ;5/1
   nop                     ;7/1
   in    operand,dbusin    ;0/0 input latched at 7/1 +30ns
   out   cbus,clear        ;1/0 end strobe 125ns after phi2 te
.endmacro

;macro phase 2 synchronized write
;
;                    output data valid +
;      address valid +                 |
;     after sync +   |                 |
;                |   |    _ _ _ _ _ _ _|_ _ _ _ _ _ _
; chip select _ _|_ _|_ _|             |             |_ _ _
;         _ _ _ _V_  |              _ _V_ _ _ _ _ _       
; Phi2             |_V_ _ _ _ _ _ _|               |_ _ _ _
;
; tcnt    3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3
;
.macro   phi2_wrt
   phi2_sync
   cbi   abuslo,7          ;7/1 generate R/-W - tcnt=7/OC2=1
   sbi   cbus,io_select    ;1/0 CS strobe high >300ns before phi2
   nop2                    ;3/0
   nop2                    ;5/0
   nop                     ;7/0
   out   dbusout,operand   ;0/1 precharge data to be written
   out   dbusddr,allon     ;1/1 write data valid 125 ns after phi2 le
   nop2                    ;2/1
   nop2                    ;4/1
   nop2                    ;6/1
   out   cbus,clear        ;0/0 end strobe 60ns after phi2 te
   out   dbusddr,zero      ;data hold ends
.endmacro

note: register address is present on abuslo before macros are called. Global interrupts must be disabled.

edit1: replaced with improved code saving 2 cycles to sync
edit2: avoided the use of register a and the page alignment
edit4: fixed broken offset calculation - forward reference & wrong carry

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Last edited by Klaus2m5 on Mon Dec 10, 2012 5:42 pm, edited 4 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 01, 2012 9:38 am 
Offline

Joined: Thu Nov 22, 2012 6:32 am
Posts: 7
Thanks a lot. That's exactly what I'm looking for. I'll try to put this to my code in the next days. Maybe I contact you directly since this is ATMega stuff and I'm not very experienced in mixing C and assy with AVR-Studio.


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 01, 2012 6:09 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Code:
;         you are here | at end of macro
;           _ _ _ _ _ _V_ _                 _ _
; Phi2  _ _|               |_ _ _ _ _ _ _ _|


Transistorfips, do these macros satisfy the 6522's need to have certain input lines valid before the rising edge of Phase 2 (as noted in previous posts)? Using a macro has lots of advantages, and I like the approach Klaus2m5 has taken -- especially using the timer -- but I suspect you'll need to make some changes if it's the 6522 you're dealing with.

-- Jeff
EDIT: oops, sorry -- I spoke too soon. I guess the two outer macros, phi2_wrd and phi2_wrt, take you right through the following cycle, which is where the action is. phi2_sync is just the setup.

Code:
;         you are here | at end of inner macro (phi2_sync)
;           _ _ _ _ _ _V_ _                 _ _ _ _ _ _ _ _
; Phi2  _ _|               |_ _ _ _ _ _ _ _|               |_

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 05, 2012 11:01 am 
Offline

Joined: Thu Nov 22, 2012 6:32 am
Posts: 7
Hello Jeff,
the last few days I wrote some code around my 6522project - now I even have a user interface for playing with my new little toy.
The next days I will try to test the code from Klaus (haven't done any Assy on the ATMega though). Then I can tell you more.

http://img717.imageshack.us/img717/9660/img02626522.jpg


Joachim


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 07, 2012 12:38 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
While I was debugging a 6532 RIOT (NMOS), I noticed a potential problem.
Attachment:
6532_phi2_markup.jpg
6532_phi2_markup.jpg [ 53.38 KiB | Viewed 1159 times ]
Attachment:
6532_rw_markup.jpg
6532_rw_markup.jpg [ 56.9 KiB | Viewed 1159 times ]

Scope was set to 100ns & 2V per division, synced to chip select (the scope has about 100ns delay from sync to display, so chip select is actually 1 division earlier)

When the 6532 is read, the signal level barely reaches the minimum high level (0.6*Vcc) that the AVR recognizes as high. This wasn't actually causing a problem in my setup, however may cause problems later.

One way to circumvent this (quick and dirty) is adding 10k pullups to all bits on the data bus. This way I measured ~4V high level. The correct way to deal with this is probably adding a TTL compatible bus transceiver like a 74HCT245.

The bug I was chasing was bad RAM. However, I have improved the code and replace it in my last post.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: