Shop OBEX P1 Docs P2 Docs Learn Events
Newbie Spin Question - Page 2 — Parallax Forums

Newbie Spin Question

2»

Comments

  • ratronicratronic Posts: 1,451
    edited 2013-04-19 17:18
    In the code you posted above he started the dithering audio engine, I am trying his regular dac engine with the volume turned up to 100. So if your audio pins are P25 and P26 then you would write dac.dacenginestart(25, 26, 100)

    EDIT: I have not tested this but if you can't get it to work I will try to play the chimes file on my PropBOE.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-19 18:31
    It is not working. I tried placing the dac.dacenginestart(25, 26, 100)in various locations and each time I get a different result. I did have to had the dacengine to the OBJ list, otherwise I got an error.
  • ratronicratronic Posts: 1,451
    edited 2013-04-19 18:38
    I have yet to play a wav file on my PropBOE so tonight I will try the engine file with the chimes wav file and let know what happens.
  • ratronicratronic Posts: 1,451
    edited 2013-04-19 19:07
    I looked closer at Kye's engine and it uses a SD card to play the wav file from and you have to include a start to the SD card. Perhaps you might post an archive of your code that last worked for us to look at by using the Propeller tool - File/Archive/Project... and attach the zip file it creates here.
  • ratronicratronic Posts: 1,451
    edited 2013-04-20 09:50
    NW I made this short demo that just repeat plays the chimes sound using Kye's engine. The pin #'s in the CON section will need to match your setup for the SD card's DO, DI, CLK, and CS pins. Audio's _lpin, _rpin. The pin#'s listed are for the PropBOE. I used an IF NOT statement to make sure the player is finished before trying to play again. Make sure the chimes wav file is put into the folder you download.
    CON
      _clkmode = xtal1 + pll16x ' The clkfreq is 80MHz.
      _xinfreq = 5_000_000 ' Demo board compatible.
      _dopin = 22
      _clkpin = 23
      _dipin = 24
      _cspin = 25
      _cdpin = -1 ' -1 if unused.
      _wppin = -1 ' -1 if unused.
      _rtcres1 = -1 ' -1 always.
      _rtcres2 = -1 ' -1 always.
      _rtcres3 = -1 ' -1 always.
      _lpin = 26 ' -1 if unused.
      _rpin = 27 ' -1 if unused.
      _volume = 50 ' Default volume.
      _ditherEnable = true ' "true" or "false" please.
      _ditherLevel = 4 ' 0 = Most Dither ... 31 = Least Dither.
      
    OBJ dac: "WAV-Player_DACEngine"
    VAR 
    PUB demo  | a,b,c
      
      dac.FATEngineStart(_dopin, _clkpin, _dipin, _cspin, _wppin, _cdpin, _rtcres1, _rtcres2, _rtcres3)     
      dac.DACEngineStart(constant(_lpin | (not(not(_ditherEnable)))), constant(_rpin | (not(not(_ditherEnable)))), _volume)  
        
      if(_ditherEnable)
        dac.DACDitherEngineStart(_lpin, _rpin, _ditherLevel)
        
      repeat
        if not dac.waveplayerstate                                  
          dac.playwavfile(string("CHIMES.WAV"))
    
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 11:50
    OK. I will give this a try some time this week. I have a lot going on right now and think there may be a bit of confusion as to what I am trying to do. I will explain in full detail when I get back to my office.
  • ratronicratronic Posts: 1,451
    edited 2013-04-20 12:17
    Make sure the chimes.wav file you want to play is put on the SD card not the folder - sorry about that.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 13:02
    OK. So the program you wrote works fine. I am able to play chimes.wav using it. However, I need to call that OBJ from my main program which is where the problem lies. I named the new program Testwav. See attached code for what I am trying to do. I was able to get it to work using the ASM wav player OBJ but it is way more than I need and also outputs to Serial terminal which I did not need. I modified that code and was able to get it to work. I am just trying to get a slimmed down version to work.
    {{
    Pressure Sensor and BarGraph DEMO.spin
    Program Date: 1/4/2013
    Version:      1.1 Modified version to add the ability to turn a servo on and off at specified pressure.
    Description:
    This program reads voltage values from the Propeller BOE's ADC and prints the raw value to
    the Parallax Serial Terminal program running on your PC.  The program also uses a cog to
    show a linear representation of the pressure sensed on a 10-segment LED bar graph.
     
                               Propeller BOE Wiring Diagram
    
    === Pressure Sensor Pin Connections ===   
                                                       
                             +5v                       
                                                      
                              │                        
              ┌─────────────┐ │                        
              │             │ │                        
              │   MPX5010   │ │                         
              │             │ │                         
              └─┬─┬─┬─┬─┬─┬─┘ │                         
          Pin 1 │ │ │ x x x   │                        
        AD0 ───┘ │ └─────────┘                        
                                                      
                 GND
     
    === LED Bar Graph Pin Connections ===
                                         
         P0 ──────┐                 
         P1 ──────┫                 
         P2 ──────┫                 
         P3 ──────┫                 
         P4 ──────┫                 
         P5 ──────┫                 
         P6 ──────┫                 
         P7 ──────┫                             
         P8 ──────┫                                                                    
         P9 ──────┫                 
              220Ω     │                 
                       │                 
                         GND             
     
    }}
    CON
      'let the compiler know which crystal and PLL settings to use
      _xinfreq = 5_000_000
      _clkmode = xtal1 + pll16x
      _timeStepInMilliseconds = 20
      _updateFrequencyInHertz = 50
      INPUT         = false         'bit pattern is all 0s
      OUTPUT        = true          'bit pattern is all 1s
      PC_BAUD       = 115_200       'PC serial terminal's baud rate
      
      ADC_CH0       = 1 << 0
      ADC_CH1       = 1 << 1
      ADC_CH2       = 1 << 2
      ADC_CH3       = 1 << 3
      ADC_ALL       = ADC_CH0 + ADC_CH1 + ADC_CH2 + ADC_CH3
      'LED Bar graph pin definitions
      BAR_GRAPH_0   = 0
      BAR_GRAPH_1   = 1
      BAR_GRAPH_2   = 2
      BAR_GRAPH_3   = 3
      BAR_GRAPH_4   = 4
      BAR_GRAPH_5   = 5
      BAR_GRAPH_6   = 6
      BAR_GRAPH_7   = 7
      BAR_GRAPH_8   = 8
      BAR_GRAPH_9   = 9
      Servo_Run     = 14
    OBJ
      adc    :     "PropBOE ADC"                           'Requires 1 cog
      pc     :     "Parallax Serial Terminal"              'Requires 1 cog
      system :     "Propeller Board of Education"          'PropBOE configuration tools
      time   :     "Timing"                                'Timekeeping and delay object
      servo  :     "PropBOE Servos"                        'Servo control object 
      dac    :     "TestWav"                          ' SD Card/Wave Plaer
    VAR
      'Globally accessible variables, shared by all cogs
      byte pressure
      long cogStack[20]
     
    PUB Go | rawReading
      'Start other objects
      pc.Start(PC_BAUD)
      adc.Start(ADC_CH0)
      
      'Launch additional cogs
      
      cognew(RunBarGraph, @cogStack)
      
      repeat
        rawReading := adc.In(0)                             'Get the reading from channel 0 on the ADC.
        pressure := rawReading / 25                         'Scale the raw reading to be displayed on the LED bar graph.
                                                            'Note that this scaled reading does not correspond with a particular
                                                            'unit of pressure such as mmH2O, mmHg, kPa, or PSI.  Check the sensor's
                                                            'datasheet (MPX5010DP) for the mV/mmH2O conversion value if you want an
                                                            'absolute reading in a particular unit of pressure.
                                                                                                       '
                                                            'The global variable "pressure" is shared between this cog and the cog
                                                            'that is controlling the LED bar graph.  
        '===== Print to the PC serial terminal =====
        pc.Home
        pc.Str(string("=== Pressure Sensor Test ==="))
        pc.NewLine
        pc.NewLine
        pc.Str(string("Raw ADC Value: "))
        pc.dec(rawReading)
        pc.Chars(" ", 5)
        pc.NewLine
        
          if rawReading >= 150                              ' Set rawReading accordingly to turn servo on 
           servo.Set(14, 200)                                ' Servo on pin 14 counterclockwise
           servo.Set(15, -200)
           dira[11] :=1
           outa[11] :=1
           Chimes   ' like this put the call here, although I don't have a way of testing this to see if the call affects the servos running 
          elseif rawReading <149                             ' Set rawReading accordingly to stop servo
           servo.stop
           servo.stop
           dira[11] :=0
           outa[11] :=0                                        ' Stop servo
                   
          waitcnt(cnt + clkfreq/20)                     'wait for ~1/20th seconds so as not to flood the computer's serial port with data.
    PUB Chimes 
     dac.playwavfile(string("Chimes.wav"))
     
    PUB RunBarGraph | i
       
      dira[BAR_GRAPH_9..BAR_GRAPH_0] := OUTPUT              'set range of pins to output
                                                            '(this works in this case because the pins are consecutive)
                                      
      
      repeat
        outa[BAR_GRAPH_9..BAR_GRAPH_0] := 1<<pressure - 1   'Continually set the value of the scaled pressure to the LED bar graph pins.
                                                            'Do a little bitwise manipulation to make the LEDs look nice.
        
    
    DAT
     
    {{
    
  • ratronicratronic Posts: 1,451
    edited 2013-04-20 13:40
    You will need to include the entire CON section from above with your program. And these lines to start everything -
    dac.FATEngineStart(_dopin, _clkpin, _dipin, _cspin, _wppin, _cdpin, _rtcres1, _rtcres2, _rtcres3)     
    dac.DACEngineStart(constant(_lpin | (not(not(_ditherEnable)))), constant(_rpin | (not(not(_ditherEnable)))), _volume)  
    
    if(_ditherEnable)
      dac.DACDitherEngineStart(_lpin, _rpin, _ditherLevel)
    
    and then when your ready to play it in your program include these two lines instead of calling chimes and you can loose the chimes Pub method -
    if not dac.waveplayerstate                                  
      dac.playwavfile(string("chimes.wav"))
    
    The chimes.wav takes ~.8 of a second to play before it returns. I'm not sure what you are trying to do.

    You can also put more than one wav file on your SD card and call those sounds by substituting the name "chimes.wav" in your program to play that wav.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 14:09
    That did not work. I hear the speaker kick on and then off but the rest of the program does not run correctly and the chimes.wav file does not play. What I am trying to accomplish is when the pressure reaches 150 the 2 servos run, the bar graph runs, an LED lights up and a wav file will play. I have everything but the wav file portion working correctly. I may just go back to the one I know that worked even though it is overkill on the code.
  • ratronicratronic Posts: 1,451
    edited 2013-04-20 14:14
    NW post what you last tried using the Propeller tool - File/Archive/Project and attach the zip file it creates here.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 14:41
    Here you go.
  • ratronicratronic Posts: 1,451
    edited 2013-04-20 14:54
    I do not have that sensor but running your code I get the chimes sound constantly repeating. I notice you need to indent one line "dac.playwavfile(string("chimes.wav")) " a couple of spaces. But I get sound indented or not. Are you using a PropBOE board?
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 15:15
    Yes, I am using a Prop BOE board with a 9V wall wart. I will try a couple things a little later and get back to you. Thanks for all the help.

    Edit. There must be an issue somewhere as the chimes.wav file should only play once the pressure reaches 150.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 15:47
    OK. I got it figured out. I need a little more power to run everything. I commented out one of my servos and it worked. Once I uncommented the servo it quit working again. Just need to dig up a 12V wall wart and all should be fine. Thanks again for all your help.
  • ratronicratronic Posts: 1,451
    edited 2013-04-20 16:13
    Good! I was going to remind you to watch your indenting but I'm glad you sorted it out.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-04-20 16:27
    All fixed now. I swapped out the 9V wall wart for a 12V one and it works great now. I ended up placing your code after the last BarGraph code and left PUB Chimes. I then placed a call to Chimes in my IF RawReading >= 150. I also modified the code so the Servo and LED start and stop function jumped to PUB Start and PUB Stop. This is working as expected now. Not that anyone will ever need this code but I am attaching it any how just in case someone needs an example to start from. Thanks again for all your help. :):)
  • cavelambcavelamb Posts: 720
    edited 2013-04-20 18:54
    It's not voltage that was lacking, but amperage.
    12 volts is awful high for that regulator to handle.

    Look at the warts carefully.
    Every one of them has a rating statement somewhere.

    It will say X volts - Y ma
    or X volts DC - Y watts

    What was the 9 volt current rating?
    What is the 12 volt wart's rating?

    What you probably want is a 7 volt 2 amp wart.
    Not so much voltage to drop across the regulator and plenty of current.
Sign In or Register to comment.