Difference between revisions of "83:Ports:04"

From WikiTI
Jump to: navigation, search
m (Wrong category (83, not 83Plus))
(added documentation for bits 5-7)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:83:Ports:By_Address|04 - Timer Interrupt Frequency]] [[Category:83:Ports:By_Name|Timer Interrupt Frequency]]
+
[[Category:83:Ports:By_Address|04 - Timer Interrupt Frequency / Memory Map / Battery Status]] [[Category:83:Ports:By_Name|Timer Interrupt Frequency / Memory Map / Battery Status]]
 
== Synopsis ==
 
== Synopsis ==
 
'''Port Number:''' 04h
 
'''Port Number:''' 04h
  
'''Function:''' Timer Interrupt Frequency
+
'''Function:''' Timer Interrupt Frequency, Memory Map Control and Battery Status Checking
  
This port controls the frequency of the hardware timer.
+
This port controls the frequency of the hardware timer and the memory map mode. The higher bits of this port control at which voltage level [[83:Ports:14|bit 0 of port 14]] flips.
  
 
=== Read Values ===
 
=== Read Values ===
Line 11: Line 11:
  
 
=== Write Values ===
 
=== Write Values ===
* Bit 0: Unknown. The calculator crashes when set. Maybe it has more or less the same behaviour as bit 0 of [[83Plus:Ports:04]].
+
* Bit 0 controls the [[83:OS:Memory Mapping|memory mapping mode]]. The default value for this bit is 0.
* Bits 1 and 2 control the hardware timer frequency. Setting both 0 sets the timer to the fastest speed, and both 1 is the slowest speed. The normal speed is with both bits 1.
+
* Bits 1 and 2 control the hardware timer frequency. Setting both 0 sets the timer to the fastest speed, and both 1 is the slowest speed. The default is with both bits 1.
 
* Bit 3: Unused? Always 0.
 
* Bit 3: Unused? Always 0.
* Bit 4: Unused? Always 1.
+
* Bit 4: Timer frequency multiplier; when this bit is set, all the times are multiplied by 90% (i. e. it's 11.1% faster) compared to when it's reset.
* Bit 5-7: Unknown, but definitely used.
+
* Bit 5: Set this bit to keep the [[83:OS:Hardware Reset|reset circuit]] high even when [[83:Ports:14|bit 0 of port 14]] is 0. The default value for this bit is 0.
 +
* Bits 6-7: These bits control the voltage level you want to compare the batteries with. After changing these bits you need a delay for [[83:Ports:14|port 14]] to adapt. A 100 clock cycles should be more than sufficient. The default value for these bits is 00.
 +
** 00: [[83:Ports:14|Bit 0 of port 14]] will go low when voltage drops below ~3.2V and high again when over ~3.5V.
 +
** 10: [[83:Ports:14|Bit 0 of port 14]] will go low when voltage drops below ~3.5V and high again when over ~3.8V.
 +
** 01: [[83:Ports:14|Bit 0 of port 14]] will go low when voltage drops below ~3.8V and high again when over ~4.2V. This test is continuously used by the OS to safe power down when necessary.
 +
** 11: [[83:Ports:14|Bit 0 of port 14]] will go low when voltage drops below ~4.2V and high again when over ~4.6V. This test is used when you turn the calculator on to display a low battery warning when necessary.
 +
 
 +
== Comments ==
 +
* The voltages given above are purely indicative and may be highly inaccurate. (until somebody confirms them)
 +
* To calculate the resulting timer frequency you can use the following formula:
 +
:freq = 1800 * ((out_value & 0x10) ? 1.0 : 0.9) / (3 + ((out_value & 0x06) << 1))
 +
 
 +
== Example ==
 +
This example shows how to test the batteries.
 +
<nowiki> ld a,36h  ;First we make sure the calculator doesn't reset
 +
out (4),a  ;when we change bits 6 and 7.
 +
ld a,76h  ;We'll check if batteries are below ~3.8V.
 +
out (4),a
 +
ld b,8    ;After changing bits 6 and 7 we need a delay.
 +
djnz $
 +
in a,(14h) ;Read the battery status
 +
ld c,a    ;and save it.
 +
ld a,36h  ;Set bits 6 and 7 back to default but keep bit 5
 +
out (4),a  ;set until after the delay.
 +
ld b,8    ;After changing bits 6 and 7 we need a delay.
 +
djnz $
 +
ld a,16h  ;Now it's safe to reset bit 5 too.
 +
out (4),a
 +
bit 0,c    ;Bit 0 is zero when batteries are lower than ~3.8V.</nowiki>

Latest revision as of 15:07, 28 April 2005

Synopsis

Port Number: 04h

Function: Timer Interrupt Frequency, Memory Map Control and Battery Status Checking

This port controls the frequency of the hardware timer and the memory map mode. The higher bits of this port control at which voltage level bit 0 of port 14 flips.

Read Values

This is a mirror of the link port.

Write Values

  • Bit 0 controls the memory mapping mode. The default value for this bit is 0.
  • Bits 1 and 2 control the hardware timer frequency. Setting both 0 sets the timer to the fastest speed, and both 1 is the slowest speed. The default is with both bits 1.
  • Bit 3: Unused? Always 0.
  • Bit 4: Timer frequency multiplier; when this bit is set, all the times are multiplied by 90% (i. e. it's 11.1% faster) compared to when it's reset.
  • Bit 5: Set this bit to keep the reset circuit high even when bit 0 of port 14 is 0. The default value for this bit is 0.
  • Bits 6-7: These bits control the voltage level you want to compare the batteries with. After changing these bits you need a delay for port 14 to adapt. A 100 clock cycles should be more than sufficient. The default value for these bits is 00.
    • 00: Bit 0 of port 14 will go low when voltage drops below ~3.2V and high again when over ~3.5V.
    • 10: Bit 0 of port 14 will go low when voltage drops below ~3.5V and high again when over ~3.8V.
    • 01: Bit 0 of port 14 will go low when voltage drops below ~3.8V and high again when over ~4.2V. This test is continuously used by the OS to safe power down when necessary.
    • 11: Bit 0 of port 14 will go low when voltage drops below ~4.2V and high again when over ~4.6V. This test is used when you turn the calculator on to display a low battery warning when necessary.

Comments

  • The voltages given above are purely indicative and may be highly inaccurate. (until somebody confirms them)
  • To calculate the resulting timer frequency you can use the following formula:
freq = 1800 * ((out_value & 0x10) ? 1.0 : 0.9) / (3 + ((out_value & 0x06) << 1))

Example

This example shows how to test the batteries.

 ld a,36h   ;First we make sure the calculator doesn't reset
 out (4),a  ;when we change bits 6 and 7.
 ld a,76h   ;We'll check if batteries are below ~3.8V.
 out (4),a
 ld b,8     ;After changing bits 6 and 7 we need a delay.
 djnz $
 in a,(14h) ;Read the battery status
 ld c,a     ;and save it.
 ld a,36h   ;Set bits 6 and 7 back to default but keep bit 5
 out (4),a  ;set until after the delay.
 ld b,8     ;After changing bits 6 and 7 we need a delay.
 djnz $
 ld a,16h   ;Now it's safe to reset bit 5 too.
 out (4),a
 bit 0,c    ;Bit 0 is zero when batteries are lower than ~3.8V.