Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:58 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 4 of 5    
Author Message
matherp
Guru

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

Please try these


PicoMiteVGA (2).zip

PicoMite (5).zip

Tested on your program above and also on the first of the sine wave programs
Continuous conversion doesn't work with a simple hack on the logic analyser but that is probably me not understanding it.
 
Volhout
Guru

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

Hi Peter,

LA also works (just did a quick sanity check). See attached.
- Updated the DMA with 0
- Included ReadyInt in the program flow, since it did post processing, but is now not called anymore.

See attached.

It still needs a thorough test, but the basis works...

Volhout
LA_24_DMA.zip

P.S. maybe I should modify the LA to detect the MMBasic version and adapt to it. Since I would like to support 50707 (the official latest release) also.
Edited 2023-06-30 21:33 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

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

OK, back to Mick's topic....

This is the sine wave generator running on Picomite 5.0708b7 (infinite DMA).

'Sine wave generator 1Hz...1MHz using a ladder DAC on Picomite 5.07.08b7 and newer
'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.
'this version uses 5.070807 that has continuous DMA.

'has options to use FIFO more efficient for 8 bit.

'defines
bits% = 7 '7 bit ladder DAC
length% = 4096          'allows up to 16kHz full resolution
Dim o%(length%-1) 'array containing source samples
level=2^(bits%-1)*0.9   'amplitude of sine signal is 90%


'packed data in DMA ring buffer
Dim pkd%
'PIO make ring buffer pkd%,length%*4  'length in 32 bit fifo values
PIO make ring buffer pkd%,length%     'length in 8 bit fifo values

'free pio pins for use with 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 4x8bit values packed in 32 bits to GPx pins, or 32 bits.
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,8"  'set all associated pins (8) output
PIO assemble 1,".wrap target"
PIO assemble 1,"pull noblock"   'get data from fifo
PIO assemble 1,"out pins,8"     'write out to 7(8) pins
PIO assemble 1,"out pins,8 [1]" 'write out to 7(8) pins delay 1 (8bit only)
PIO assemble 1,"out pins,8 [1]" 'write out to 7(8) pins delay 1 (8bit only)
PIO assemble 1,"out pins,8 [1]" 'write out to 7(8) pins delay 1 (8bit only)
PIO assemble 1,".wrap"
PIO assemble 1,".end program list"

'pio config
f=133e6               'default: 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 do UI and create sine waves
Do
 'input frequency
 Input "what frequency ";x
 y%=1+x/16000            'y%=number of sine cycles in one buffer
 f=x*2*length%/y%
 Print x,y%,f
 Timer = 0

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

 'calculate sinewave table
 calc_sin  '-or- calc_modsin
 'Memory pack o%(),pkd%(),length%,32   'fill it with values from the sine wave for 32 bits
 Memory pack o%(),pkd%(),length%,8     'fill it with values from the sine wave for 8 bits

 'restart machine
 PIO init machine 1,0,f,p,e,s,0
 'PIO dma tx 1,0,&hffffffff,pkd%(),help,,length% '5.0707 command longest run 32 bits
 PIO dma tx 1,0,0,pkd%(),,,length%/4  '5.070807 command infinite run 8 bit
 'PIO dma tx 1,0,0,pkd%(),,,length%  '5.070807 command infinite run 32 bit
Loop
End



Sub help '5.0707 only
 Print "stopped after ";Timer;" ms"
 PIO stop 1,0
End Sub


Sub calc_modsin
'calculate sinewave table
For i=0 To length%-1
 alpha=i*2*Pi/length%
 o%(i)=Int(level*(1.1+(Sin(y%*alpha))*Sin(alpha)*Sin(alpha)))
Next
End Sub

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

PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 03:11pm 30 Jun 2023
Copy link to clipboard 
Print this post

Something not quite right with the waveform.







Edited 2023-07-01 01:14 by matherp
 
Volhout
Guru

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

Checkt the values of the ladder resistors, looks like the msb is few percent off, or, the pin impedance creates a fault.

I used a 2k/1k ladder and do not see this.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

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

It looks rather like bit0 and/or bit1 is strange. How does it look at a low frequency?
Mick

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 04:45pm 30 Jun 2023
Copy link to clipboard 
Print this post

I'm using some 120R, 240R 1% resistors left over from CMM2 so I think Volhout is right that it is an pin drive/impedance issue
 
