Thursday, September 29, 2016

The z80 system clock

      
My z80 system will be started in a section named OpenZ80, the clock, that I had so many doubts about it, as I used to work with moderns microcontrollers and clock does not need to be so clear, and I read that z80 needs a clean clock and reset, I decided to use an attiny15L that I have some pieces here. This chip will provide several clocks for the system and configuring 2 pins it is possible to change betwen them. The clock values are: 12Mhz, 6Mhz, 3Mhz and 1,6Mhz no need to say that all of them will not have the precise value, because the attiny15l has a pll that generate 25Mhz that is divided to get these values Another feature is: 1 - the reset pulse to the z80, this reset will maintain the z80 for a long time in logic level zero when the power supply is turned on. 2 - led blinking, this is just to sinalize that the system is on, Image 01 - Clock Attiny15L - Assembler code to generate: clock, reset and blink led
 
; Program....: reset.asm
; Description: Z80 reset, clock 1,6Mhz, 3,2Mhz, 6,4Mhz or 12,8Mhz
; Author.....: Paulo da Silva
; Date.......: 26/09/2016
; 
; Attiny15L
;        +----+
;   rst--|    |-- vcc;
; cfg1 --|    |-- led blink
; cfg2 --|    |-- z80 clock
;   gnd--|    |-- z80 reset
;        +----+
;                                           
;    cfg2 cfg1                                      
;     0    0  ->   12,8Mhz                           
;     0    1  ->    6,4Mhz                  
;     1    0  ->    3,2Mhz                      
;     1    1  ->    1,6Mhz   
;
; Assembler: avra version 1.3.0 build 1
; Command..: avra reset.asm
.nolist
.include "/usr/share/avra/tn15def.inc"
.list
;==============
; Declarations
; PB0 - reset for z80
; PB1 - z80`s clock
; PB2 - led blink
; PB3 - Clock`s Configuration bit 1 (cfg1)
; PB4 - Clock`s Configuration bit 2 (cfg2)
;=================
; Variable Declarations
.equ OSCCAL_val = 0x6F  ; Calibrate
.def cseg       = r21  
.cseg      ; Code segment.
; Start of Program
.org    0
 rjmp Init   ; First line executed
 reti     ; IRQ0 handler
 reti     ; Pin change handler
 rjmp timer1CM  ; Timer1 compare match
 reti     ; Timer1 overflow handler
 rjmp timer0;  ; Timer0 overflow handler    
 reti     ; Eeprom Ready handler
 reti     ; Analog Comparator handler
 reti     ; ADC Conversion Handler
;============
Init:
 ; writing calibration byte to the OSCCAL Register.
 ldi     r16, OSCCAL_val
 out     OSCCAL, r16       
 nop
 nop
 ;Analogue comparator initialization
 ldi      r16, 0b10000000  ; Disable analogue comparator
 out      ACSR, r16
 ;PORTB initialization
 ldi      r16, 0b00000111  ; 1 = output e 0 =input1/6
 out      DDRB, r16    ; pb0 and pb1 = output pb2 = input
 ldi      r16, 0b11111000
 out      PortB, r16
 ;Timer initialization
 ldi      r16, 0x05   ; Timer 0 rolls over at 1.6MHz/1024/256 = 6.1Hz
 out      TCCR0, r16
 
 ;timer 1
 in    r16, PinB   ; Input port b to read clock configuration
 andi  r16, 0b00011000          ; pb3 and pb4
 cpi   r16, 0b00000000  ; 00 = 12,847Mhz
 brne  test6mhz
 ldi   r16, 0b10010001  ; 12Mhz
 rjmp  init2 
test6mhz: 
 cpi   r16, 0b00001000  ; 01 = 6Mhz
 brne  test3mhz
 ldi   r16, 0b10010010  ; 6,396 Mhz
 rjmp  init2  
test3mhz: 
 cpi   r16, 0b00010000  ; 10 = 3Mhz
 brne  test1mhz
 ldi   r16, 0b10010011  ; 3,210Mhz
 rjmp   init2
test1mhz: 
 ldi   r16, 0b10010100  ; 1,605Mhz
init2:
 out   TCCR1, r16
 ldi   r16, 0b00000000
 out   TCNT1, r16
 
 ldi      r16, $02  ;  Enable TOVF0
 out      TIMSK, r16  
 ldi      cseg, $01  ; Start at segment
 ldi      r17, 0x00
 ldi      r16, 0x00
 sei                  ; Enable Interrupts          
;======================
; Main body of program:
Main:            
loopRst:
 cbi  PortB, pb0 
 cpi  r16, 6  ; Wait some time here before to raise z80's reset line 
 brne loopRst
 sbi  PortB, pb0
blink:
 ;blink a led
 SBRS    r16, 0  ;2 Skip next instruction if bit0 = 1
 SBI     PORTB, pb2 ;2 Turn LED ON if bit0 = 0
 SBRC    r16, 0  ;2 Skip next instruction if bit0 = 0
 CBI     PORTB, pb2 ;2 Turn LED OFF if bit0 = 1
 rjmp    blink   ;2 loops back to the start of Main
 
timer0:
 inc  r16   ;Increment and will be used to blink a led
 reti
    
timer1CM:
This is tested !!! :) Enjoy

The complete system list at least for while


They are a sketch by this they can change any time.

1 - The z80 clock
2 - Addressing system
3 - Static memory(SRAM) 32kbytes minimal
4 - Eprom memory(8kbytes)
5 - I/O system(bip sound, rs232, spi interface)
6 - SDcard (at least 8gb)
7 - keyboard and 6 display 7 segments and LCD maybe 4lines 20 characters
8 - CPU Z80 8Mhz and I/O expansion bus

Greetings !!


Hi all,

Wecome to my blog!

It is the first time that I will share my things, so I hope you enjoy all of them.

Here I'll try to publish all my projects of hardware and software, specially the embedded one.
My first project is a z80 system made by me, I know that outside there has a lot of this kind of project but mine is a long time desire,since I was attending an electronic technician course so don't blame me to realize it.

:) Enjoy !!!