Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    Hello. I want to build a audio spectrum analyzer using this chip. The picture below is from datasheet:

    Name:  DMESG7.jpg
Views: 1672
Size:  71.6 KB

    Below is the sample code I've created for reading the chip:

    Code:
    'INIT
    
    HIGH RESET 
    HIGH STROBE 
    PAUSEUS 18 
    LOW STROBE
    PAUSEUS 18
    LOW RESET
    HIGH STROBE
    PAUSEUS 18
    
    'READING
    
    LOW STROBE
    ADCIN 1, VALUE
    BAND=1
    GOSUB DISPLAY
    PAUSEUS 18
    HIGH STROBE
    PAUSEUS 18
    
    LOW STROBE
    ADCIN 1, VALUE
    BAND=2
    GOSUB DISPLAY
    PAUSEUS 18
    HIGH STROBE
    PAUSEUS 18
    
    LOW STROBE
    ADCIN 1, VALUE
    BAND=3
    GOSUB DISPLAY
    PAUSEUS 18
    HIGH STROBE
    PAUSEUS 18
    To simplify the things, code above reads only data for 3 frequencies, full code will read 7 frequencies, then repeat in loop. Is above code correct, how do you think?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    As usual, have YOU tried it yourself?

    Random comments:
    * Don't use HIGH/LOW, they're wasting time and program space.
    * After STROBE goes LOW (active) there's a 36us (minimum) settling time so I'd wait that amount of time before sampling the output.
    * The ADCIN statement is likely to take longer than the needed 18us so there shouldn't be a need to have that delay in there.
    * What's being done in the display subroutine? Does it take longer than 18us? If so move things around and eliminate the other delay as well
    Code:
    FOR Band = 0 to 6
      STROBE = 0
      PAUSEUS 36   ' Wait specified settling time
      ADCIN 1, Value   ' Take a reading, this will take tens of uS depending on how the ADC is setup.
      STROBE = 1
      GOSUB Display  ' This will also take time so we'll most likely meet the 72us minimum strobe to strobe time - needs verifying.
    NEXT
    Or, sample all bands and then display them
    Code:
    Spectrum VAR BYTE[7]
    Band VAR BYTE
    FOR Band = 0 to 6
      STROBE = 0
      PAUSEUS 36   ' Wait specified settling time
      ADCIN 1, Spectrum[Band]
      STROBE = 1
      PAUSEUS 36   ' Can probably be removed altogether since ADCIN will provide the needed "delay".
    NEXT
    The above has obviously not been tested, it's being provided as food for thought.

    /Henrik.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    No, I haven't tested yet by myself, because I need to assemble circuit, etc. So instead I decided to check software first.

    This code was just an example how I understand timings, in real code I won't use HIGH and LOW statements.
    Display subroutine will either drive MAX7219 with 8x8 led matrix connected, or will multiplex 5x7 discrete leds.

  4. #4
    Join Date
    Jun 2016
    Location
    Melbourne, Australia
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    Quote Originally Posted by HenrikOlsson View Post
    * Don't use HIGH/LOW, they're wasting time and program space.
    /Henrik.
    Excuse my ignorance, but what's the alternative to setting bits without using high/low?
    Is it preferable just to use "PORTB.1 = 1" etc?

    Regards,
    Marty.
    Last edited by OldMarty; - 6th July 2016 at 02:55.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    Excuse my ignorance, but what's the alternative to setting bits without using high/low?
    Is it preferable just to use "PORTB.1 = 1" etc?
    yes or EVEN BETTER LATB.1 = 1 if chip has LAT regs

    high/low always resets TRIS bit wether it needs to or not (ie already set to output)
    which takes a

    BANKSEL TRISX
    BCF TRISX,PIN
    BANKSEL PORTX
    BSF/BCF PORTX,PIN
    BANKSEL 0

    HEAPS OF STUFF
    Warning I'm not a teacher

  6. #6
    Join Date
    Jun 2016
    Location
    Melbourne, Australia
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    Quote Originally Posted by richard View Post
    high/low always resets TRIS bit wether it needs to or not (ie already set to output)
    which takes a

    BANKSEL TRISX
    BCF TRISX,PIN
    BANKSEL PORTX
    BSF/BCF PORTX,PIN
    BANKSEL 0

    HEAPS OF STUFF
    wow, that's a lot of junk going on ;-)
    thanks.

  7. #7
    Join Date
    Jun 2016
    Location
    Melbourne, Australia
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    Quote Originally Posted by CuriousOne View Post
    Hello. I want to build a audio spectrum analyzer using this chip. The picture below is from datasheet:

    Attachment 8263

    Below is the sample code I've created for reading the chip:

    Code:
    'INIT
    
    HIGH RESET 
    HIGH STROBE 
    PAUSEUS 18 
    LOW STROBE
    PAUSEUS 18
    LOW RESET
    HIGH STROBE
    PAUSEUS 18
    
    'READING
    
    LOW STROBE
    ADCIN 1, VALUE
    BAND=1
    GOSUB DISPLAY
    PAUSEUS 18
    HIGH STROBE
    PAUSEUS 18
    
    LOW STROBE
    ADCIN 1, VALUE
    BAND=2
    GOSUB DISPLAY
    PAUSEUS 18
    HIGH STROBE
    PAUSEUS 18
    
    LOW STROBE
    ADCIN 1, VALUE
    BAND=3
    GOSUB DISPLAY
    PAUSEUS 18
    HIGH STROBE
    PAUSEUS 18
    To simplify the things, code above reads only data for 3 frequencies, full code will read 7 frequencies, then repeat in loop. Is above code correct, how do you think?

    Just thought i'd mention you're using 18uSecs for your strobe pulses....

    Looking at the diagram, 18uS is the MINIMUM duration, so you're right on the edge of it not strobing, or being intermittent about strobing the chip or not.
    I'd be inclined to make your strobes 20,25 or even 30uSecs duration to be certain it'll trigger the chip consistently.

    Just my 2cents ;-)

  8. #8
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    So, my general idea is correct, and I can go on with hardware?

  9. #9
    Grantwt's Avatar
    Grantwt Guest


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    From the datasheet the times stated are for the minimum times, therefore I went with 100uS not 18uS, also I used a FOR NEXT loop to keep the code short. I am using an 18F252 to read from the ADC and outputting onto a standard LCD, using two arrays of seven each in the code variables for the code setup:

    Code:
    'Port Definitions
    RESET  VAR PORTB.6
    STROBE VAR PORTB.7
    
    'Variables
    AD0  VAR WORD  ' A to D 1 variable holder
    AD1  VAR WORD  ' A to D 2 variable holder
    RD VAR WORD[7] ' Right ADC value
    LD VAR WORD[7] ' Left ADC value
    C  VAR WORD    ' Count variable holder
    
    TRISA = 1111            ' Set as outputs & inputs
    TRISB = 000000        ' Set as outputs
    LOW RESET 
    LOW STROBE     
    
    'Here is the working code:
    
    REM ============================== LCD Setup ===================================
    LCDOUT $FE,$40,$00,$00,$00,$00,$00,$00,$00,$1F ' Bar 1
    LCDOUT $FE,$48,$00,$00,$00,$00,$00,$00,$1F,$1F ' Bar 2
    LCDOUT $FE,$50,$00,$00,$00,$00,$00,$1F,$1F,$1F ' Bar 3
    LCDOUT $FE,$58,$00,$00,$00,$00,$1F,$1F,$1F,$1F ' Bar 4
    LCDOUT $FE,$60,$00,$00,$00,$1F,$1F,$1F,$1F,$1F ' Bar 5
    LCDOUT $FE,$68,$00,$00,$1F,$1F,$1F,$1F,$1F,$1F ' Bar 6
    LCDOUT $FE,$70,$00,$1F,$1F,$1F,$1F,$1F,$1F,$1F ' Bar 7
    LCDOUT $FE,$78,$0E,$0A,$0A,$0A,$0A,$0A,$0A,$0E ' Bar over
    LCDOUT 254,1                        ' Clear display 
    
    REM ============================== Main loop ===================================
    Main:
    GOSUB EQread
    GOSUB Display
    PAUSE 10
    GOTO Main
    
    REM ============================= MSGEQ7 code ==================================
    EQread:
    HIGH RESET   'Reset
    HIGH STROBE 
    PAUSEUS 100 
    LOW STROBE
    PAUSEUS 100
    LOW RESET
    HIGH STROBE
    PAUSEUS 100
    FOR C=0 TO 6  'Read
    LOW STROBE
    PAUSEUS 100
    ADCIN 0,AD0
    RD[C]=AD0
    ADCIN 1,AD1 
    LD[C]=AD1
    HIGH STROBE
    PAUSEUS 100
    NEXT C
    LOW STROBE 
    RETURN
    
    REM =============================== Display ====================================
    Display:
    FOR C=0 TO 6
    RD[C]=RD[C]/8192
    LD[C]=LD[C]/8192
    IF RD[C]=0 THEN
    RD[C]=$20
    ELSE
    RD[C]=RD[C]-1
    ENDIF
    IF LD[C]=0 THEN
    LD[C]=$20
    ELSE
    LD[C]=LD[C]-1
    ENDIF
    NEXT C      
    LCDOUT 254,129,LD[0],LD[1],LD[2],LD[3],LD[4],LD[5],LD[6]," ",RD[0],RD[1],RD[2],RD[3],RD[4],RD[5],RD[6]       ' Display output on line 1      
    RETURN
    END
    Last edited by Ioannis; - 21st November 2021 at 15:31.

  10. #10
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?

    Welcome to our community, Grant. Looks like you are familiar with PBP already. Thanks for sharing your work. For future posts, you can put code in a smaller window by using [ CODE ] at the beginning of your code (without the spaces) and at the end, add [ / CODE ] (again, without the spaces). It looks like this:
    Code:
    Some Variable = Some SFR Value

Similar Threads

  1. How to define OSC for vlaues below 1mhz? so you get the timing correct.
    By ofuzzy1 in forum FAQ - Frequently Asked Questions
    Replies: 1
    Last Post: - 3rd May 2011, 17:17
  2. Timing Diagram software suggestions?
    By PickyBiker in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th April 2010, 07:11
  3. Circuit Diagram Applications
    By -Dan- in forum General
    Replies: 5
    Last Post: - 11th April 2009, 07:32
  4. Circuit Diagram for interfacing AC to PIC IC?
    By wellyboot in forum Schematics
    Replies: 3
    Last Post: - 8th March 2008, 20:40
  5. Poor mans "semi" logic analyzer
    By anj in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st September 2004, 14:26

Members who have read this thread : 2

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