Looking for example code of using the streamer to generate a sine wave output on the dac (solved)

BeanBean Posts: 8,116
edited 2020-10-14 - 16:24:06 in Propeller 2
Specifically I'm trying to generate a 9.999MHz sine wave with a system clock of 250MHz, but I'll take anything I can get.

I'm confused because is the DAC in the streamer or in the smart pin ? I see references to both.

Thanks,
Bean

Comments

  • TubularTubular Posts: 4,086
    edited 2020-10-09 - 19:12:30
    The DACs are physically in the smartpins (pin pad analog circuitry) . There are two DACs, each having two resistors in order to give the 75/123/600/1k driving impedance options. There is also a separate, slower dac used in "Pin A>D" comparator mode to set the D threshold, but thats in the incoming signal side.

    If you look at Chip's Goertzel demos he is streaming a few different sine waves from lut tables to the DACs, where the channels streamed have 90 (4ch) or 120 (3ch) phase shifts between them
  • evanhevanh Posts: 9,956
    edited 2020-10-10 - 04:20:13
    The smartpins aren't really involved between the streamer and the DAC/pin drive. Smartpins have their own paths. Discussion of overview - https://forums.parallax.com/discussion/171420/smartpin-diagram-now-with-p-p-bit-mode-table/p1
    SmartpinDiagram4a.png
  • Tubular wrote: »
    If you look at Chip's Goertzel demos he is streaming a few different sine waves from lut tables to the DACs, where the channels streamed have 90 (4ch) or 120 (3ch) phase shifts between them

    Does anyone have a link to this demo ?

    Thanks,
    Bean
  • dMajodMajo Posts: 823
    edited 2020-10-12 - 20:29:48
    Here you go
    https://forums.parallax.com/discussion/170783/goertzel-board-demo-for-p2-rev-b

    I think that the demo code was also included in v33 pnut release
  • Thanks.
    Bean
  • RaymanRayman Posts: 11,349
    edited 2020-10-13 - 16:28:45
    There's a DDS example from Chip around that can output any waveform you like from a table...

    There's also a .wav file player around that can show you some tips.

    But, for just a sin wave, I guess I'd use the cordic qrotate function to generate samples...
  • Oh wait... do you really want to use the streamer?
  • BeanBean Posts: 8,116
    edited 2020-10-13 - 17:53:27
    Yeah, I just want the streamer to make a sine wave on the DAC.
    I assume it can do that without the COG being involved ? Once it is setup of course.
    From what I read, I assume you have to use Goertzel mode, but I don't know that for sure.

    Any help would be appreciated,
    Bean

    P.S. I'm using PASM2, but SPIN2 code will probably help too.
  • RaymanRayman Posts: 11,349
    edited 2020-10-13 - 19:18:38
    Check out Chip's HDMI scope with DDS example code here:

    https://forums.parallax.com/discussion/170820/hdmi-4-channel-oscilloscope-demo/p2

    Just pull out the DDS part and tweak for your needs.

    He generates the wave data in the LUT and then uses the stream to output it...
    Somehow, he can vary the waveform frequency too.
    I used to know how that worked, but forgot...
  • Thanks Rayman,
    I'll look at it tomorrow when I'm back at work.
    I don't have a scope here at home.

    Bean
  • Thanks to everyone's help I got it working.
    Here it what I have:
    '****************************************
    '*  Use streamer to generate sine wave  *
    '****************************************
    
    CON
    	dds_base	= 0 		'Pin for sine output (must be a multiple of 4)
    	dds_freq        = 1_234_567.0	'Frequency of sine output
    
    	freq		= 250_000_000.0	'System clock frequency
    
    DAT	org
    
    ' Setup for 250MHz system clock
    	hubset  ##%1_000001_0000011000_1111_10_00       'config PLL, 20MHz/2*25*1 = 250MHz
    	waitx   ##20_000_000 / 200                      'allow crystal+PLL 5ms to stabilize
    	hubset  ##%1_000001_0000011000_1111_10_11       'switch to PLL
    
    ' Setup streamer in DDS/Goertzel mode
    	cogid	cogNum			'Init DAC pins for this cog's DAC channels
    	setnib	dacmode,cogNum,#2       'Modify dacmode value for this cog
    	wrpin	dacmode,#3<<6+dds_base	' ???
    	dirh	#3<<6+dds_base		' ???
    
    ' Create sine pattern in LUT
    	mov	index,#$1FF		'make 512-sample DDS table in LUT
    .lut
    	shl	index,#32-9		'Scale index up to 32 bits
    	qrotate	#127,index		'Compute sine of index, amplitude of 127 using cordic
    	shr	index,#32-9		'Scale index down to 9 bits
    	getqy	sinValue		'Get sine value from cordic
    
    	wrlut	sinValue,index		'write sine value into LUT
    	djnf	index,#.lut		'loop until 512 samples are written to LUT
    
    ' Start streamer
    	xcont	dds_d,dds_s		'issue perpetual DDS/Goertzel command
    	setxfrq	xfreq			'Set streamer frequency
    
    	jmp	#$			'Stop here (Streamer creates sine wave)
    
    ' Data
    
    dacmode		long	%0000_0000_000_10110_00000000_01_00000_0	'DAC mode, cog DAC channels
    			' ???
    
    xfreq		long	round(dds_freq/freq * 65536.0 * 32768.0)	'streamer frequency value
    
    dds_d		long	%1111_0001_0_000_0_111 << 16 + $FFFF		'DDS/Goertzel mode, continuous
    			'1111  . . . . . . . . DDS/Goertzel mode
    			'     0001 . . . . . . Output X0 on DAC channel 0
    			'          0 . . . . . SINC1 filtering (doesn't matter for DDS)
    			'            000 . . . Pin group (not used by DDS mode)
    			'                0 . . Bottom first / Top first selection (???)
    			'                  111 Always for DDS/Goertzel mode 
    
    dds_s		long	%0000_0000_000_000000000			'DDS/Goertzel mode, no input
    			'0 . . . . . . . . . . . Base pin +3 is summed (1 means inverted and summed) 
    			' 0  . . . . . . . . . . Base pin +2 is summed (1 means inverted and summed) 
    			'  0 . . . . . . . . . . Base pin +1 is summed (1 means inverted and summed) 
    			'   0  . . . . . . . . . Base pin +0 is summed (1 means inverted and summed) 
    			'     0  . . . . . . . . Base pin +3 is ignored (1 means is used)
    			'      0 . . . . . . . . Base pin +2 is ignored (1 means is used)
    			'       0  . . . . . . . Base pin +1 is ignored (1 means is used)
    			'        0 . . . . . . . Base pin +0 is ignored (1 means is used)
    			'          000 . . . . . Use LUT of 512 entries
    			'              000000000 Offset if using less than 512 LUT entries
    
    
    cogNum          res	1
    index		res	1
    sinValue	res	1
    
    
    

    If anyone can tell me what the values that I have ??? as comments for, I will add that info.

    Bean
  • Did you actually get 9.999MHz?

    That seems like a lot of precision...
  • jmgjmg Posts: 14,492
    Rayman wrote: »
    Did you actually get 9.999MHz?

    That seems like a lot of precision...

    The DOCs say you should get
    250M/0x80000000*(round(0x80000000*9.999M/250M)) = 9999000.00169 Hz
    and the next step is 9999000.118114 Hz
    with a step size of 116.415mHz
    There will be some jitter on that from the DDS adder quantize, plus some PLL jitter, but those averages will be the result.
  • BeanBean Posts: 8,116
    edited 2020-10-14 - 20:31:58
    I couldn't tell how exact it was because the oscillator on the eval board was drifting, but it was pretty close (after adjusting for the oscillator offset).

    Just so everyone knows, I spent a couple hours because there was a glitch on the sine wave and I couldn't figure out a way to get rid of it.

    Then, while removing code from Chip's demo I removed the code that generated the triange, sawtooth and squarewave on the other pins and it magically went away. Doh....

    Bean
  • RaymanRayman Posts: 11,349
    edited 2020-10-15 - 00:49:15
    Is that a rev A P2?
    That sort of coupling was fixed in rev.B silicon ...
  • RevC fixed an ADC crosstalk in the resistor networks. This is the DACs. Not that I've tested the DACs but what Bean is seeing could be ground bounce or just the scope probes picking up some near field effect. The sharp edges of the sawtooth and square will be noisy.

  • Right...
    But somehow I’m thinking it showed up in chips demo mentioned above...
  • Rayman wrote: »
    Is that a rev A P2?
    That sort of coupling was fixed in rev.B silicon ...

    Just to be clear it was fixed in rev C silicon, not rev B silicon. (It was observed as an artifact in Rev B, causing the cut to me made, that fixed it in Rev C)

  • Yes. Think I remember now... Chips demo used jumper wires to connect dds output pins to scope input pins... it was the input pins that showed the crosstalk. Now fixed with rev.C silicon.

  • BeanBean Posts: 8,116
    edited 2020-10-15 - 13:29:17
    No it was my fault.
    I was using an 12" 3-pin header wire so I had Gnd-Sin-Sawtooth right next to each other.

    At the falling edge of the sawtooth, I would get a negative glitch on the sine wave.

    I am using the Rev C eval board.

    Bean
Sign In or Register to comment.