Spark Logic

$10 O-Scope revisited

ahull

Over the last few days I’ve been playing with Ray’s STM32 Oscilloscope idea.

Image

Some preliminary results are available here..

https://github.com/pingumacpenguin/STM3 … ontruction

My take on the Scope Sketch is here..

https://github.com/pingumacpenguin/STM32-O-Scope

Its a fun little project and well worth building just for the entertainment value. Currently bandwidth is a little limited, but with a little extra effort it would be possible to make a fully functional 2MHz Scope for next to nothing. Ideal for probing i2c, audio and other low speed signals.

EDIT: We managed to squeeze the maximum speed out of the ADC, read further through the thread for details. The github code includes all of the enhancements made of the course of this thread.

Replies20

ahull Tue Nov 08, 2016 10:17 pm

ThunderOwl wrote:I would be very thankful, if Author, or, anyone who knows and can, could make small instructions “for dummies” about serial interaction of this Scope. I have used terminals and serial connections before, problem is, that I am very new in this STM area. Thanks in advance!
P.S.: is there planned advances, changes for this Scope? Or, it was just a quick exercise that is not planned to become “bigger”? I hope it grows… :) Thanks!

ThunderOwl Wed Nov 09, 2016 10:04 am

Andy Hull, Thank You for answering. As I was writing one page earlier, after some fixes in library names, scope was working. Trying serial terminal from Arduino IDE or from separate program did not give any responses. Where in STM-duino case can I see baudrate what I should use for serial interaction?
Also, in Your tutorial is this:
https://github.com/pingumacpenguin/STM3 … l-Commands
“You must have compiled the sketch with the -DSERIAL_USB flag, so for example if you are using a genreic STM32F103C you need something like this in your boards.txt file.
genericSTM32F103C.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB
(end of quote) “.

I checked, that under C:\Program Files (x86)\Arduino\hardware\Arduino_STM32\STM32F1\ in file boards.txt I have this:
genericSTM32F103C.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER
so, there is one flag more, about bootloader. Should I edit now?
Or, perhaps, I am probably using genuinely outdated .INO file to start with? :)
I would appreciate some lessons to me, duino-STM novice :) Thanks!

ahull Wed Nov 09, 2016 11:16 am

ThunderOwl wrote:Andy Hull, Thank You for answering. As I was writing one page earlier, after some fixes in library names, scope was working. Trying serial terminal from Arduino IDE or from separate program did not give any responses. Where in STM-duino case can I see baudrate what I should use for serial interaction?
Also, in Your tutorial is this:
https://github.com/pingumacpenguin/STM3 … l-Commands
“You must have compiled the sketch with the -DSERIAL_USB flag, so for example if you are using a genreic STM32F103C you need something like this in your boards.txt file.
genericSTM32F103C.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB
(end of quote) “.

I checked, that under C:\Program Files (x86)\Arduino\hardware\Arduino_STM32\STM32F1\ in file boards.txt I have this:
genericSTM32F103C.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER
so, there is one flag more, about bootloader. Should I edit now?
Or, perhaps, I am probably using genuinely outdated .INO file to start with? :)
I would appreciate some lessons to me, duino-STM novice :) Thanks!

rexnanet Wed Nov 09, 2016 1:45 pm

Do you mean on the arduino IDE Serial monitor?
If so you may have to change the baudrate on the dropdown box each time you reprogram the STM in order to receive data.
Doesn’t matter which baudrate you choose.
This happens to me all the time.

mausi_mick Fri Nov 11, 2016 2:57 am

I have some problems with the scope:
the serial functions starts only one time, I have included in the source one
statement: Serial.begin(115200); with different baudrates(9600), but no real success.

But the Touch function is ok, but the coordinates go from left to right for y and bottom for x.

The display is an 2.8″ with touch for about 11 $.

mausi_mick

bianchifan Fri Nov 11, 2016 10:30 am

mausi_mick wrote:the serial functions starts only one time,

mausi_mick Fri Nov 11, 2016 1:03 pm

on the screen it should be something like a “pink pig”, but it was a little bit difficult, because the pen was a Q-Tip and the coordinates from the TFT and the Touch differed (ca 3mm).

Perhaps the problem with the Display is, that both needs SPI-Pins (SCK, Mosi; Miso, Cs …), the UTOUCH / URTOUCH – lib is presumable Software-SPI.

Therefore I switched the Touch – before and after use – on / off:

digitalWrite(PB13,LOW); // enable Touch device ######################################

