I want to control the volume of the output using Sound command.


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2013
    Posts
    17

    Default I want to control the volume of the output using Sound command.

    I am going to use SOUND command to produce a white noise.

    Is there any way to control from the program the volume of the output ?

    I want to take a result with max volume and then the volume will decrease to minimum. Something like this |\ |\ |\.

    The noise of a steam train engine.

    It is here, http://usuaris.tinet.cat/fmco/download/TuShuuu10.asm but i don't know assembly, and here http://usuaris.tinet.cat/fmco/dccfunc_en.html Tushuuu project.

    Thank you!

  2. #2
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    What specifically are you trying to do? Change the volume in a pattern, or just make it louder / softer?
    If it's the latter, changing the final 358 stage to include a variable resistor would be simplest.

  3. #3
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    I want to make the sound of chuff-chuff.

  4. #4
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    My issue is that i don't know how to create white noise, without using the SOUND command.
    If i knew, it would be easier to me, to make the pattern of the sound i want.

    The other choice is to to connect the output of the sound to a transistor and with an interrupt and PWM output to the base of the transistor.

  5. #5
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    To me, white noise is a random frequency in the audible range. Using the SOUND command gives you a specific frequency. Packing together commands to give you a randomish frequency won't be what I think of as white noise.

    To make a specific sound, as the whistle on a train, or music, the chuff-chuff sound, will require you to know the frequency or key of the sound and use the sound command to approximate it.

    From experience I've found feeding the output from a 12F683 into a speaker doesn't generate a very "loud" sound. You'll have to amplify it somehow and I don't know why you couldn't use a pin off the the chip to control the volume of the sound. I'm sure someone will shoot a hole in that theory but why not?

    I'm thinking if you're going to go through that trouble why don't you get an actual recording of the train whistle or horn signals and put them on a SD card and just have it play into the amplifier? Might be easier and sound better than trying to approximate locomotive horn signals with a PIC.

    My nickels worth.

  6. #6
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    Actually, If i knew the frequency of sound command 255, which is a white noise, it would be easy for me to edit it.
    Paco here http://usuaris.tinet.cat/fmco/dccfunc_en.html has made it with Tushuuu and assembly.

    He uses TMR2 as PWM generator for sound, Vref module for volume control, TMR1 for Envelope timing, TMR0 for software noise generator, internal comparator for mixing sound and noise.
    RB0 is DCC input, RB3 (PWM) conected to RA1 (comparator), RA2 outputs to a buffer OPAMP, RA4 to OPAMP output throught a resistor and to another OPAMP buffer for output to a buzzer.

    The size of the circuit is the reason that i need software edit of the sound. The circuit must be very small.

  7. #7
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    I wrote this, but it is very slow.
    The pic is 16F1824, and RA2 is connected to the base of BC547, RC3 to opamp and the output of the opamp to the collector of BC547 and emmiter to speaker.


    @ __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    @ __config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF

    DEFINE OSC 4

    OSCCON = %01101000 '4mhz oscillator

    DEFINE CCP3_REG PORTA 'Channel-1 port
    DEFINE CCP3_BIT 2 'Channel-1 bit

    TRISA = 0
    TRISC = 0 ' OUTPUT
    ANSELA = 0
    ANSELC = 0

    OPTION_REG.7=0 ' Weak pullup enabled
    OPTION_REG.6=0 ' Interrupt Edg Select bit
    OPTION_REG.5=0 ' TMR0CS Timer0 Clock Source select
    OPTION_REG.4=0 ' TMR0CS Timer0 Source edge select
    OPTION_REG.3=0 ' Prescaller assignemnet (0-> timer0)
    OPTION_REG.2=1 ' Prescaller rate
    OPTION_REG.1=1 ' Prescaller rate
    OPTION_REG.0=1 ' Prescaller rate
    'Prescaler 1:256, INTERRUPT every 65,536ms


    x var BYTE

    ON INTERRUPT GOTO ISR
    INTCON = %10100000 ' enable TMR0 and GLOBAL
    X = 0

    GOTO START

    START
    sound portc.3, [255, 65535]
    goto START


    ISR:
    disable
    X=X+5
    IF X>255 THEN
    X=0
    ENDIF

    hpwm 3,x,20000

    INTCON.2=0

    resume
    enable

    end

    Where is my mistake ?

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,607


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    Hi,
    First of all, the manual states that the duration part of the sound statement should be 0-255, you're specifying 65535.
    Second, and what I think is the main "mistake", is in your interpretation of how ON INTERRUPT works.

    ON INTERRUPT isn't a real hardware interrupt. It will only check the interrupt flag between each PBP statement. If you specify a sound duration of 255 the sound command takes 255*12ms=3060ms so the ISR will only execute once ever ~3 seconds even if TMR0 overflows once every 65ms. Had it worked with 65535 as the duration the ISR would only execute every 786th second.

    Finally, doing things like IF X>255 THEN when X is declared as a BYTE doesn't do anything because X can never be larger than 255 anyway. You can safely keep adding 5 to it, it will wrap around by itself.

    Hope it helps.

    /Henrik.

  9. #9
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    Yes you are right.
    How can i make a real interrupt ?

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    You can use
    http://darreltaylor.com/DT_INTS-14/intro.html
    This is the easy way.

    Or you can read in the manual for an explanation on how to write your own.
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,607


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    I don't see the need for an interrupt for what you're doing there.
    Code:
    X = 5
    Start:
       HPWM 3, X, 20000
       SOUND PortC.3, [255, 5]   ' Make sound for ~60ms
       X = X + 5
    Goto Start
    Though I'd probably setup the CCP module manually and write to the dutycycle register instead of using the HPWM command since I Believe you'll get some discontinuties in the output when constantly changing the dutycycle using HPWM - may be wrong on that and/or it may not matter in your case, try it.

    /Henrik.

  12. #12
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: I want to control the volume of the output using Sound command.

    Totaly, i have tried all the methods you have suggested me, unfortunately the results wasn't so good.
    In every case, there was a small interrupt on the sound.

    I decided to produce the white noise by an external small circuit, and then to process it with PWM.

    Thank you all.

Similar Threads

  1. pt2258+16f877 how can i use for 5.1 volume control ?
    By whyliving in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th January 2008, 17:51
  2. Volume Control On Piezo
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th August 2007, 04:34
  3. sound command
    By micro in forum General
    Replies: 0
    Last Post: - 1st April 2006, 18:09
  4. Volume Control IC's
    By HarryK in forum General
    Replies: 0
    Last Post: - 8th March 2005, 08:46
  5. Sound and sound control with minimal parts
    By bartman in forum General
    Replies: 23
    Last Post: - 18th January 2005, 14:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts