66 of 158
60 3.7 Timers The ZX series CPUs both incorporate several timers, the actual number depending on the underlying CPU. On all ZX models, Timer0 and Timer2 are 8-bit timers while the remaining timers are 16-bit. The table below summarizes timer usage. Timer Usage by CPU Type Underlying CPU RTC I/O Serial PWM InputCapture OutputCapture mega32 Timer0 Timer1 Timer2 Timer1 Timer1 Timer1 mega644 Timer0 Timer1 Timer2 Timer1 Timer1 Timer1 mega128 Timer0 Timer1 Timer2 Timer1/3 Timer1/3 Timer1/3 mega1281 Timer2 Timer4 Timer0 Timer1/3 Timer1/3 Timer1/3 mega1280 Timer2 Timer4 Timer0 Timer1/3/4/5 Timer1/3/4/5 Timer1/3/4/5 The RTC Timer is used to generate interrupts to manage the real time clock (RTC). The I/O Timer is used for several I/O functions that require accurate timing. The Serial Timer is used to implement the “software UART” for the serial channels Com3 to Com6. When a specific timer is not being used by the system, you are free to use that timer in your program as you wish. To do so, you’ll have to read the Atmel datasheet for the ATmega32, ATmega644, ATmega128, ATmega1280 or ATmega1281 microcontroller to determine how to program the timers and then use the built-in registers to read and write the timer registers. Further discussion of that topic is beyond the scope of this document. 3.8 Built-in Variables The set of pre-defined registers comprises two sub-groups: actual CPU registers and control program variables. All of these built-in variables must be referenced using the Register prefix or within a With Register compound statement. Example Dim tick as Long tick = Register.RTCTick 3.8.1 CPU Registers ZX-24, ZX-40, and ZX-44 Registers The pre-defined CPU registers for the ZX-24, ZX40 and ZX-44 match those available on the ATmega32 CPU and all are Byte values. Discussion of the use of these registers is beyond the scope of this document. See the Atmel documentation for a full description. Also, be advised that modifying some of these registers may severely alter the behavior of the control program, possibly even rendering it inoperable. The register value may be accessed by using the register name, from the table below, prefixed by the keyword Register, e.g. Register.PortC. CPU Registers for mega32-based ZX Models ACSR EECR OCR1AL PORTD TCCR2 UBRRH ADCH EEDR OCR1BH SFIOR TCNT0 UBRRL ADCL GICR OCR1BL SPCR TCNT1H UCSRA ADCSRA GIFR OCR2 SPDR TCNT1L UCSRB ADMUX GIMSK OSCCAL SPH TCNT2 UCSRC ASSR ICR1H PINA SPL TIFR UDR DDRA ICR1L PINB SPMCR TIMSK WDTCR DDRB MCUCR PINC SPSR TWAR