Goertzel for stm32f103 LCD

What are you developing?
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

Goertzel for stm32f103 LCD

Post by stan »

Hi
This program is working fine with arduino uno, for blue pill there is compiling error. I looked at Goertzel.h but I didn't find something special which can cause the problem.
Here are, program, error, Goertzel.h file.

Code: Select all

// Set things up
//http://play.fallows.ca/wp/radio/ham-radio/signal-analysis-morse-decoder/
#include <Goertzel.h>
int sensorPin =PA6;
//int sensorPin =A0;
int led = PC13;
//int led = 13;
//const float TARGET_FREQUENCY = 500;
const float TARGET_FREQUENCY = 5000;
const int N = 100;
const float THRESHOLD = 4000;
const float SAMPLING_FREQUENCY = 8900;
// Create the filter
//Goertzel goertzel = Goertzel(TARGET_FREQUENCY, N, SAMPLING_FREQUENCY); 
Goertzel goertzel = Goertzel(TARGET_FREQUENCY, N, SAMPLING_FREQUENCY);
 
void setup(){
  pinMode(led, OUTPUT);    
  Serial.begin(115200);
}
 
void loop()
{
   goertzel.sample(sensorPin);
// Check samples for tone at target
   float magnitude = goertzel.detect();
// if the tone is present, light LED
   if(magnitude>THRESHOLD)
     digitalWrite(led, HIGH);
   else
     digitalWrite(led, LOW);
     // Serial.println(magnitude);
      Serial.println(magnitude);
}
///////////////////////////////////////////////////////////////
error

Arduino: 1.8.8 (Windows 10), Board: "Generic STM32F1 series, BluePill F103C6 (32K), STLink, Enabled (generic 'Serial'), None, Low/Full Speed, Smallest (-Os default), Newlib Nano (default)"

A subdirectory or file sketch already exists.

In file included from c:\users\galinka\appdata\local\arduino15\packages\stm32\tools\arm-none-eabi-gcc\6-2017-q2-update\arm-none-eabi\include\c++\6.3.1\cctype:42:0,

from c:\users\galinka\appdata\local\arduino15\packages\stm32\tools\arm-none-eabi-gcc\6-2017-q2-update\arm-none-eabi\include\c++\6.3.1\bits\localefwd.h:42,

from c:\users\galinka\appdata\local\arduino15\packages\stm32\tools\arm-none-eabi-gcc\6-2017-q2-update\arm-none-eabi\include\c++\6.3.1\string:43,

from c:\users\galinka\appdata\local\arduino15\packages\stm32\tools\arm-none-eabi-gcc\6-2017-q2-update\arm-none-eabi\include\c++\6.3.1\stdexcept:39,

from c:\users\galinka\appdata\local\arduino15\packages\stm32\tools\arm-none-eabi-gcc\6-2017-q2-update\arm-none-eabi\include\c++\6.3.1\array:39,

from c:\users\galinka\appdata\local\arduino15\packages\stm32\tools\arm-none-eabi-gcc\6-2017-q2-update\arm-none-eabi\include\c++\6.3.1\tuple:39,

from c:\users\galinka\appdata\local\arduino15\packages\stm32\tools\arm-none-eabi-gcc\6-2017-q2-update\arm-none-eabi\include\c++\6.3.1\functional:55,

from C:\Users\Galinka\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.5.0\cores\arduino/WInterrupts.h:25,

from C:\Users\Galinka\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.5.0\cores\arduino/wiring.h:39,

from C:\Users\Galinka\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.5.0\cores\arduino/Arduino.h:32,

from C:\Users\Galinka\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:19:

C:\Users\Galinka\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:26:5: error: expected unqualified-id before numeric constant

int _N;

^

In file included from C:\Users\Galinka\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:22:0:

C:\Users\Galinka\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp: In constructor 'Goertzel::Goertzel(float, float, float)':

C:\Users\Galinka\Documents\Arduino\libraries\Goertzel-master\Goertzel.h:26:14: error: lvalue required as left operand of assignment

#define MAXN 200

^

C:\Users\Galinka\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:48:9: note: in expansion of macro 'MAXN'

_N=MAXN;

^~~~

C:\Users\Galinka\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:50:8: error: lvalue required as left operand of assignment

_N=N;

^

exit status 1
Error compiling for board Generic STM32F1 series.


Goertzel.h

Code: Select all

/*
  The Goertzel algorithm is long standing so see 
  http://en.wikipedia.org/wiki/Goertzel_algorithm for a full description.
  It is often used in DTMF tone detection as an alternative to the Fast 
  Fourier Transform because it is quick with low overheard because it
  is only searching for a single frequency rather than showing the 
  occurrence of all frequencies.
  
  This work is entirely based on the Kevin Banks code found at
  http://www.eetimes.com/design/embedded/4024443/The-Goertzel-Algorithm 
  so full credit to him for his generic implementation and breakdown. I've
  simply massaged it into an Arduino library. I recommend reading his article
  for a full description of whats going on behind the scenes.

  See Contributors.md and add yourself for pull requests
  Released into the public domain.
*/

// ensure this library description is only included once
#ifndef Goertzel_h
#define Goertzel_h

// include types & constants of Wiring core API
#include "Arduino.h"

#define MAXN 200
#define ADCCENTER 512

// library interface description
class Goertzel
{
  // user-accessible "public" interface
  public:
    Goertzel(float,float,float);
    Goertzel(float,float);
	void sample(int);
	float detect();

  // library-accessible "private" interface
  private:
	void GetRealImag(float*,float*);
	void ProcessSample(int);
	void ResetGoertzel(void);
	
};

#endif
Last edited by stan on Fri Dec 18, 2020 4:43 pm, edited 1 time in total.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Goertzel for stm32f103

Post by fpiSTM »

Firstly, update to latest release 1.9.0.

Edit:
In fact you used _N while it is a definition in ctypes.h:

Code: Select all

#define	_N	04
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

Re: Goertzel for stm32f103

Post by stan »

With new IDE the error is;

Arduino: 1.9.0-beta (Windows 7), Board: "Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), STM32duino bootloader, 72Mhz (Normal), Smallest (default)"

In file included from C:\Users\John\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2017.8.5\cores\maple/WString.h:28:0,

from C:\Users\John\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2017.8.5\cores\maple/wirish.h:47,

from C:\Users\John\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2017.8.5\cores\maple/Arduino.h:30,

from C:\Users\John\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:19:

C:\Users\John\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:26:5: error: expected unqualified-id before numeric constant

int _N;

^

C:\Users\John\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp: In constructor 'Goertzel::Goertzel(float, float, float)':

C:\Users\John\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:48:8: error: lvalue required as left operand of assignment

_N=MAXN;

^

C:\Users\John\Documents\Arduino\libraries\Goertzel-master\Goertzel.cpp:50:7: error: lvalue required as left operand of assignment

_N=N;

^

exit status 1
Error compiling for board Generic STM32F103C series.
feluga
Posts: 64
Joined: Wed Mar 18, 2020 2:50 am

Re: Goertzel for stm32f103

Post by feluga »

stan wrote: Wed Dec 16, 2020 11:14 pm error

Arduino: 1.8.8 (Windows 10), Board: "Generic STM32F1 series, BluePill F103C6 (32K), STLink, Enabled (generic 'Serial'), None, Low/Full Speed, Smallest (-Os default), Newlib Nano (default)"
The problem is in the board you selected. Use BluePill F103C8 instead of BluePill F103C6 (32K).
Change it on Arduino IDE menu "Tools" --> "Board Part Number:" option.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Goertzel for stm32f103

Post by fpiSTM »

The main issue is that you used _N in your code as a variable name while it is a statndard definiton in ctype.h of the toolchain.
Simply change it and this will work...
feluga
Posts: 64
Joined: Wed Mar 18, 2020 2:50 am

Re: Goertzel for stm32f103

Post by feluga »

fpiSTM wrote: Thu Dec 17, 2020 5:47 pm The main issue is that you used _N in your code as a variable name while it is a statndard definiton in ctype.h of the toolchain.
Simply change it and this will work...
Looking at Goertzel.cpp, there may be another potential problem, beside the compiling issue you pointed with _N, regarding CPU Frequency:

Code: Select all

Goertzel::Goertzel(float TARGET_FREQUENCY, float N, float SAMPLING_FREQUENCY)
{
  
  _SAMPLING_FREQUENCY=SAMPLING_FREQUENCY;	//on 16mhz, ~8928.57142857143, on 8mhz ~44444
  _TARGET_FREQUENCY=TARGET_FREQUENCY; //should be integer of SAMPLING_RATE/N
  if(N>MAXN){
     _N=MAXN;
  }else{
    _N=N;
  }
  
  float omega = (2.0 * PI * _TARGET_FREQUENCY) / _SAMPLING_FREQUENCY;

  coeff = 2.0 * cos(omega);

  ResetGoertzel();
}

This may demand some "manual" adjusting of MAXN and N... Thus, even if it compiles right, it may not work properly.
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

Re: Goertzel for stm32f103

Post by stan »

so I made modification

Code: Select all

// Set things up
//http://play.fallows.ca/wp/radio/ham-radio/signal-analysis-morse-decoder/
#include <Goertzel.h>
int sensorPin =PA6;
//int sensorPin =A0;
int led = PC13;
//int led = 13;
//const float TARGET_FREQUENCY = 500;
const float TARGET_FREQUENCY = 5000;
const int N = 100;
const float THRESHOLD = 4000;
const float SAMPLING_FREQUENCY = 8900;
int coeff;
 int goertzel;