Mixtel90

Guru

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

Yep. A higher resistance will swamp it. I'm intending to use R=1K8 2R=3K6 followed by an op-amp non-inverting input. Purely because I happen to have some 0805 0.1% in that value. :)  If I can still manage to solder 0805, of course. I've not done any for a while. Or I might just order some 1K / 2K 0.25W from China. They would be a lot easier to handle ...
Mick

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 05:26pm 30 Jun 2023
Copy link to clipboard 
Print this post

RS has 1k 2k leaded in 0.1% at sensible price (GBP 0.42 each).
I have improved the waveform by increasing the pin drive when a pin is set to PIO. Will put the change in the next beta.
 
Volhout
Guru

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

That is why most DACs are current driven, not voltage.

I see barely any roll-off attenuation) with 1k/2k at 1MHz. So that ahould be fine. I am not sure about the LM358 buffer though. It is not really helping I think. It can only drive few mA. You might be able to get 600 ohm output impedance, but the 1k/2k ladder is 1k.

Volhout

Ironically the ADC problem in the pico, is exactly this, but then with capacitors in the ADC on chip. That is why Analog Devices, TI, Microchip exist. Not easy to make a good adc on microcontroller silicon.
Edited 2023-07-01 03:42 by Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 06:37pm 30 Jun 2023
Copy link to clipboard 
Print this post

FYI

Next version will have continuous ADC conversion into an array since I've now cracked how to do it
 
Mixtel90

Guru

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

I've discovered, after a lot of sorting out, that I can do a lot better than the LM358. :) There are a couple of LM833 in there and a couple of NE5532 and TL081. I think there's a TL082 as well. I suspect all these will be much better. :)  Most of these are in a load of components that my brother gave me.

The AD8055 video amp is pretty cheap when you look around.
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: 06:47pm 30 Jun 2023
Copy link to clipboard 
Print this post

Peter,

It may be me, and my serious experiments that cause this, but on few platforms I have RTC's.
Is it possible that between changing firmware I loose the RTC pre-set time?

I will keep an eye on when it happens (I lost track where) but I noticed first when I saw the time stamps in the file system where not correct, and it appeared the TIME$ was wrong,, and traced it back to the RTC being wrong.

I use DS1307 RTC's, so the exhibit some drift, but not this bad... hours off.
This is both on picomite VGA (2 systems) and picomite (1 system).
Again, I experiment a lot... so it may very well be me.

Regards,

Volhout
Edited 2023-07-01 04:50 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

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

My main problem with RTCs has been that the tiny ones have unknown battery life when you buy them and the calibration usually leaves a lot to be desired. I have come to a blank RTC, but it's because the battery has gone flat. I've come across the occasional very inaccurate ones but I put that down to the battery going flat! As far as I'm aware firmware upgrades haven't had any effect.

Just a thought... are you depending on I2C pullups on the RTC module or on the PCB? The module ones tend to be a bit high.
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: 06:39am 01 Jul 2023
Copy link to clipboard 
Print this post

The 1307 runs at 5V, pullups 4.7k on module, and 10k pull down on breadboard.
The VGA boards are Peters 1.7 design. I didn’t check,just plugged it in.

Maybe the problem is that in my measuring and modifying I accidentally touch the metal part of the batterij, the positive terminal,and short it to ground. That is what I can think of.

Volhout
Edited 2023-07-01 16:40 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 05:26pm 01 Jul 2023
Copy link to clipboard 
Print this post

This project is looking better and better. :)

Just a thought though. I don't know if this is even possible  because of the way the system is working, but would it be possible to produce a sync pulse on a GP pin once every revolution of the ring buffer? It would be handy to produce a trigger input for an oscilloscope. One use would be to trigger the scope at the beginning of a ramp that is being used to control the frequency of another oscillator. Nice for seeing shapes of filters.

Another idea I've been playing with is to use a DAC (or PWM?) to produce a DC voltage that can be used to bias the inverting input of the non-inverting op-amp, giving a neat DC shift control. A MCP48xx would be nice as the 0-4096 output works well if the output stage is fed from +/-12V. The other half of it could be a PLAY TONE output to give a second channel with FM control from one of the ADC inputs. :)
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: 05:31pm 01 Jul 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  This project is looking better and better. :)