…
while ((myTouch.dataAvailable() == false) && thisCount < calibrationTries) {

…

digitalWrite(PB13,HIGH); // disable Touch device #############################################

Because of the problems with the serial-cmds I have tested
switches (on Pin PB7 … PB3 (15…20 maple mini)) with Interrupts with success:

void isr_15() {   // sign for timeBase,xZoomfactor,Scroll, offset etc.

if (vorz == 0) vorz = 1;

else vorz = 0;

}
void isr_16() {  // increase, decrease timeBase

if (vorz == 1)   if (timeBase < 10000 ) timeBase = timeBase + 100;

if (vorz == 0)   if (timeBase > 100 )   timeBase = timeBase – 100; 

}
void isr_17() {  // increase, decrease ZoomFactor

if (vorz == 1)   if ( xZoomFactor < 21)  xZoomFactor += 1; 

if (vorz == 0)   if ( xZoomFactor >  1)  xZoomFactor -= 1; 

}
void isr_18() {  // ScrollRightLeft

if (vorz == 1)  if (startSample < (endSample – 120)) startSample += 100; // ScrollRight

if (vorz == 0)  if (startSample > (120))             startSample -= 100; // ScrollLeft

} 
void isr_19() {  // increase, decrease Y-Position

if (vorz == 1)  if (yPosition < myHeight )   yPosition ++;

if (vorz == 0)  if (yPosition > -myHeight )  yPosition –;

} 
void isr_20() {  // increase, decrease TriggerPosition

if (vorz == 1) if (triggerValue < ANALOG_MAX_VALUE )      triggerValue += TRIGGER_POSITION_STEP; //trigger position step

if (vorz == 0) if (triggerValue > TRIGGER_POSITION_STEP ) triggerValue -= TRIGGER_POSITION_STEP;  //trigger position step

}  

Now I will test the same with two quadraturencoders, the first one for the function, the second for the value.

mausi_mick

ThunderOwl Fri Nov 11, 2016 2:05 pm

mausi_mick wrote: …
Because of the problems with the serial-cmds I have tested
switches (on Pin PB7 … PB3 (15…20 maple mini)) with Interrupts with success
Now I will test the same with two quadraturencoders, the first one for the function, the second for the value…

mausi_mick

rexnanet Fri Nov 11, 2016 2:36 pm

Great! :)

I didn’t know that pin ISR was this simple :) don’t even need to clear Int. flags and stuff?… nice :)

Yep, this way it’s really easy to add an encoder to this! Even 2!!! :D

mausi_mick Sat Nov 12, 2016 1:16 am

With the encoders (“multi_encoder_acc”)it’s not so easy, because they need timer1. But with this timer I had problems with the scope and I changed it to timer 3.
Therefore I had to deactivate the test pulse:

// The test pulse is a square wave of approx 3.3V (i.e. the STM32 supply voltage) at approx 1 kHz
// “The Arduino has a fixed PWM frequency of 490Hz” – and it appears that this is also true of the STM32F103 using the current STM32F03 libraries as per
// STM32, Maple and Maple mini port to IDE 1.5.x – http://forum.arduino.cc/index.php?topic=265904.2520
// therefore if we want a precise test frequency we can’t just use the default uncooked 50% duty cycle PWM output.

//timer_set_period(Timer3, 1000); //<<<<<<<<<<<<<<<<<<<<<<<<<<<
// toggleTestPulseOn();

But with the switches I had also problems: PB3 …PB7 was functioned, but switch on PA15 not.
Perhaps with the switches it’s better to take I2C.

mausi_mick

mausi_mick Sat Nov 12, 2016 1:56 am

Hi,

a picture from the light modified screen:

On the left thre is fot test the actual positions of encoder1 and encoder2 (in red).
In the bottom line you can see 2 Parameters : the actual used encoder – Values for encoder 1 / 2.

On the right you can see two resistors: 13 Ohm from Vcc (3.3V) to LED-Pin and 470 Ohm between Vcc and Reset-Pin.

On Youtube is a video with changing timeBase over quadrature-encoders:

https://www.youtube.com/watch?v=DPiD25t … e=youtu.be]

ThunderOwl Sat Nov 12, 2016 2:51 pm

mausi_mick, I wish You all the best on Your work on code, hoping to see and use that code (with encoders or/and buttons) in future! Me myself – I am not that good at programming :)

mausi_mick Sat Nov 12, 2016 7:29 pm

Hi,

with the two rotary encoders I can change the parameters .
Encoder0 is for the functions (e.g. timeBase, offset, yPos…), Encoder1 to chnage the function-parameters.
I have modified the SW to hold the Position of Encoder1, if I go with Encoder0 to another function and back.(e.g. if timeBase is in Position 2 (200µs) and I modify e.g. yPosition and go than back with the encoder0+8 to timeBase, that there is the old Position (200µs)).