// Create the filter
//Goertzel goertzel = Goertzel(TARGET_FREQUENCY, N, SAMPLING_FREQUENCY); 
//Goertzel goertzel = Goertzel(TARGET_FREQUENCY, N, SAMPLING_FREQUENCY);
//////////////////
Goertzel::Goertzel(float TARGET_FREQUENCY, float N, float SAMPLING_FREQUENCY)
{

  
  SAMPLING_FREQUENCY=SAMPLING_FREQUENCY;  //on 16mhz, ~8928.57142857143, on 8mhz ~44444
  TARGET_FREQUENCY=TARGET_FREQUENCY; //should be integer of SAMPLING_RATE/N
  if(N>MAXN){
     N=MAXN;
  }else{
    N=N;
  }
  
  float omega = (2.0 * PI * TARGET_FREQUENCY) / SAMPLING_FREQUENCY;

  coeff = 2.0 * cos(omega);

  ResetGoertzel();
}
/////////////////
 
void setup(){
  pinMode(led, OUTPUT);    
  Serial.begin(115200);
}
 
void loop()
{
   goertzel.sample(sensorPin);
// Check samples for tone at target
   float magnitude = goertzel.detect();
// if the tone is present, light LED
   if(magnitude>THRESHOLD)
     digitalWrite(led, HIGH);
   else
     digitalWrite(led, LOW);
     // Serial.println(magnitude);
      Serial.println(magnitude);
}
///////////////////////////////////////////////////////////////
and error is;
Arduino: 1.8.12 (Mac OS X), Board: "Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), STLink, 72Mhz (Normal), Smallest (default)"

/Users/Documents/Arduino/goertzel_org3/goertzel_org3.ino: In function 'void loop()':
goertzel_org3:46:13: error: request for member 'sample' in 'goertzel', which is of non-class type 'int'
goertzel.sample(sensorPin);
^~~~~~
goertzel_org3:48:31: error: request for member 'detect' in 'goertzel', which is of non-class type 'int'
float magnitude = goertzel.detect();
^~~~~~
exit status 1
request for member 'sample' in 'goertzel', which is of non-class type 'int'
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Goertzel for stm32f103

Post by fredbox »

Replacing _N in Goertzel.cpp as advised by fpiSTM allows the example program to compile without error.
This will probably need more work to actually do something useful as the CPU frequencies are quite different between the two processors.

Code: Select all

26 int _Number;
48      _Number=MAXN;
50      _Number=N;

Code: Select all

Sketch uses 23944 bytes (36%) of program storage space. Maximum is 65536 bytes.
Global variables use 1696 bytes (8%) of dynamic memory, leaving 18784 bytes for local variables. Maximum is 20480 bytes.
Last edited by fredbox on Fri Dec 18, 2020 7:59 pm, edited 1 time in total.
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

Re: Goertzel for stm32f103

Post by stan »

Thanks it is done, no errors. For some reason I have higher space usage

Code: Select all

Sketch uses 25352 bytes (38%) of program storage space. Maximum is 65536 bytes.
Global variables use 3960 bytes (19%) of dynamic memory, leaving 16520 bytes for local variables. Maximum is 20480 bytes.
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

Re: Goertzel for stm32f103 LCD

Post by stan »

it is compiling but not working I added LCD, in uno LCD it is alive in stm32 it is dead just displays 0.00 and do on respond to signal on PA6.

Code: Select all

// Set things up
//http://play.fallows.ca/wp/radio/ham-radio/signal-analysis-morse-decoder/
#include <Goertzel.h>
int sensorPin = PA6;
//int sensorPin =A0;
int led = PC13;
//int led = 13;
//const float TARGET_FREQUENCY = 500;
const float TARGET_FREQUENCY = 5000;
const int N = 100;
const float THRESHOLD = 4000;
const float SAMPLING_FREQUENCY = 8900;
// Create the filter
//Goertzel goertzel = Goertzel(TARGET_FREQUENCY, N, SAMPLING_FREQUENCY);
Goertzel goertzel = Goertzel(TARGET_FREQUENCY, N, SAMPLING_FREQUENCY);

#include <LiquidCrystal.h>
LiquidCrystal lcd(PB15, PB5, PA2, PB6, PB8, PB9);
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(115200);
    lcd.begin( 16, 2 );
}

void loop()
{
  goertzel.sample(sensorPin);
  // Check samples for tone at target
  float magnitude = goertzel.detect();
  // if the tone is present, light LED
  if (magnitude > THRESHOLD)
    digitalWrite(led, HIGH);
  else
    digitalWrite(led, LOW);
  // Serial.println(magnitude);
  Serial.println(magnitude);

  lcd.setCursor(0, 0);
  lcd.print(magnitude);
}
Post Reply

Return to “Projects”