Just a thought though. I don't know if this is even possible  because of the way the system is working, but would it be possible to produce a sync pulse on a GP pin once every revolution of the ring buffer? It would be handy to produce a trigger input for an oscilloscope. One use would be to trigger the scope at the beginning of a ramp that is being used to control the frequency of another oscillator. Nice for seeing shapes of filters.

Another idea I've been playing with is to use a DAC (or PWM?) to produce a DC voltage that can be used to bias the inverting input of the non-inverting op-amp, giving a neat DC shift control. A MCP48xx would be nice as the 0-4096 output works well if the output stage is fed from +/-12V. The other half of it could be a PLAY TONE output to give a second channel with FM control from one of the ADC inputs. :)


How do I trigger a scope.. from displaying a-d samples?
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 05:37pm 01 Jul 2023
Copy link to clipboard 
Print this post

Use the ADC command to load the samples into an array in the background. It will give you an interrupt when the array is full. That's your signal to process the array.
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: 06:22pm 01 Jul 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  Use the ADC command to load the samples into an array in the background. It will give you an interrupt when the array is full. That's your signal to process the array.

I had trouble from the info in the manual. My prob. Not a clue why this fails. Obvious but not for me as first time I used an interrupt. ps I don't like asking advice and don't want to be a pain. stan
 dim count%,sync!,sync2!
 Dim samples!(160)
 Dim old_samples!(160)
'PLAY TONE 10000,10000,60000
 SETPIN GP26, AIN
 'SetPin GP18,pwm1A 'this optional test signal comment out
 'PWM 1,5000,50   ' 50% = square wave ,this optional test signal comment out
 
 Pause 100
 adc open 500000,1 'samples per second
 cls
 adc start samples!()'get new samples
 math scale samples!(),80,samples!()
 'for count%=0 to 159
   'samples!(count%)=(samples!(count%)*20)+10 'scale 3V samples to 0 to 79 pixels
 'next count%
 math add samples!(),0,old_samples!() 'copies a() to b()
 'for count%=0 to 159
   'old_samples!(count%)=samples!(count%) 'copy samples to old_samples
 'next count%

 for count%=0 to 158
   line count%,samples!(count%),count%+1,samples!(count%+1),,rgb(white) 'draw first samples
 next count%
adc close
adc open 500000,1,int1 'samples per second --interrupt

'-------- main loop
 do
   adc start samples!() 'get new samples
loop

int1:
  '
   math scale samples!(),80,samples!()
   'for count%=0 to 159
     'samples!(count%)=(samples!(count%)*20)+10 'scale 3V samples to 0 to 79 pixels
   'next count%
  '
   for count%=0 to 158
     line count%,old_samples!(count%),count%+1,old_samples!(count%+1),,rgb(black) 'erase old_sample
     line count%,samples!(count%),count%+1,samples!(count%+1),,rgb(white) 'draw new sample
   next count%
  '
   math add samples!(),0,old_samples!() 'copies a() to b()
   'for count%=0 to 159
     'old_samples!(count%)=samples!(count%) 'copy samples to old_samples
   'next count%
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 07:52pm 01 Jul 2023
Copy link to clipboard 
Print this post

Have a play with something very simple to start with, like using SETTICK to flash an LED. Just to get the idea of interrupts. SETTICK calls an interrupt SUB at regular time intervals, so you can use it to toggle a GP pin. e.g.:


'create your output pin
Setpin gp0,dout

'call SUB Flip every 500ms. This is SETTICK 1. You can have up to 4 running.
SETTICK 500, flip, 1

do
loop until the_end_of_time

SUB flip
 PIN(gp0) = NOT(PIN(gp0))
end sub


Interrupts are invisible to the rest of your program. The best way to use them is to just set a flag in the interrupt sub then scan for that flag in the body of your program, process it and reset it. It will get set again when the next interrupt occurs, but in the meantime you haven't slowed your program down much.

======================

Ah... I've just looked at the manual again. It's ages since I used the ADC command and I think I've misled you. The interrupt is called at the end of a conversion, not after filling an array AFAIK. Sorry. You may be able to increment a counter in the interrupt routine and, when it gets to a certain value, your array is full. I've not tried this.
Edited 2023-07-02 06:08 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
     Page 4 of 5    
Print this page
© JAQ Software 2024