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


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    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.

  2. #2
    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 ?

  3. #3
    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.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    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.

  5. #5
    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, 18:51
  2. Volume Control On Piezo
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th August 2007, 05:34
  3. sound command
    By micro in forum General
    Replies: 0
    Last Post: - 1st April 2006, 19:09
  4. Volume Control IC's
    By HarryK in forum General
    Replies: 0
    Last Post: - 8th March 2005, 09:46
  5. Sound and sound control with minimal parts
    By bartman in forum General
    Replies: 23
    Last Post: - 18th January 2005, 15: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