Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

What are you developing?
ag123
Posts: 124
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by ag123 » Mon Mar 18, 2019 6:55 pm

Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

updated, this is now a 'just works' release
https://github.com/ag88/GirinoSTM32F103duino
  • first connect the maple mini with Girino stm32duino flashed/installed (libmaple core)
  • then start the java Girinoscope front end and connect to it
  • voltage scales
    Girino maps the range to 0 to 255 - -2.5 to 2.5v, so 0v is around 128.
    STM32 ADC maps the range range 0 to 4096 - 0v to 3.3v. To change the voltage scale mapping on the menu select Display > Change Signal Intepretation
Image

The ADC (oscilloscope) input is from pin PA0 ADC channel 0 (max 3.3v)

Timer 2 is setup on PA1 to generate a 1khz signal, hence patch PA1 to PA0 for a test signal.

should work on maple mini and blue pill
:D
Last edited by ag123 on Sun Mar 24, 2019 8:58 am, edited 4 times in total.

User avatar
mack
Posts: 28
Joined: Fri Mar 08, 2019 7:59 pm
Location: Australia
OS: Windows 10
IDE: Arduino 188
Core: Roger (BluePill),StevStrong (F407 Black)
Board: BluePill,F407 Black

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by mack » Mon Mar 18, 2019 8:59 pm

Hi
In my project I used adc callback interrupts, is that what you're wanting to achieve?
if so, Have a look at my code.
https://github.com/mackelec/Power_Scope

cheers
Andrew

ag123
Posts: 124
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by ag123 » Tue Mar 19, 2019 2:22 am

thanks!
i think i'm using a poorer approach the timer interrupt fires and i did a software adcRead(ADC1, 1).
i think this should work for low to moderately high sample rates.
however, as sample rates approaches 1msps, the software processing may overlap to the next sample clock as it is done sequentially.
i think there is a way in which the timer can trigger the adc sampling directly, i did not manage to do that successfully.
in that approach, adc conversion would have completed and the EOC interrupt calls the adc interrupt handler where i can do the s/w processing.
that approach is 'pipelined' i.e. adc conversion happen independently of s/w irq. that would allow higher sample speeds

however, what you have done is better, in the timer interrupt you started the conversion. and in the separate adc EOC interrupt you process the adc data, this would pretty much achieve the pipe lining as well

ag123
Posts: 124
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by ag123 » Tue Mar 19, 2019 4:42 am

i've updated my codes to use the 2 interrupts approach
- timer interrupt - start conversion
- adc eoc interrupt, read the adc data and do software processing
things seemed quite a bit improved

User avatar
mack
Posts: 28
Joined: Fri Mar 08, 2019 7:59 pm
Location: Australia
OS: Windows 10
IDE: Arduino 188
Core: Roger (BluePill),StevStrong (F407 Black)
Board: BluePill,F407 Black

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by mack » Tue Mar 19, 2019 7:10 am

I'm glad it was useful. I look forward to hearing about the final project.

Cheers
Andrew

ag123
Posts: 124
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by ag123 » Tue Mar 19, 2019 10:48 am

thanks and oops, i made a *huge* goof, i forget to setup the pin modes ! :lol:

this is actually working:
i've place a binary in the bin folder in the repository
https://github.com/ag88/GirinoSTM32F103duino
and you need Girinoscope java app from, i think the author has release a jar file on the repository web under releases. you could download that jar file and try it out.
https://github.com/Chatanga/Girinoscope

now this looks more like an oscilloscope ! patch pa1 to pa0 (the adc)
Image

the fixed codes are checked into github
tested works on blue pill as well
Last edited by ag123 on Wed Mar 20, 2019 7:44 am, edited 1 time in total.

User avatar
mack
Posts: 28
Joined: Fri Mar 08, 2019 7:59 pm
Location: Australia
OS: Windows 10
IDE: Arduino 188
Core: Roger (BluePill),StevStrong (F407 Black)
Board: BluePill,F407 Black

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by mack » Tue Mar 19, 2019 12:09 pm

I will definitely try this - looks like fun. Might be a little while though.
Could the Girinoscope java app go to 2 or 3 channel? The bluepill can simultaneously sample 2 channels.
I have a F4vet6 board on order, I think it has 3 ADCs.