The active Touch-Field is smaller than the TFT-field . On the picture I marked the region with pink circles. The Touch Centre is approximately 3mm left from the graphic centre.

P1020567-001.JPG
P1020567-001.JPG (164.84 KiB) Viewed 1279 times

RogerClark Sat Nov 12, 2016 7:37 pm

did you use the rotary encoder code that @madias posted yesterday ?

mausi_mick Sun Nov 13, 2016 2:38 am

yes,

multi_encoder_acc.zip

But I have make some changes for setPosition and eliminate the acc-function (1 or 5 steps):

void readEncoders() { // ********encoder function ##################
for (byte counter = 0; counter < MAXENCODERS; counter++)
{
if ( (gpio_read_bit(PIN_MAP[encoderpinA[counter]].gpio_device, PIN_MAP[encoderpinA[counter]].gpio_bit) ? HIGH : LOW) != A_set[counter] )
{
A_set[counter] = !A_set[counter];
if ( A_set[counter] && !B_set[counter] ) encoderpos[counter] += 1;
// { if (millis() – encodertimer > 3) encoderpos[counter] += 1;
// else encoderpos[counter] += 5;
// }

encodertimer = millis();

}
if ( (gpio_read_bit(PIN_MAP[encoderpinB[counter]].gpio_device, PIN_MAP[encoderpinB[counter]].gpio_bit) ? HIGH : LOW) != B_set[counter] )
{
B_set[counter] = !B_set[counter];
if ( B_set[counter] && !A_set[counter] ) encoderpos[counter] -= 1;
// { if (millis() – encodertimer > 3) encoderpos[counter] -= 1;
// else encoderpos[counter] -= 5;
// }
encodertimer = millis();

}
}
}

and for set position:

void setEncoderPos(byte enc_nr, int16_t pos_nr)

{

encoderpos[enc_nr] = pos_nr;
}

ahull Sun Nov 13, 2016 11:46 am

Just being pedantic I know, but if you wrap the code in
 [ /code] tags, it makes it much easier for others to cut and paste.
[code]
void readEncoders() { // ********encoder function ##################

for (byte counter = 0; counter < MAXENCODERS; counter++)

{

if ( (gpio_read_bit(PIN_MAP[encoderpinA[counter]].gpio_device, PIN_MAP[encoderpinA[counter]].gpio_bit) ? HIGH : LOW) != A_set[counter] )

{

A_set[counter] = !A_set[counter];

if ( A_set[counter] && !B_set[counter] ) encoderpos[counter] += 1;

// { if (millis() - encodertimer > 3) encoderpos[counter] += 1;

// else encoderpos[counter] += 5;

// }
encodertimer = millis();

}

if ( (gpio_read_bit(PIN_MAP[encoderpinB[counter]].gpio_device, PIN_MAP[encoderpinB[counter]].gpio_bit) ? HIGH : LOW) != B_set[counter] )

{

B_set[counter] = !B_set[counter];

if ( B_set[counter] && !A_set[counter] ) encoderpos[counter] -= 1;

// { if (millis() - encodertimer > 3) encoderpos[counter] -= 1;

// else encoderpos[counter] -= 5;

// }

encodertimer = millis();

}

}

}

RogerClark Sun Nov 13, 2016 7:41 pm

Andy

I find code a lot easier to read if its correctly indented.

If I have to work on some code, from someone else, that is not indented, one of the first things I end up doing, is to indent the bits of code I and working on.
It helps me get an understanding of how the code functions / flows

There are a number of common mistakes in C and one is confusion about the end of an “if” block especially when braces are not used ( for a single line )

I know a lot of people think this is overkill, but I generally try to put braces even for single lines inside an if block and also indent the single line accordingly.

mausi_mick Sun Nov 13, 2016 7:56 pm

Sorry, I agree,

it’s clearer an more compact.

Today I tested a little bit the touch functionality on the display,
I defined two fields on the left side of the display . The top most field is for activate witch touch a sign-bottom (+/- , up/down),
the field below is for changing the value of the timeBase.

You can see it on Youtube:

increase timebase:

https://www.youtube.com/watch?v=5ys88sK … e=youtu.be

decrease timebase:

https://www.youtube.com/watch?v=jHkaI3SEdZE

But I think with the two encoders is better

mausi_mick Sun Nov 13, 2016 8:21 pm

In connection with the touch I have modified the
URTouch_ButtonTest Program for using with Adafruit_ILI9341_STM – lib.

The source:
[

Post a reply