Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:46 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite sine waves?

     Page 2 of 5    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 07:07am 21 Jun 2023
Copy link to clipboard 
Print this post

  Quote  Mmbasic is fully equipped to do this. Use a ring buffer and dma to pio.


ring buffer is circular - the key is in the name


Or lots of ways using a CSUB
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 713
Posted: 03:10pm 21 Jun 2023
Copy link to clipboard 
Print this post

It seems that ( way back ) parallel was always
way faster than serial ......
( whose only advantage was fewer wires )
That has seemingly changed though .
my site
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 03:55pm 21 Jun 2023
Copy link to clipboard 
Print this post

Oh no, parallel is still way faster. The thing is, you are feeding the parallel output from a BASIC program. Even if BASIC is running very fast it's still a lot slower than hardware driven DMA. On top of that, the main system may be getting interrupts. You don't want those while you are generating a waveform. Even using a SPI DAC the data will be being transferred to it in the background, not depending on the speed of a BASIC program.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 05:11pm 21 Jun 2023
Copy link to clipboard 
Print this post

Mick,

Why not build geoff's DDS signal generator?

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 05:25pm 21 Jun 2023
Copy link to clipboard 
Print this post

Because I already have the bits for this (well, it may be a temporary buffer op-amp) including the case I'd like to fit it into. :)  Also, I've just had to pay out a lot of money to get the kitchen roof fixed so I don't really want to spend on anything else at the moment. I'd have to buy the module and the display as a minimum.
Edited 2023-06-22 03:27 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 12:27am 22 Jun 2023
Copy link to clipboard 
Print this post

call that a sine wave generator.. This is a sine wave generator.. uses valves, how cool? :)
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 713
Posted: 01:07am 22 Jun 2023
Copy link to clipboard 
Print this post

  stanleyella said  
call that a sine wave generator.. This is a sine wave generator.. uses valves, how cool? :)

Valves are not cool .... Get with the program !  

my site
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 06:44am 22 Jun 2023
Copy link to clipboard 
Print this post

Hi Hitsware,

Your circuit uses a glass bulb though....
That is a valve, without anode, kathode and grids....

But the distortion figures are impressive. Can't do that with less than 16 bit DAC's.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 07:27am 22 Jun 2023
Copy link to clipboard 
Print this post

Ah... lamp stabilisation. Amplitude bounce when you change the frequency of the bridge, wait for it to settle. :) Cheaper than the R53 thermistor though, and actually obtainable. Mind you, 40mA and 60mA bulbs aren't that easy to find now and the thermistor is long gone.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 01:54pm 22 Jun 2023
Copy link to clipboard 
Print this post

Nostalgia isn't what it used to be and reminded of the bulb.
The gen I posted is an Advance and over 50 years old but still works. Thought the caps dried out by now.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 03:04pm 23 Jun 2023
Copy link to clipboard 
Print this post

Hi Mick,

See below program to generate sine waves using PIO and a DMA ring buffer. It runs on Picomite 5.07.07 on CPUSPEED 133000

'test HW for sine wave generator

'this is running in basic
bits% = 7
length% = 64' 128

'calculate sinewave table
level=2^(bits%-1)*0.9
Dim o%(length%-1)
For i=0 To length%-1
 o%(i)=Int(level*(1.1+Sin(i*2*Pi/length%)))
Next

'pack data in ring buffer
'shortest ring buffer is 256
Dim pkd%
PIO make ring buffer pkd%,length%*4  'length in 32 bit fifo values
Memory pack o%(),pkd%(),length%,32   'fill it with values from the sine wave

'pio pins
SetPin gp6,pio1
SetPin gp7,pio1
SetPin gp8,pio1
SetPin gp9,pio1
SetPin gp10,pio1
SetPin gp11,pio1
SetPin gp12,pio1

'pio program
PIO assemble 1,".program out"
PIO assemble 1,".line 0"
PIO assemble 1,"mov osr ,!null" 'fill osr with &hffffffff
PIO assemble 1,"out pindirs,32" 'set all associated pins output
PIO assemble 1,".wrap target"
PIO assemble 1,"pull noblock"   'get data from fifo
PIO assemble 1,"out pins,32"    'write out to 7 pins
PIO assemble 1,".wrap"
PIO assemble 1,".end program list"

