Skip to content

Potential Bug in Chapter 5 serialOrgan/organ.c #60

@vilroi

Description

@vilroi

If I understood correctly, playNote() is supposed to create a square wave with a period of period by toggling the SPEAKER_PORT, and continues to output the wave for duration.

If this is the case, shouldn't SPEAKER_PORT be toggled twice after half the amount of time for period has elapsed, as the period is the duration of a single cycle?

Thus instead of:

for (i = 0; i < period; i++) {
    _delay_us(1);
}
SPEAKER_PORT ^= (1 << SPEAKER);

I would assume it should be something like:

for (i = 0; i < 2; i++) {
    for (j = 0; j < period / 2; j++) {
        _delay_us()
    }
    SPEAKER_PORT ^= (1 << SPEAKER);
}

Please let me know If I have misunderstood how this is supposed to work.

Otherwise, thank you for your outstanding book.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions