Shop OBEX P1 Docs P2 Docs Learn Events
Help on Spin headphone to microphone object — Parallax Forums

Help on Spin headphone to microphone object

domeniv97domeniv97 Posts: 14
edited 2023-08-03 12:03 in Propeller 1

Hi there,

I am trying to get familiar it audio in and out with the parallax propeller 1 activity board.

I am using the Microphone to headphone object published in the github (https://github.com/parallaxinc/propeller/blob/master/libraries/community/p1/All/Microphone to Headphones/microphone_to_headphones.spin) but I seem to not be able to produce any output nor input.

It is unclear to me, with the mask $00000E00, which pin is expected to be used for microphone input and which for speaker output. Can someone maybe help me understand the code a bit better?

Domenico

Comments

  • Hi,
    The application notes on adc and counters might be helpful!
    https://www.parallax.com/download/propeller-1-documentation/

  • AribaAriba Posts: 2,685

    $00000E00 ist the bitmask for dira, every 1 bit sets a pin to output. So P9, P10, P11 are outputs.
    The demo is made for the DemoBoard, which uses P10, P11 for Audio Out, and P8, P9 for the Microphon ADC. P8 is the input pin for the ADC and P9 the Feedback output for the delta modulator.

    Unfortunately the demo code is written with all hardcoded pins, so it needs some PASM knowledge to change it to other pins.

    I think the Activity board has no Microphon input, so you will need to add it on the breadboard. The problem is the ADC circuit must be built very close to the Propeller pins to work well.

    Andy

  • domeniv97,

    The Propeller Activity Board (PAB) has an ADC built into it, but the documentation doesn't specify its part number.
    https://www.parallax.com/package/propeller-activity-board-wx-product-guide/
    https://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-circuits/measure-volts

    What exactly are you trying to do?

    BTW, $E00 = 1110 0000 0000

  • Thank you all for the explanation!

    For the moment, I am just interested in the audio input and output capabilities of the propeller 1 for a university project involving open source hardware, so I would like to fin out if it is possible to use solely that chip for ADC in and DAC out.

    I am using a propeller activity board and I did not notice that a discontinued demo board also existed and though they were the same, no the pin masking and the fact that I have to change it accordingly is clearer, I still struggle with understanding if the propeller 1 alone would be able to deal with ADC in and DAC out by itself though.

    Domenico

  • domeniv97,

    Chapter 7 of the Propeller Education Kit Text has a number of different applications using the Propeller.
    https://www.parallax.com/package/propeller-education-kit-fundamentals-text-and-code/

    You should also refer to the Propeller Manual for programming information.
    https://www.parallax.com/download/propeller-1-documentation/

    There's an old schematic for the Demo board here.
    https://forums.parallax.com/discussion/85107/new-propeller-demo-board-photo-and-schematic

    This is the newest.
    https://www.jameco.com/Jameco/Products/ProdDS/2174856Schematic.pdf

  • I wanted to give you a bit of an update and ask again for suggestions: I put together in the breadboard of the Propeller 1 activity board the schematic of mic input and feedback loop of the demo board (https://forums.parallax.com/discussion/85107/new-propeller-demo-board-photo-and-schematic, picture related
    ) and modified the mask of DIRA in the spin code (https://github.com/parallaxinc/propeller/blob/master/libraries/community/p1/All/Microphone to Headphones/microphone_to_headphones.spin) to 0000_1100_0000_0000_0000_0010_0000_0000 so that P9 and P26, P27 are now outputs, so that now according to the Parallax propeller activity board it should output to the headphone jack of the board itself. I still get no signal. Suggestions? Has anyone tried DAC and ADC scripts for the propeller activity board?

  • @domeniv97

    In that code, did you also change:

                  movs      ctra,#8                     '<-- Change #8 to #7
                  movd      ctra,#9
                  movi      ctra,#%01001_000
                  mov       frqa,#1
    
                  movs      ctrb,#10                    '<-- Change #10 to #26
                  movd      ctrb,#11                    '<-- Change #11 to #27
    

    Those lines set up the counters with the correct I/O pins.

  • domeniv97,

    I think it is important that you not only know what changes to make but WHY.

    According to page 96 of the Propeller Manual:
    MOVS writes the value for APIN to the CTRx register.
    MOVD writes the value for BPIN to the CTRx register.
    MOVI writes the values for CTRMODE and PLLDIV to the CTRx register.

    In the code above, 01001 is CTRMODE which is POS detector with feedback, and PLLDIV is 000 which is VCO/128 but PLL is not being used here so this value is meaningless.
    The table of CTRMODEs and is on page 98 of the Propeller Manual.

  • AribaAriba Posts: 2,685

    Here is a modified version with PIN constants (untested)

    ''***************************************
    ''*  Microphone-to-Headphones v1.0      *
    ''*  Author: Chip Gracey                *
    ''*  Copyright (c) 2006 Parallax, Inc.  *
    ''*  See end of file for terms of use.  *
    ''***************************************
    '' modified for PIN CONSTANTS by Ariba
    
    ' This program uses the Propeller Demo Board, Rev C
    ' The microphone is digitized and the samples are played on the headphones.
    
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      ADCIN  =  8           'used pins
      ADCFB  =  9
      DAC_L  =  26
      DAC_R  =  27
    
    
    ' At 80MHz the ADC/DAC sample resolutions and rates are as follows:
    '
    ' sample   sample
    ' bits       rate
    ' ----------------
    ' 5       2.5 MHz
    ' 6      1.25 MHz
    ' 7       625 KHz
    ' 8       313 KHz
    ' 9       156 KHz
    ' 10       78 KHz
    ' 11       39 KHz
    ' 12     19.5 KHz
    ' 13     9.77 KHz
    ' 14     4.88 KHz
    
      bits = 11               'try different values from table here
    
    
    PUB go
    
      cognew(@asm_entry, 0)   'launch assembly program into a COG
    
    
    DAT
    
    '
    '
    ' Assembly program
    '
                  org
    
    asm_entry     mov       dira,asm_dira                   'make pins 8 (ADC) and 0 (DAC) outputs
    
                  movs      ctra,#ADCIN                     'POS W/FEEDBACK mode for CTRA
                  movd      ctra,#ADCFB
                  movi      ctra,#%01001_000
                  mov       frqa,#1
    
                  movs      ctrb,#DAC_L                     'DUTY DIFFERENTIAL mode for CTRB
                  movd      ctrb,#DAC_R
                  movi      ctrb,#%00111_000
    
                  mov       asm_cnt,cnt                     'prepare for WAITCNT loop
                  add       asm_cnt,asm_cycles
    
    
    :loop         waitcnt   asm_cnt,asm_cycles              'wait for next CNT value (timing is determinant after WAITCNT)
    
                  mov       asm_sample,phsa                 'capture PHSA and get difference
                  sub       asm_sample,asm_old
                  add       asm_old,asm_sample
    
                  shl       asm_sample,#32-bits             'justify sample and output to FRQB
                  mov       frqb,asm_sample
    
                  jmp       #:loop                          'wait for next sample period
    '
    '
    ' Data
    '
    asm_cycles    long      |< bits - 1                     'sample time
    asm_dira      long      1<<DAC_L | 1<<DAC_R | 1<<ADCFB  'output mask
    
    asm_cnt       res       1
    asm_old       res       1
    asm_sample    res       1
    
    
  • Avsa242 silly me, I forgot to change those, well that was the problem!

    Thanks Ariba, now it works well and your version uses constants so I like it and I will make use of it!

    Genetix, I am aware of it, I will need to learn in deep how PASM works, I will check and recheck the manual. In my defense: The project I am part of is three years long so hopefully I will have a lot of time to learn by heart everything about the inner workings of the propeller 1.

    Again thanks to everyone!

Sign In or Register to comment.