2 Replies Latest reply on Feb 25, 2020 7:13 PM by BoTa_264741

    further details on my failed attempts to write function values to arrays

    RoBu_286116

      Hi again folks. I've sent you a simplified test program, including what works and what does not. Type of psoc and version of creator are irrelevant, but I'm using a psoc5, creator version 3.3 (less clutter than latest version).  By the way, variables declared at the top are supposed to be global, so the function call should not care.  

      Any ideas ?     So, how come I cannot put math function calls inside a DO loop ?  I also tried rewriting this using just IF statements, and it also failed. Try it yourself ! Nice staircase function using only the first of the three functions.

       

       

      // 2/25/20 BB. This simplified test program is done to show how to be able to generate

      // a multipoint waveform to modify various acquired data sets.

      #include <project.h>

      #include <math.h>

       

      int main()

      {

      double A;

      double B;

      uint8 n; 

       

      VDAC8_1_Start();

      // The top design of this test program merely has a vdac wired to an output pin.

      // If the first of the three commented statements listed below is uncommented,

      // then the oscilloscope shows a nice staircase waveform. Either of the other

      // two statements fail to compile, which is the goal. 

       

      for(;;) 

        {

        for(n=1;n<=10;n=n+1)

        {

        //A=A+10.0; This statement here compiles correctly

        //A=cos(A); This statement here does not compile correctly

        //A=exp(A); This statement here does not compile correctly 

        VDAC8_1_SetValue(A);

        CyDelay(10);

        if(n==10)

        A=1.0;

        }

        }

      }

      /* [] END OF FILE */

        • 1. Re: further details on my failed attempts to write function values to arrays
          MoTa_728816

          Hi,

           

          I tested using CY8CKIT-059

           

          schematic

          000-scheamtic.JPG

          pins

          001-pins.JPG

          main.c

          ===========

          #include "project.h"

          #include "stdio.h"

          #include "math.h"

           

          #ifndef M_PI

          #define M_PI 3.14159

          #endif

           

          #define STR_LEN 64

          char str[STR_LEN+1] ;

          void print(char *str)

          {

              UART_PutString(str) ;

          }

           

          void print_as_float(double v)

          {

              if (v < 0.0) {

                  v = -v ;

                  snprintf(str, STR_LEN, "-%d.%03d ",

                      (int)v, (int)(v * 1000) % 1000 ) ;

              } else {

                  snprintf(str, STR_LEN, "%d.%03d ",

                      (int)v, (int)(v * 1000) % 1000 ) ;

              }

              print(str) ;       

          }

           

          int main(void)

          {

              double A = 1.0 ;

              double B = 1.0 ;

              uint8_t n ;

             

              CyGlobalIntEnable; /* Enable global interrupts. */

             

              UART_Start() ;

           

              for(;;)

              {

                  for (n = 1 ; n <= 10 ; n++) {

                      A = cos(M_PI * n / 10.0) ;

                      B = exp(5.0 / n) ;

                     

                     print_as_float(A) ;

                     print_as_float(B) ;

                     print("\n") ;

                      if (n == 10) {

                          A = 1.0 ;

                          B = 1.0 ;

                      }

                  }

                  CyDelay(1000) ;

              }

          }

          ===========

           

          Tera Term log

          003-TeraTerm-log.JPG

          moto

          • 2. Re: further details on my failed attempts to write function values to arrays
            BoTa_264741

            RoBu,

            You didn't attach project archive, so my guess that in Project->Build Settings->Linker->additional libraries->add "m" (math)

            /odissey1

            1 of 1 people found this helpful