PDA

View Full Version : Timing diagram for MSGEQ7 spectrum analyzer chip, is it correct?



CuriousOne
- 5th July 2016, 10:18
Hello. I want to build a audio spectrum analyzer using this chip. The picture below is from datasheet:

8263

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



'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?

HenrikOlsson
- 5th July 2016, 11:54
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

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

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.

CuriousOne
- 5th July 2016, 13:01
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.

OldMarty
- 6th July 2016, 01:52
* 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.

richard
- 6th July 2016, 02:05
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

OldMarty
- 6th July 2016, 06:19
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.

OldMarty
- 6th July 2016, 06:23
Hello. I want to build a audio spectrum analyzer using this chip. The picture below is from datasheet:

8263

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



'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 ;-)

CuriousOne
- 7th July 2016, 05:24
So, my general idea is correct, and I can go on with hardware?

Grantwt
- 20th November 2021, 15:50
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:



'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

mpgmike
- 20th November 2021, 16:53
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:


Some Variable = Some SFR Value