Skip to content

Commit 0d832c7

Browse files
committed
Bump to 1.1.2, example code cleanup, doc update
1 parent 7072874 commit 0d832c7

File tree

5 files changed

+20
-46
lines changed

5 files changed

+20
-46
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ I created an Arduino-AY38910 chiptunes player board, see the [README][9] in the
7575

7676
## Example Sketches
7777

78+
*NOTE: While the library itself does not use any platform-specific code, the examples that generate tones (EX3, EX5, EX6, EX7) have platform-specific code to generate the `CLOCK` signal required by the sound generator chip. If you are using an ATmega329 or ATmega32u4 chip, then the examples should run as-is. For other chips, consult the respective datasheet or connect an externally-generated clock signal to the sound generator chip and update the example code accordingly.*
79+
7880
**EX1 - Find Address**
7981
The AY-3-8910 chip typically has a binary address of `01 0000 xxxx`,
8082
where `xxxx` represents the specific register you are addressing.

examples/AY3891x_EX3_Simple_Tone/AY3891x_EX3_Simple_Tone.ino

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,12 @@ static const byte clkOUT = 9;
3434
const byte DIVISOR = 7; // Set for 1MHz clock
3535
static void clockSetup()
3636
{
37-
// Timer 1 setup for Mega32U4 devices
38-
//
39-
// Use CTC mode: WGM13..0 = 0100
40-
// Toggle OC1A on Compare Match: COM1A1..0 = 01
41-
// Use ClkIO with no prescaling: CS12..0 = 001
42-
// Interrupts off: TIMSK0 = 0
43-
// OCR0A = interval value
44-
4537
TCCR1A = (1 << COM1A0);
4638
TCCR1B = (1 << WGM12) | (1 << CS10);
4739
TCCR1C = 0;
4840
TIMSK1 = 0;
4941
OCR1AH = 0;
50-
OCR1AL = DIVISOR; // NB write high byte first
42+
OCR1AL = DIVISOR;
5143
}
5244
#endif
5345

examples/AY3891x_EX5_Serial_Commands/AY3891x_EX5_Serial_Commands.ino

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,12 @@ static const byte clkOUT = 9;
6565
const byte DIVISOR = 7; // Set for 1MHz clock
6666
static void clockSetup()
6767
{
68-
// Timer 1 setup for Mega32U4 devices
69-
//
70-
// Use CTC mode: WGM13..0 = 0100
71-
// Toggle OC1A on Compare Match: COM1A1..0 = 01
72-
// Use ClkIO with no prescaling: CS12..0 = 001
73-
// Interrupts off: TIMSK0 = 0
74-
// OCR0A = interval value
75-
7668
TCCR1A = (1 << COM1A0);
7769
TCCR1B = (1 << WGM12) | (1 << CS10);
7870
TCCR1C = 0;
7971
TIMSK1 = 0;
8072
OCR1AH = 0;
81-
OCR1AL = DIVISOR; // NB write high byte first
73+
OCR1AL = DIVISOR;
8274
}
8375
#endif
8476

examples/AY3891x_EX6_Chiptunes_Flash/AY3891x_EX6_Chiptunes_Flash.ino

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// #define HARDWARE_GENERATED_CLOCK
1919
2020
02/08/21 - A.T. - Original
21+
07/25/22 - Andy4495 - Implement non-blocking delay
2122
2223
*/
2324

@@ -46,20 +47,12 @@ static const byte clkOUT = 9;
4647
const byte DIVISOR = 3; // Set for approximate 2 MHz clock
4748
static void clockSetup()
4849
{
49-
// Timer 1 setup for Mega32U4 devices
50-
//
51-
// Use CTC mode: WGM13..0 = 0100
52-
// Toggle OC1A on Compare Match: COM1A1..0 = 01
53-
// Use ClkIO with no prescaling: CS12..0 = 001
54-
// Interrupts off: TIMSK0 = 0
55-
// OCR0A = interval value
56-
5750
TCCR1A = (1 << COM1A0);
5851
TCCR1B = (1 << WGM12) | (1 << CS10);
5952
TCCR1C = 0;
6053
TIMSK1 = 0;
6154
OCR1AH = 0;
62-
OCR1AL = DIVISOR; // NB write high byte first
55+
OCR1AL = DIVISOR;
6356
}
6457
#endif
6558

@@ -79,18 +72,21 @@ void setup()
7972
void loop()
8073
{
8174
byte i;
82-
prev_micros = micros();
8375

84-
for (i= 0; i < 14; i++) {
85-
psg.write(i, pgm_read_byte(&psg_data[index++]));
86-
}
76+
if (micros() - prev_micros > INTERVAL)
77+
{
78+
prev_micros = micros();
79+
80+
for (i= 0; i < 14; i++) {
81+
psg.write(i, pgm_read_byte(&psg_data[index++]));
82+
}
8783

88-
if (index >= sizeof(psg_data)) {
89-
psg.write(AY3891x::Enable_Reg, MIXER_NOISES_DISABLE | MIXER_TONES_DISABLE | psg.read(AY3891x::Enable_Reg));
90-
while (1);
91-
// Or... you can re-start to song:
92-
// index = 0;
84+
if (index >= sizeof(psg_data)) {
85+
psg.write(AY3891x::Enable_Reg, MIXER_NOISES_DISABLE | MIXER_TONES_DISABLE | psg.read(AY3891x::Enable_Reg));
86+
while (1);
87+
// Or... you can re-start the song:
88+
// index = 0;
89+
}
9390
}
9491

95-
while (micros() - prev_micros < INTERVAL) ; // Empty statement, loop until it is time for next update
9692
}

examples/AY3891x_EX7_Chiptunes_SD/AY3891x_EX7_Chiptunes_SD.ino

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,12 @@ static const byte clkOUT = 9;
5151
const byte DIVISOR = 3; // Set for approximate 2 MHz clock
5252
static void clockSetup()
5353
{
54-
// Timer 1 setup for Mega32U4 devices
55-
//
56-
// Use CTC mode: WGM13..0 = 0100
57-
// Toggle OC1A on Compare Match: COM1A1..0 = 01
58-
// Use ClkIO with no prescaling: CS12..0 = 001
59-
// Interrupts off: TIMSK0 = 0
60-
// OCR0A = interval value
61-
6254
TCCR1A = (1 << COM1A0);
6355
TCCR1B = (1 << WGM12) | (1 << CS10);
6456
TCCR1C = 0;
6557
TIMSK1 = 0;
6658
OCR1AH = 0;
67-
OCR1AL = DIVISOR; // NB write high byte first
59+
OCR1AL = DIVISOR;
6860
}
6961
#endif
7062

0 commit comments

Comments
 (0)