HBBR Basic

  • Increase font size
  • Default font size
  • Decrease font size

Part 2: How to make a sound

E-mail Print PDF
User Rating: / 0
PoorBest 

When developing for a deeply embedded system it is very important to find some kind of a simple debugging mechanism that is available in the system. It can be visual or audible but should be something that does not depend on any external hardware and is easy to program. Probably the most useful are LEDs hooked to the GPIO or a simple beeper.

In case of the NXT brick the choice for the debug mechanism is pretty straightforward, the ARM CPU is directly connected to the audio amplifier, on the schematic the signal is labeled SOUND_ARMA. It connects AT91SAM7S256 Pin 9 which is a GPIO line PA17/PGMD5/AD0 to the input of the sound driver SPY0030A, which in turn drives 16 ohm loudspeaker inside the brick.

The first program is designed to test the debugging mechanism itself. The program is very simply, after the boot the PA17 GPIO line is initialized as an output line then Sub sound() is called to generate continuous sound or so it seams. To generate the sound we will need a way to do the delay which is implemented in a Sub delay().


After uploading (see this article on how to upload to he NXT Brick) the program runs but in a bit of surprising way. It does not produce continuous tone, what actually happens is this:

  • After power is turned on the brick makes sound for 2 seconds
  • Then every second it repeats this pattern: no sound for 0.5s, play sound for 0.5s


This pattern can be easily heard in the captured sound of the beeping brick (click play button below) it can also be seen in the waveform picture below.

Image below is showing about 7 seconds of captured sound from the NXT brick. The power is applied around 0.8s (there is a short spike when the battery was plugged in) followed by 0.2s delay when the brick boots. The brick then beeps for 2s (1.0 to 3.0) and reapeats the pattern: no sound for 0.5s then play for 0.5s.



 

In the next installment we wil focus on the question of why we do not get the continuous tone from the brick,

as well as why do we get sound waveform seen in this picture.

 

Here is a full listing of the program, follow the comments for details:

' HBBR NXT Native app for NXT programmable brick
' (C) Hobby-Robotics, LLC 2008
' 

' Delay generation
' Resolution is 1/10 of ms
Sub delay(ByVal d As UInteger )
    Do
        d -=1
    Loop While d > 0
End Sub

' Sound generation
' pitch is frequency in Hz
Sub sound(ByVal pitch As UInteger)
    Dim i As UInteger
    Dim d As UInteger
    i = 0
    Do
        ' Call delay
        Call delay(pitch)
        ' Toggle the pin
        ' PIO_ODSR - PIO Controller Output Data Status Register
        ' 0 = The data to be driven on the I/O line is 0
        ' 1 = The data to be driven on the I/O line is 1 
        If (AT91C_PIOA_ODSR And AT91C_PIO_PA17) Then
            ' PIO_CODR - PIO Controller Clear Output Data Register
            ' 1 = Clears the data to be driven on the I/O line
            AT91C_PIOA_CODR = AT91C_PIO_PA17
        Else
            ' PIO_SODR - PIO Controller Set Output Data Register
            ' 1 = Sets the data to be driven on the I/O line
            AT91C_PIOA_SODR = AT91C_PIO_PA17
        End If
    Loop
End Sub

' Entry point for user code
Sub Main()

    ' Configure the pin P9 PA17 as output
    ' PIOA_OER - PIO Controller Output Enable Register 
    ' 1 = Enables I/O line for output
    AT91C_PIOA_OER = AT91C_PIO_PA17
    ' Set the PIO controller in PIO mode not the peripheral mode 
    ' PIOA_PER - PIO Controller PIO Enable Register
    ' 1 = Enables PIO to control the corresponding pin
    AT91C_PIOA_PER = AT91C_PIO_PA17
    ' Disable pull-up
    ' PIO_PUDR - PIO Pull Up Disable Register
    ' 1 = Disables the pull up resistor on the I/O line
    AT91C_PIOA_PPUDR = AT91C_PIO_PA17

    ' Generate sound
    Call sound(1000)
  
End Sub

 

Last Updated on Sunday, 15 June 2008 22:50  

Little Bird

twitter Bird more info...!