1

when I load this onto my board, I get a pinmap not found for peripheral error. I did some research on this problem (One of the pages I visited) and I think I understand the problem, however the pins I'm using all support exactly what I'm asking them to do. This problem has only arisen since I converted my code from procedural to object orientated (I need to do this to implement scheduling properly).

I have a feeling it's to do with how I'm initializing them in the constructor member initialiser list as i don't fully understand how it works (I'm fairly new to C++).

there are other classes to my program however they follow the same structure as my UpdateOutput class.

Thanks in advance for any advice.

int main() {
    printf("inside main");

    DigitalOut led1(LED1);
    AnalogOut Vout(A0);
    UpdateOutput wave;
    SensorData inputs;
    Timer time;

    enum waves {OFF = 0, SINE, TRIANGLE, SAW, SQUARE};
    int waveType = OFF;

    float sonarCorrection = inputs.calibrateSonar();//makes a measurement of the acatual run time of the sonar code
    float topFrequency = 1047.0f;                                       //the highest frequency the synth will play
    float upperSonarThreshold = 1000.0f;                        //the furthest distance the sonar will register
    float lowerSonarThreshold = 100.0f;                         //the closest distance the sonar will measure
    float period = 2272.73f; 
    //replace with:
    //float period = inputs.getFrequency(float lowerThreshold, float upperThreshold, int correction, float topFrequency);
    //after bug fixes have been applied

    led1 = 1;                   //turn on led1 to show code is running properly

    time.reset();
    time.start();
    int tmr = time.read_us();

    //test loop before thredding is applied
    while(true)
    {
        waveType = SINE; //keep synth producing a sine wave for testing
        tmr = time.read_us();
        switch(waveType)
        {
            case OFF:
                Vout = 0.0f;
                break;

            case SINE:
                Vout = wave.sinWave(tmr , period);
                break;

            case TRIANGLE:
                Vout = wave.triangleWave(tmr , period);
                break;

            case SAW:
                    Vout = wave.sawWave(tmr, period);
                break;

            case SQUARE:
                Vout = wave.squareWave(tmr, period);
                break;

            default:
                waveType = TRIANGLE;
                break;


        }//end of wave type switch case
    }

}

Update Output class:

class UpdateOutput{


    public:


            //constructor for class, with member initializer list
                UpdateOutput(): runLed(LED2), clipLed(LED3), dac(D13) 
                {}

            float sinWave(int tmr, float period);

            float sawWave(int tmr, float period);

            float triangleWave(int tmr, float period);

            float squareWave(int tmr, float period);


    private:

    //class attributes
    DigitalOut runLed;
    DigitalOut clipLed;
    AnalogOut dac;

    //extern float frequency(float lowerThreshold, float upperThreshold, int correction);
    bool waveState = 0;
    //float lastVout;
};

example of function within UpdateOutputs class

float UpdateOutput::squareWave(int tmr, float period){
    float Vout = 0.0f;
    //float period5 = period/1.587401052;
    float resultingWave;

    float x = (float)(tmr % (int)period)/period;

    if (x > 0.5f){
        resultingWave = 1.0f;
    }
    else{
        Vout = 0.0f;
    }

    Vout = (resultingWave/WAVE_DEVIDOR)+(0.25f); //translate wave to work between 0 and 1 rather than -1 and 1
    if (Vout > 1){
        clipLed = 1;
        Vout = 1.0f;
    }
    else if (Vout < 0.0f){
        clipLed = 1;
        Vout = 0.0f;
    }
    //printf("Vout = %5.3f\n\r", Vout);
    return Vout;
}//end of squareWave
Clifford
  • 88,407
  • 13
  • 85
  • 165
Jake
  • 90
  • 9
  • If you have procedural code that works and this code that does not, posting the code that works for comparison might be helpful. – Clifford Apr 29 '20 at 14:26
  • Your justification for using OOP is a non-sequitur and in any case unnecessary. It may attract comment unrelated to your question. Best removed I think. Also you changed the code and it broke - it is not because you made it more OO that it broke, you simply introduced an error when refactoring - could have happened regardless of the paradigm. – Clifford Apr 29 '20 at 14:58
  • The reason for making this an OOP is because I need to incorporate thredding and sheduling as this is running on a Cortex M4. There are many other functions that need to be added that would be blocked if I don't make OO. But thanks anyway. – Jake Apr 29 '20 at 15:20
  • There will also be multiple instances of certain objects, as I have multiple of the same sensors that could run of the same code – Jake Apr 29 '20 at 15:22
  • My point was that your reasons for using OOP are not relevant to the question, and need not be justified. Nonetheless you added further justification in your comment - it needs no justification, it is a legitimate design choice. However you added a further non-sequitur in the comment _Cortex-M4 -> need threading -> need OOP_ do not follow. But again using threading/scheduling is a legitimate design decision but not related to the question. Removing the mention of coding paradigm, scheduling, and any justification for either would be to remove unnecessary distractions - that is all. – Clifford Apr 29 '20 at 17:22

1 Answers1

1

You are using AnalogOut Vout(A0); as your DAC output in main(). Perhaps you intended to update UpdateOutput::dac directly in the class>

A0 is assigned PA_3 in PinNames.h while PeripheralPinMaps.h has:

//*** DAC ***

MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_DAC[] = {
    {PA_4,       DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC_OUT1
    {PA_5,       DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC_OUT2
    {NC, NC, 0}
};

So it is the AnalogOut Vout(A0); is invalid. D13 assigned to UpdateOutput::dac and which is an alias for PA_5 however is correct.

You might change AnalogOut Vout(A0) to AnalogOut Vout(D13);, but I suspect that your either are, or intended to update UpdateOutput::dac in the waveform generator functions themselves rather then assigning their return value.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • That seems to be it! i'm not getting the error message anymore and led1 (which im using to tell if the code is running) is on. The program is still not doing what it's supposed to. But hopefully I can figure it out from here. Thanks alot! – Jake Apr 29 '20 at 15:12