ag123
Posts: 124
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by ag123 » Tue Mar 19, 2019 12:56 pm

well, the force (source) is out there, all it takes is some imagination and work
and imho it is a 'perfect combo' girinoscope arduino based + stm32 duino libmaple core, hope someone could try to put this on stm32duino official core as well
the idea that to do some basic oscilloscope stuff < 1msps, all you need is your laptop and a blue pill / maple mini is just too seductive hence this project
if you bother to go more than stm32f103, i'd think >> 1msps is well possible

imho just to brag a little, i think it is worth trying it out with your blue pill or maple mini
it actually takes quite a lot girinoscope java front end + libmaple core + stm32f103 + the girinoscope firmware to bring this to you
and i only did a little patches on the last part girinoscope firmware and here you go stm32girino
:lol:

ag123
Posts: 124
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by ag123 » Wed Mar 20, 2019 3:36 am

oh there is a (minor) catch, i think for atmega328p (arduino uno) the ranges 0 - 255 is mapped to -2.5v to 2.5v as it seemed to suggest from the voltages on the girinoscope display. As i tried to make it 'compatible' i mapped 0 - 4096 (0 - 3.3v) stm32f103 to 0 - 255 girinoscope, hence the rather strange looking voltages. so 2.5v is actually 3v and -2.5v is 0v and 0v on the scale is about 3.3/2 ~ 1.65v

to make the voltage ranges correct some changes on the girinoscope java front end would be needed

edit:
ok i've added some voltage translation defines so that it is possible to make the display look this way.
but that reduces accuracy from 12 bits to 7 bits plus various integer division / scaling arithmetic, hence accuracy is likely sacrificed for 'correct' looking graphs
Image

ag123
Posts: 124
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Girinoscope ported to STM32duino (libmaple core) stm32f103 maple mini

Post by ag123 » Thu Mar 21, 2019 3:41 pm

there is a new puzzle, if you try girinoscope out and you try the highest sample rates 307 khz (or 307 k samples per sec)
you would note that the time base is wrong.

it turns up that stm32 adc in this current setup couldn't catch up !

after a lot of misses, i tried this. i make a flag (boolean variable) so that when the end-of-conversion interrupt processing starts i flag that true
and when it ends i flag that false. if the flag is true even before that flag is set, i turn on the led.
i.e. the end-of-conversion interrupt processing is a critical zone, if the led turns on it means the next end-of-conversion starts before
the previous can finish. surprisingly stm32 is pretty fast and it can do all that software edge triggering, conversions, math and put the data in the ring buffer before the next end-of-conversion processing starts. that's true even if i push above 600 ksps (1 adc 1 channel, adc 2 is left idle)

so i tried something different, i make the critical zone flag start when the timer interrupt triggers the adc (start of conversion)
and flag critical zone off when i get the end-of-conversion interrupt and i've read the data.
if the led lights it means the next adc conversion is attempted before the last one finish
now something happens, the max sampling rates i get :

1 adc 1 channel (adc 2 left idle) and sample time set to 1.5 adc clocks
stm32 f103 cb maple mini (clone) - but real mccoy : 200 k samples per sec - above that the led lit (conversions crash) and answers are incorrect
cs32 f103 c8 blue pill (yup the 'replica' stm32) just slightly below at 190 k samples per sec, try 200 k samples per sec and the led lit

i verified some parameters, APB2 pre-scaler divide by 1 i.e. 72 mhz - at least it is that in the codes
adc prescaler : divide by 6 (i tried setting this and no difference)
so adc clock 72 mhz / 6 - 12 mhz
i set sample time 7.5 adc clocks then rm0008 mentions 12.5 adc clocks + sample time for 1 conversion
12 mhz / (7.5 + 12.5) ~ 600 k samples per sec
i tried over clocking the adc setting prescaler = 4 so 72 mhz / 4 ~ 18 mhz adc clock
i get slightly above 200 k samples per sec like 210 - 220 k samples per sec but no higher

for some reason i do not know with all the software interrupts triggering setups the max achievable is about 200 k samples per sec or less

Post Reply