Shop OBEX P1 Docs P2 Docs Learn Events
Goertzel from ADC+Streamer — Parallax Forums

Goertzel from ADC+Streamer

cgraceycgracey Posts: 14,152
edited 2018-03-27 22:48 in Propeller 2
I'm done proving out all the pads on the latest test chip. Everything was spot-on, except the PLL, which I believe is in good shape now.

The last thing to try out was the Goertzel circuit. This brings all kinds of capability together. It uses an ADC on a pin, in conjunction with the streamer and CORDIC solver to perform frequency-power measurements. It can even output a sine and cosine on separate DAC pins, while some echoed version of either comes back in through an ADC pin. It resolves phase difference and power.

In my test, since I know the output already works, I tried out the input, never minding the output potential. I let it accumulate sine and cosine samples multiplied by the ADC bit stream, treating 0's as -1 and 1's as 1 coefficients. In my test, after 16 complete target-frequency cycles, I grab the sine and cosine accumulations and perform a cartesian-to-polar conversion on them to render power level of the target frequency in the ADC bitstream. Then, I get the power into a byte and output it onto a DAC pin which the scope shows. It's looking for 3.33MHz:

(pictures in next post, due to modern computer problems)

Comments

  • cgraceycgracey Posts: 14,152
    edited 2018-03-27 22:31
    Goertzel.jpg

    Here's the code that does it:
    dat		org
    
    		hubset	#$FF
    
    ' make a sin/cos table in LUT and then output it to dacs 1/0
    ' switches between 1x and 2x frequency
    
    doit		wrpin	adcmode,#4		'enable adc mode on pin 4
    		bith	dira,#5			'enable output on pin 5
    
    		mov	z,#$1FF			'make 512-sample sin/cos table in lut
    sincos		mov	x,z			'get angle into top 9 bits of x
    		shl	x,#32-9
    		qrotate	#$7F,x			'get sin/cos of (ro,theta)
    		getqx	x			'get cos
    		getqy	y			'get sin
    		setbyte	x,y,#1			'get sin into byte1, cos in byte0
    		setword	x,x,#1			'copy bytes 1,0 to 3,2
    		xor	x,##$8080		'make bytes 1,0 positive (not used, but could be)
    		wrlut	x,z			'write sin:cos:psin:pcos into lut bottom bytes
    		djnf	z,#sincos		'make 512 samples
    
    loop		setq	f1			'ready frequency
    		xcont	m1,#0			'issue Goertzel command
    		getxacc	x			'get last Goertzel accumulations, x first
    		mov	y,0			'y comes through s
    		qvector	x,y			'convert (x,y) to (rho,theta)
    		getqx	x			'get rho (power measurement)
    		shr	x,#5			'scale into byte
    		sca	x,##$7700
    		setbyte	dacmode,0,#1		'update dac pin (scaled byte comes through s)
    		wrpin	dacmode,#5
    		jmp	#loop			'loop
    
    
    adcmode		long	%0000_0000_000_1000110000000_01_00000_0		'adc
    dacmode		long	%0000_0000_000_1010000000000_00_00000_0		'dac
    
    f1		long	round(3_333_333.3/80_000_000.0 * float($80000000))	'3.33MHz
    
    m1		long	4<<17 + 16	'Goertzel mode, pin 4 input, 16-cycle measurement
    
    x		res	1
    y		res	1
    z		res	1
    
    996 x 812 - 165K
  • cgraceycgracey Posts: 14,152
    Here it is averaged 16x:

    Goertzel2.jpg
    2048 x 1152 - 716K
  • cgraceycgracey Posts: 14,152
    edited 2018-03-27 22:49
    And in case you need that in log form, you can add these three instructions (in the middle):
    		getqx	x			'get rho (power measurement)
    
    		qlog	x			'get log of rho
    		getqx	x
    		shr	x,#17			'shift it into range
    
    		shr	x,#5			'scale into byte
    

    Goertzel3.jpg

    The CORDIC makes some otherwise-extremely-tedious things super easy and fun in assembly language.
    2048 x 1152 - 745K
  • When Phil Pilgrim wrote that object that responds to spoken commands based on Goertzel's algorithm my jaw dropped. When we get the P2 the Goertzel circuit will be one of the first things I intend to learn about. Great job Chip!
  • I agree, this is just great.

    Now to dissect the code... think there's a lot of help going on with streamer and smart pin
  • cgraceycgracey Posts: 14,152
    edited 2018-03-28 00:10
    lardom wrote: »
    When Phil Pilgrim wrote that object that responds to spoken commands based on Goertzel's algorithm my jaw dropped. When we get the P2 the Goertzel circuit will be one of the first things I intend to learn about. Great job Chip!

    Voice projects I see on Youtube tend to demonstrate mere connectors back to Google's voice system. Bringing in the cloud is so anticlimactic. They only tell you what they want you to know, and they harvest every bit of information they gather. Then, they interpret what you say through their lens, which does things like apply capitalization on incidental words and phrases that happen to be trademarks. And someday, when they determine that they really don't like you for some secret reason, your system won't work. Not cool.
  • Neat!

    Having analog functionality on P2 will be a game changer IMO.
  • lardomlardom Posts: 1,659
    edited 2018-03-28 01:55
    cgracey wrote: »
    Voice projects I see on Youtube tend to demonstrate mere connectors back to Google's voice system. Bringing in the cloud is so anticlimactic. They only tell you what they want you to know, and they harvest every bit of information they gather. Then, they interpret what you say through their lens, which does things like apply capitalization on incidental words and phrases that happen to be trademarks. And someday, when they determine that they really don't like you for some secret reason, your system won't work. Not cool.
    I posted Phil's object on YouTube. Here's the video.


Sign In or Register to comment.