4 Channel Quadrature LFO

From circuitbending to homebrew stompboxes & synths, keep the DIY spirit alive!

Moderators: Kent, luketeaford, Joe.

tardishead
Wiggling with Experience
Posts: 359
Joined: Sat Aug 03, 2013 3:00 pm
Location: London

Re: 4 Channel Quadrature LFO

Post by tardishead » Fri Sep 10, 2021 4:15 am

Quadro_LFO.ino.generic_stm32f103c.bin.zip
I can't expand the file on my system. Have tried a few ways and it says that is not supported
Mac. Stuffit Expander
Sorry for the ball ache

User avatar
paperCUT
Ultra Wiggler
Posts: 771
Joined: Sat Mar 12, 2011 11:13 pm
Location: Stockholm

Re: 4 Channel Quadrature LFO

Post by paperCUT » Fri Sep 10, 2021 11:35 am

No idea, it works fro me. Try this, it's a 7zip file named as jpg to attach. Just remove the .jpg at the end and see if you can open the 7zip

Hmm no that wont attach, trying .tar
Quadro_LFO.ino.generic_stm32f103c.bin.tar
tar version
(41 KiB) Downloaded 3 times

tardishead
Wiggling with Experience
Posts: 359
Joined: Sat Aug 03, 2013 3:00 pm
Location: London

Re: 4 Channel Quadrature LFO

Post by tardishead » Fri Sep 10, 2021 12:43 pm

nope exactly the same. Not supported. Any chance you can drop a .zip not .bin
or do a zip by email?
the original file with the sketch downloaded just fine

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Fri Sep 10, 2021 1:44 pm

The bin file is NOT the code! It is the content of the memory of a working processor.
So all you have to do is unzip it en use your STM Cube Programmer to upload the bin file to the processor.
anyway, pm your email address and I see what I can do (feel sorry for you too since you bought the components...)

tardishead
Wiggling with Experience
Posts: 359
Joined: Sat Aug 03, 2013 3:00 pm
Location: London

Re: 4 Channel Quadrature LFO

Post by tardishead » Fri Sep 10, 2021 3:54 pm

Ah ok. Sorry I thought it was an Arduino folder that you had compressed. When I download it onto my computer it shows as an archive folder
I will see if I can load it with the STM Cube Programmer

I totally get it now.
I did have some success in looking at different syntax of hardware timer libraries over the years and I managed to get the code to compile now.
I'm sure I can figure it out. But I will defo try that binary file
Ive learnt a lot just from analysing and trying to understand your code anyway.
Its all good

BTW when you call the GPIO register directly for a button push or encoder turn - I presume that's because its faster than digitalRead - is that correct? Ive never seen that before.

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Fri Sep 10, 2021 4:41 pm

Glad you sorted it out!
I use GPIO because the core library I used doesn’t support PORTn instructions to write/read a full port.

tardishead
Wiggling with Experience
Posts: 359
Joined: Sat Aug 03, 2013 3:00 pm
Location: London

Re: 4 Channel Quadrature LFO

Post by tardishead » Wed Sep 15, 2021 6:26 am

I tried a Blackpill STM401 that I had laying around. Sketch uploaded ok but I cannot get it past the Welcome Screen.
I couldn't find any reason it would not work on a Blackpill

I used this code