'pio config
f=133e6               'modify this value to tune to other frequencies

p=Pio(pinctrl 0,0,bits%,,,,gp6)
e=Pio(execctrl gp0,Pio(.wrap target),Pio(.wrap))
s=Pio(shiftctrl 0,0,0,0,0,1)
's=Pio(shiftctrl 0,bits%,0,1,0,1)     'autopull after 'bits' shift out

PIO init machine 1,0,f,p,e,s,0
Print "machine init"

'now start the actual machine
PIO dma tx 1,0,&hffffffff,pkd%(),help,,length%
Print "dma running"

'here we do nothing , or some UI
Do :Loop

Sub help
Print "help"
PIO stop 1,0
End Sub

End


This example code is based on a ladder network DAC connected to GP6...GP11 where GP11 is the most significant bit. The start pin GP6 is defined in the PIO (Pinctrl ...) definition.
I use a 7 bit DAC since that is in my hardware, but you can expand that by changing the variable "bits%", the setpin gpx 's.
The current program outputs a 1.03 MHz sine wave, the frequency can be changed by adapting the variable "f". You have to STOP PIO, then re-init the PIO machine, and then restart the DMA.

The sine waves are pre-calculated in the o%() array, and packed into a DMA buffer called "pkd%()". By putting different data into the o%() array you can make an arbitrary waveform generator. The current sample array length is length%, and it is 64, be can be made longer when desired (until memory runs out) as long as it is a power of 2.

Understand that longer arrays lower the frequency of the output signal. But... increase accuracy. So youmay want to change to longer arrays, and (just for the higher frequencies) put multiple sine cycles in one array.

I hope your project succeeds.

Volhout

P.S. I experimented with autopull, that should theoratically double the output frequency, but that was not succesfull up to now. So this is where I am at now.
Edited 2023-06-24 01:16 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 04:13pm 23 Jun 2023
Copy link to clipboard 
Print this post

Wow... that's impressive! I think that might be the core of my AWG. :)
I'm still going to do this little test oscillator though. An AWG is unlikely to fit in that space. I might think about that though........ :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3804
Posted: 06:55pm 23 Jun 2023
Copy link to clipboard 
Print this post

Is there a circuit diagram please?

John
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 07:16pm 23 Jun 2023
Copy link to clipboard 
Print this post


gp6  gp7  gp8 gp9 gp10  gp11
!    !    !    !    !    !
2k   2k   2k  2k   2k   2k
!    !    !    !    !    !
+-1k-+-1k-+-1k-+-1k-+-1k-+--- output
!
2k
!
GND


6-bit R2R DAC
Resistors should be as close a tolerance as possible, but for experimental purposes don't worry too much.

As it is you can't drive much with it. It needs a buffer amplifier to make it really usable. Unfortunately that bit tends to cost much more than the PicoMite and R2R network put together if you want anything above the audio spectrum!


    !'
-----!+ '
    !   :---+--- output
    !  .    !
  --!-.     !
  ! !.      !
  !_________!

Simple buffer


You can try anything as a buffer. If you don't mind a bit of distortion try a LM358 (very cheap) with a 3K3 resistor from the output to GND. It will run fine from 5V. Not that good above audio range.
.
Edited 2023-06-24 05:28 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3804
Posted: 07:45pm 23 Jun 2023
Copy link to clipboard 
Print this post

Thanks. I did wonder about the output!

I found this and I see one keeps adding more of the R/2R parts for each extra bit. It didn't say what the final device ought to be so thanks for an example.

John
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 08:11pm 23 Jun 2023
Copy link to clipboard 
Print this post

Cheap buffer is a 2N2907 with 100 ohm resistor to 5V. Collector to grond.
Above example also uses gp12

Volhout
Edited 2023-06-24 06:12 by Volhout
PicomiteVGA PETSCII ROBOTS
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 713
Posted: 12:04am 24 Jun 2023
Copy link to clipboard 
Print this post

  Volhout said  
Volhout

Seems like with those relatively low
resistances , and pin output Z ,
perhaps , at times , no buffer needed ?
my site
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 07:49am 24 Jun 2023
Copy link to clipboard 
Print this post

