Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. Error Esp32
Posted: Fri Sep 15, 2023 5:09 am
I'm trying to implement speech recognition on a max9814 microphone module. I found the code in the article, but it was written for Arduino Nano. I tried to port the code to Esp32, but I have little experience in this matter, and I studied some points in ChatGpt. However, I eventually ran into this error:
And after that the error repeats.
Program code:
Link to article: https://www.instructables.com/Speech-Re ... uino-Nano/
Thank you in advance.
Code: Select all
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400861f4 PS : 0x00060c30 A0 : 0x800d16bd A1 : 0x3ffc5450
A2 : 0x3ffc546e A3 : 0x0000017a A4 : 0x000000ff A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x800d1681 A9 : 0x3ffc5310
A10 : 0x3ffc546e A11 : 0x0000000d A12 : 0x00000001 A13 : 0x00002710
A14 : 0x3ffc1d54 A15 : 0xff000000 SAR : 0x0000000a EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000017a LBEG : 0x400d15f1 LEND : 0x400d1622 LCOUNT : 0x00000000
Backtrace: 0x400861f1:0x3ffc5450 0x400d16ba:0x3ffc5460 0x400d1851:0x3ffc54b0 0x400d1971:0x3ffc54d0 0x400d25e1:0x3ffc54f0
ELF file SHA256: 462eb524cea7298d
Rebooting...
Program code:
Code: Select all
//-----------------------------------------------------------------------------
// Copyright 2021 Peter Balch
// распознавание слов
// подлежит GNU General Public License
//-----------------------------------------------------------------------------
#include <Arduino.h>
#include "driver/adc.h"
#include "Coeffs.h"
#include "Templates.h"
//-----------------------------------------------------------------------------
// Defines, constants and Typedefs
//-----------------------------------------------------------------------------
// Пины
const int AUDIO_IN = 35; // Используйте соответствующий пин ADC на ESP32
//-----------------------------------------------------------------------------
// Глобальные константы
//-----------------------------------------------------------------------------
const byte SegmentSize = 50; // в миллисекундах
const byte hyster = 2;
const byte thresh = 100;
//-----------------------------------------------------------------------------
// Глобальные переменные
//-----------------------------------------------------------------------------
int CurBandData[nSegments][nBand + 1]; // текущие данные полосы
bool bAnalyse = true;
//-------------------------------------------------------------------------
// GetSerial
//-------------------------------------------------------------------------
byte GetSerial() {
while (Serial.available() == 0);
return Serial.read();
}
//-------------------------------------------------------------------------
// PollBands
//-------------------------------------------------------------------------
bool PollBands(bool init)
{
bool IsPos, Collecting;
static unsigned long prevTime;
byte band, seg, val1, val2, i;
const byte hyster = 20;
static int zero = 500;
static byte curSegment = 255;
long val;
word zcr;
static int valmax[10];
static int pd[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static int ppd[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static int ppval = 0;
static int pval = 0;
if (init)
{
memset(pd, 0, sizeof(pd));
memset(ppd, 0, sizeof(ppd));
memset(CurBandData, 0, sizeof(CurBandData));
pval = 0;
ppval = 0;
return false;
}
val = 0;
IsPos = true;
Collecting = false;
int n = 0;
for (curSegment = 0; curSegment < nSegments; curSegment++) {
zcr = 0;
prevTime = 0;
memset(valmax, 0, sizeof(valmax));
prevTime = millis();
while (millis() - prevTime < SegmentSize)
{
// val = analogRead(AUDIO_IN);
val1 = analogRead(AUDIO_IN);
val2 = val1 >> 8;
val1 &= 0xFF;
val = val1 + (val2 << 8);
if (val < zero)
zero--;
else
zero++;
val = val - zero;
if (!Collecting) {
if (abs(val) > thresh)
Collecting = true; else
return false;
}
if (IsPos)
{
if (val < -hyster)
{
IsPos = false;
zcr++;
}
} else {
if (val > +hyster)
{
IsPos = true;
zcr++;
}
}
ppval = pval;
pval = val;
for (band = 0; band < nBand; band++)
{
int L1, L2;
L1 = ((-(filt_b1[band]) * pd[band] - filt_b2[band] * ppd[band]) >> 16) + val;
L2 = (filt_a0[band] * L1 - filt_a0[band] * ppd[band]) >> 16;
ppd[band] = pd[band];
pd[band] = L1;
if (abs(L2) > valmax[band])
valmax[band]++;
}
}
for (band = 0; band < nBand; band++)
CurBandData[curSegment][band + 1] = valmax[band];
CurBandData[curSegment][0] = zcr;
}
if (Collecting) {
Serial.println("a");
SendUtterance(CurBandData);
if (bAnalyse)
AnalyseUtterance(CurBandData);
}
return Collecting;
}
//-----------------------------------------------------------------------------
// AnalyseUtterance
//-----------------------------------------------------------------------------
void AnalyseUtterance(int Utterance[nSegments][nBand+1]) {
int i,dist;
char buffer[30];
i = FindBestUtterance(Utterance,&dist);
strcpy_P(buffer, (char *)pgm_read_word(&(sUtterances[i])));
Serial.println(i);
Serial.println(buffer);
}
//-----------------------------------------------------------------------------
// PrintCurBandData
//-----------------------------------------------------------------------------
void PrintCurBandData(void)
{
byte seg, band;
Serial.println("a");
for (seg = 0; seg < nSegments; seg++) {
for (band = 0; band <= nBand; band++) {
Serial.print(CurBandData[seg][band]);
Serial.print(" ");
}
Serial.println("");
}
}
//-----------------------------------------------------------------------------
// SendUtterance
//-----------------------------------------------------------------------------
void SendUtterance(int Utterance[nSegments][nBand+1])
{
byte seg,band;
for (seg = 0; seg < nSegments; seg++) {
for (band = 0; band <= nBand; band++) {
Serial.print(Utterance[seg][band]);
Serial.print(" ");
}
Serial.println("");
}
}
//-----------------------------------------------------------------------------
// ShiftedDistance
// distance from Utterance shifted by shift
// to Templates[TemplateUtt]
//-----------------------------------------------------------------------------
int ShiftedDistance(int Utterance[nSegments][nBand+1], byte TemplateUtt, int8_t shift){
byte band,seg,importance;
int aUtterance[nSegments][nBand+1];
int Dist,aMean,aSD;
ShiftUtterance(Utterance, aUtterance, shift);
Dist = 0;
for (seg = 0; seg < nSegments; seg++) {
if (seg == 0)
importance = 2; else
importance = 1;
for (band = 0; band <= nBand; band++) {
aMean = pgm_read_word(&Templates[TemplateUtt][seg][band].mean);
aSD = pgm_read_word(&Templates[TemplateUtt][seg][band].sd);
Dist = constrain(Dist+importance*abs(((long)aUtterance[seg][band])-aMean)*1000 / (50+aSD),-10000,+10000);
}
}
return Dist;
}
//-----------------------------------------------------------------------------
// ShiftUtterance
// shift an utterance by shift/SubShifts
//-----------------------------------------------------------------------------
void ShiftUtterance(int utSource[nSegments][nBand+1], int utDest[nSegments][nBand+1], int shift) {
int8_t i,j,k,n;
int m;
byte seg,band;
if (shift == 0) {
for (seg = 0; seg < nSegments; seg++)
for (band = 0; band <= nBand; band++)
utDest[seg][band] = utSource[seg][band];
} else {
for (seg = 0; seg < nSegments; seg++)
{
n = SubShifts*(nSegments-1);
i = shift*(nSegments-1);
j = -i / (SubShifts*(nSegments-1));
i = abs(i) % ((nSegments-1)*SubShifts);
if (shift < 0)
k = j+1; else
k = j-1;
for (band = 0; band <= nBand; band++) {
if ((seg+j >= 0) && (seg+j < nSegments))
m = utSource[seg+j][band]*((nSegments-1)*SubShifts-i) / n; else
m = 0;
if ((seg+k >= 0) && (seg+k < nSegments))
m = m+utSource[seg+k][band]*i / n;
utDest[seg][band] = m;
}
}
}
NormaliseUtterance(utDest);
}
//-----------------------------------------------------------------------------
// NormaliseUtterance
//-----------------------------------------------------------------------------
void NormaliseUtterance(int Utterance[nSegments][nBand+1]) {
byte seg,band;
long SegmentTotal,i;
SegmentTotal = 0;
for (seg = 0; seg < nSegments; seg++)
for (band = 0; band <= nBand; band++)
SegmentTotal += Utterance[seg][band];
SegmentTotal = max(SegmentTotal, static_cast<long>(1));
i = 50*nSegments*nBand;
for (seg = 0; seg < nSegments; seg++)
for (band = 0; band <= nBand; band++)
Utterance[seg][band] = (i*Utterance[seg][band]) / SegmentTotal;
}
//-----------------------------------------------------------------------------
// FindBestShift
//-----------------------------------------------------------------------------
int FindBestShift(int Utterance[nSegments][nBand+1], int TemplateUtt) {
int dist,BestShift,BestShiftDist,shift;
BestShiftDist = 0x7FFF;
for (shift = -MaxShift; shift <= MaxShift; shift++) {
dist = ShiftedDistance(Utterance,TemplateUtt,shift);
if (dist < BestShiftDist) {
BestShiftDist = dist;
BestShift = shift;
}
}
return BestShift;
}
//-----------------------------------------------------------------------------
// FindBestUtterance
// which template best fits the utterance
//-----------------------------------------------------------------------------
int FindBestUtterance(int Utterance[nSegments][nBand+1], int *BestDist) {
int dist,BestUttDist,shiftDist;
int BestUtt,shift,TemplateUtt;
BestUtt = 0;
*BestDist = 0;
BestUttDist = 0x7FFF;
for (TemplateUtt = 0; TemplateUtt < nUtterances; TemplateUtt++) {
shift = FindBestShift(Utterance,TemplateUtt);
shiftDist = ShiftedDistance(Utterance,TemplateUtt,shift);
if (shiftDist < BestUttDist) {
BestUttDist = shiftDist;
BestUtt = TemplateUtt;
*BestDist = BestUttDist;
}
}
return BestUtt;
}
//-----------------------------------------------------------------------------
// CheckSerial
//-----------------------------------------------------------------------------
void CheckSerial(void)
{
byte seg,band,i,j;
static int Utterance[nSegments][nBand+1];
if (Serial.available() > 0) {
switch (GetSerial()) {
case 'u':
for (seg = 0; seg < nSegments; seg++) {
for (band = 0; band <= nBand; band++) {
Utterance[seg][band] = GetSerial();
Utterance[seg][band] += 256*GetSerial();
}
}
break;
// case 's':
// ShiftUtterance(Utterance,Utterance2,(int8_t)GetSerial());
// Serial.println('s');
// SendUtterance(Utterance2);
// break;
// case 'd':
// Serial.println('d');
// i = (int8_t)GetSerial();
// j = (int8_t)GetSerial();
// Serial.println(ShiftedDistance(Utterance, i, j));
// break;
// case 'b':
// Serial.println('b');
// Serial.println(FindBestShift(Utterance, GetSerial()));
// break;
case 'b':
Serial.println('b');
bAnalyse = false; // не анализировать фразы - мы просто собираем данные
break;
case 'c':
Serial.println('c');
bAnalyse = true; // анализировать фразы
break;
case 'f':
Serial.println('f');
AnalyseUtterance(Utterance);
break;
}
}
}
//-------------------------------------------------------------------------
// setup
//-------------------------------------------------------------------------
void setup(void)
{
Serial.begin(57600);
Serial.println("speechrecog");
pinMode(AUDIO_IN, INPUT);
adcAttachPin(AUDIO_IN);
analogSetAttenuation(ADC_11db);
analogSetWidth(12);
analogRead(AUDIO_IN); // инициализация АЦП для чтения аудио-сигнала
Serial.println("0 0 0 0 0 0 350");
PollBands(true);
}
//-----------------------------------------------------------------------------
// Основные процедуры
// loop
//-----------------------------------------------------------------------------
void loop(void)
{
CheckSerial();
PollBands(false);
}
Thank you in advance.