Code: Select all

            if (digitalRead(PB13) == 1) {
in stead of

Code: Select all

            if (GPIOB->IDR->regs & (1 << 13)) {
Just to confirm, I have verified my connections to the OLED and DAC by transmitting some simple sketch to both with the current designated pins they work fine as expected.
It seems to be a freeze in the main sketch.

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Thu Sep 16, 2021 5:39 am

Sorry, just read this, will look at it later today

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Thu Sep 16, 2021 2:38 pm

If you see the welcome screen en press the encoder button of rotate the encoder, does the welcome screen stay?
If so, it looks like the interrupt is not doing its thing.
You can check this by adding a fes lines of code within the interrupt service routines that lights up the led on board.
In the setup add:
pinMode(PC13, OUTPUT); // LED connect to pin PC13
digitalWrite(PC13, LOW); // turn the LED off by making the voltage LOW
in the isr's:

Code: Select all

void encoderISR()
{
 digitalWrite(PC13, HIGH);   // turn the LED on (HIGH is the voltage level)
  turned = true;
}

void encoderButtonISR()
{
  digitalWrite(PC13, LOW);    // turn the LED off by making the voltage LOW
  switched = true;
}
So if you rotate the encoder, the led goes on, when pressing the encoder the led goes out.
If nothing happens to the led, the interrupts are not working.
Hope this helps

tardishead
Wiggling with Experience
Posts: 359
Joined: Sat Aug 03, 2013 3:00 pm
Location: London

Re: 4 Channel Quadrature LFO

Post by tardishead » Thu Sep 16, 2021 3:08 pm

Yes I did this but when BOOT UP LED is on. Turn encoder LED goes OFF. Push switch and LED goes back ON. Thats weird!
Blue LED
Still stuck on Welcome Screen.

I feel like the syntax for the HardwareTimer is not working. After not being able to work with your CORE I went back to the STM32 official core.
When I look for examples I see code like this

Code: Select all

  timer->pause();
  timer->setPrescaleFactor(prescalefactor);
and

Code: Select all

HardwareTimer *timer = new HardwareTimer(TIM5);

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Thu Sep 16, 2021 4:07 pm

Yes I did this but when BOOT UP LED is on. Turn encoder LED goes OFF. Push switch and LED goes back ON. Thats weird!
Ok, so your interrupts are working.
Will have a look further tomorrow (it’s 23.06 now…)

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Fri Sep 17, 2021 1:48 am

To check the timer:
change the timer_value to

Code: Select all

volatile uint16_t timer_value = 0x8FFF;
and add

Code: Select all

volatile bool blink = true;
add in the setup section

Code: Select all

pinMode(PC13, OUTPUT); // LED connect to pin PC13
change the timer isr to

Code: Select all

void overflowISR()
{
  blink = !blink;
  digitalWrite(PC13, blink);
  timer_tick = true;
}
I noticed that if I remove the display, the led will not blink, but as soon as I connect the screen, the led starts blinking, is your display connected correctly and showing the welcome screen?
(don't forget to remove/change the above alterations when it's working!)
a small error in the answer above: when PC13 it LOW, the led is on, when HIGH it's off (pull down from 3.3V)

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Fri Sep 17, 2021 1:54 am

20210917_085206_01.jpg
The welcome screen.

tardishead
Wiggling with Experience
Posts: 359
Joined: Sat Aug 03, 2013 3:00 pm
Location: London

Re: 4 Channel Quadrature LFO

Post by tardishead » Fri Sep 17, 2021 6:46 am

Right I seem to be getting somewhere
I changed

Code: Select all

  timer.attachInterrupt(4,overflowISR);
to

Code: Select all

  timer.attachInterrupt(overflowISR);
And now it goes to the next screen and starts producing LFOs. What does "4" do in the original code?

I have an unusable amount of bounce from the encoder and pushbutton even with the debounce RC filters. By the way what does 100E mean on the schematic? I presume that is 100K
I am still using Blackpill
BUT DEFINITELY PROGRESS

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Fri Sep 17, 2021 1:53 pm

100E is 100ohm
I have an unusable amount of bounce from the encoder and pushbutton
This makes sense now….

tardishead
Wiggling with Experience
Posts: 359
Joined: Sat Aug 03, 2013 3:00 pm
Location: London

Re: 4 Channel Quadrature LFO

Post by tardishead » Fri Sep 17, 2021 2:26 pm

Code: Select all

  timer.attachInterrupt(4,overflowISR);
What does the 4 do?
I had t take it out and now it works

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1926
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Re: 4 Channel Quadrature LFO

Post by Grumble » Fri Sep 17, 2021 3:28 pm

I'm not very good in programming, and I assume I found part of the code on internet regarding the timer interrupts and just used it without fully understanding what is going on with the code.

Code: Select all

/*
 Timer Interrupts Example

 Demonstrates usage of the HardwareTimer classes by blinking the LED
 
 Created 22 April 2010, last updated 8 June 2010
 By Bryan Newbold for LeafLabs
 This code is released with no strings attached.
 
 */

#define LED_PIN 13
#define BUTTON_PIN 38
#define LED_RATE 500000    // in microseconds; should give 0.5Hz toggles

void handler_led(void);
void handler_count1(void);
void handler_count2(void);

int toggle = 0;

int count1 = 0;
int count2 = 0;

void setup()
{
	Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
    // Set up the LED to blink 
    pinMode(LED_PIN, OUTPUT);

    // Set up BUT for input
    pinMode(BUTTON_PIN, INPUT_PULLUP);

    // Setup LED Timer
    Timer2.setMode(TIMER_CH1, TIMER_OUTPUTCOMPARE);
    Timer2.setPeriod(LED_RATE); // in microseconds
    Timer2.setCompare(TIMER_CH1, 1);      // overflow might be small
    Timer2.attachInterrupt(TIMER_CH1, handler_led);

    // Setup Counting Timers
    Timer3.setMode(TIMER_CH1, TIMER_OUTPUTCOMPARE);
    Timer4.setMode(TIMER_CH1, TIMER_OUTPUTCOMPARE);
    Timer3.pause();
    Timer4.pause();
    Timer3.setCount(0);
    Timer4.setCount(0);
    Timer3.setOverflow(30000);
    Timer4.setOverflow(30000);
    Timer3.setCompare(TIMER_CH1, 1000);   // somewhere in the middle
    Timer4.setCompare(TIMER_CH1, 1000);   
    Timer3.attachInterrupt(TIMER_CH1, handler1);
    Timer4.attachInterrupt(TIMER_CH1, handler2);
    Timer3.resume();
    Timer4.resume();

}

void loop() {

    // Display the running counts
    Serial.print("Count 1: "); 
    Serial.print(count1);
    Serial.print("\t\tCount 2: "); 
    Serial.println(count2);

    // Run... while BUT is held, pause Count2
    for(int i = 0; i<1000; i++) {
        if(digitalRead(BUTTON_PIN)) {
            Timer4.pause();
        } else {
            Timer4.resume();
        }
        delay(1);
    }
}

void handler_led(void) {
    toggle ^= 1;
    digitalWrite(LED_PIN, toggle);
} 

void handler1(void) {
    count1++;
} 
void handler2(void) {
    count2++;
} 
But if you look at this example, the 4 has to do with the timer channel 4 (have no idea what that means... :mrgreen:
Great you got it sorted :yay:

Post Reply

Return to “Music Tech DIY”