- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 */
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
RoBu,
You didn't attach project archive, so my guess that in Project->Build Settings->Linker->additional libraries->add "m" (math)
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I tested using CY8CKIT-059
schematic
pins
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
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
RoBu,
You didn't attach project archive, so my guess that in Project->Build Settings->Linker->additional libraries->add "m" (math)
/odissey1