It depends on the input resistance of the next stage as you have a potential divider. The output from a R-2R is actually a voltage and can't provide much current no matter what the capabilities of the digital outputs are. As you reduce the load resistance the high order bits get less and less accurate. This then carries on down the ladder. The non-inverting input of an op-amp is almost infinite for those with FET inputs so those are ideal. You could probably load a ladder with about 10xR I think, but after that you are starting to lose accuracy. You can get more output current by reducing the R and 2R values but you probably shouldn't reduce 2R below about 220R with the Pico anyway because the outputs need protecting. It's not a good idea to use high values either, because of stability and noise.

I originally looked for a R-2R network in a DIL package. They are made, but are difficult to find in the UK (I could only find highish values 10k & 100k). When I investigated further the tolerance isn't too great - about 5% between packages IIRC, although the resistors may be better matched than that within a package. That would mess up extending it to 10 or 12 bits with two packages.

You can get 0.25W 0.1% tolerance resistors from China reasonably cheaply. Stupid prices here though.
Edited 2023-06-24 18:02 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 02:57pm 26 Jun 2023
Copy link to clipboard 
Print this post

Hi Mick,

This version allows you to input a frequency between 1Hz and 1MHz and get this from the ladder DAC.

'Sine wave generator 1Hz...1MHz using a ladder DAC on Picomite 5.07.07
'amplitude resolution defined in variable "bits%". In demo this is 7 bits on GP6...GP12
'uses PIO to output pre-calculated data through ring buffer DMA.

bits% = 7
length% = 4096          'allows up to 16kHz full resolution '64' 128
Dim o%(length%-1)
level=2^(bits%-1)*0.9   'amplitude of sine signal

'this uses the ring buffer.
Dim pkd%
PIO make ring buffer pkd%,length%*4  'length in 32 bit fifo values in bytes

'setup the pio pins for the ladder DAC
SetPin gp6,pio1
SetPin gp7,pio1
SetPin gp8,pio1
SetPin gp9,pio1
SetPin gp10,pio1
SetPin gp11,pio1
SetPin gp12,pio1

'pio program to send DMA data to the pins
PIO assemble 1,".program out"
PIO assemble 1,".line 0"
PIO assemble 1,"mov osr ,!null" 'fill osr with &hffffffff
PIO assemble 1,"out pindirs,32" 'set all associated pins output
PIO assemble 1,".wrap target"
PIO assemble 1,"pull noblock"   'get data from fifo
PIO assemble 1,"out pins,32"    'write out to 7 pins
PIO assemble 1,".wrap"
'PIO assemble 1,".end program list"
PIO assemble 1,".end program"

'pio config (this is the default value)
f=133e6               'modify this value to tune to other frequencies
p=Pio(pinctrl 0,0,bits%,,,,gp6)
e=Pio(execctrl gp0,Pio(.wrap target),Pio(.wrap))
s=Pio(shiftctrl 0,0,0,0,0,1)

'here we set the frequency and program the sine wave, PIO and DMA
Do
 'for frequencies < 16kHz we use the full buffer for 1 single cycle
 'for higher frequencies we pack multiple cycles in one buffer
 
 'input frequency  
 Input "what frequency ? ";x
 If x>16000 Then
   y%=1+x/16000            'y%=number of sine cycles in one buffer
   f=x*2*length%/y%
 Else
   f=x*2*length%           '1 sine cycle in buffer
   y%=1
 EndIf

 'stop running PIO and DMA machine
 PIO stop 1,0
 If MM.Info(PIO TX DMA)=1 Then PIO dma tx off

 'calculate new sinewave buffer and pack it into the ring buffer
 calc_sin
 Memory pack o%(),pkd%(),length%,32   'fill it with values from the sine wave

 'restart machine
 PIO init machine 1,0,f,p,e,s,0
 PIO dma tx 1,0,&hffffffff,pkd%(),help,,length%
Loop
End


Sub help
' Print "help"
PIO stop 1,0
End Sub


Sub calc_sin
 'calculate sinewave buffer values
 level=2^(bits%-1)*0.9
 For i=0 To length%-1
   o%(i)=Int(level*(1.1+Sin(y%*i*2*Pi/length%)))
 Next
End Sub

PicomiteVGA PETSCII ROBOTS
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3804
Posted: 08:00pm 26 Jun 2023
Copy link to clipboard 
Print this post

Impressive!

John
 
     Page 2 of 5    
Print this page
© JAQ Software 2024