- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I want to ask if there is a way to make a code work interchangeably with another code, I am programming a set of relays, but when these work they prevent me from executing an lm35 sensor and when the relay has already made its cycle, the lm35 starts running.
The cycle is repeated again, the relays work and the reading of lm35 is cut, then, once the relay cycle is completed, the sensor re-read the temperature again.
How can I make the lm35 read to me without being cut when the relays work? that work together without one cut me reading another. It's just code, probe putting functions and the result was the same, the program runs and the sensor does not go at the same time as the relays, they work first and then the lm35
Someone had this experience, how could he solve it.
I attach my program.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
My new CY8CKIT-059 has just arrived from Digi-Key, as my old one is occupied with another project,
I could not tested, but now I can 😉
So to use UART, I modified the main.c like below
===============================
#include "project.h"
#include "stdio.h"
#define USE_UART 1
#if USE_UART
void print(char *str)
{
UART_PutString(str) ;
}
#endif
int32 entero,voltaje;
float32 temp;
char str[16];
void relay(uint32_t time)
{
switch(time) {
case 0: // at 0sec
Test_Tube_Write(0);
print("\tTest_Tube_Write(0)\n") ;
break ;
case 3000: // at 3sec
Sample_Write(0);
print("\tSample_Write(0)\n") ;
break ;
case 8000: // at 8sec
Molish_Write(0);
print("\tMolish_Write(0)\n") ;
break ;
case 10000: // at 10sec
Sample_Write(1);
print("\tSample_Write(1)\n") ;
Test_Tube_Write(1);
print("\tTest_Tube_Write(1)\n") ;
break ;
case 19000: // at 19sec
Molish_Write(0);
print("\tMolish_Write(0)\n") ;
break ;
}
}
void measure(uint32_t time)
{
if (time % 1000) { // measure only each 1sec => ((time % 1000) == 0)
return ;
}
/*SENSOR LM35*/
ADC_StartConvert();
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
entero = ADC_GetResult32();
ADC_StopConvert();
voltaje = ADC_CountsTo_mVolts(entero);
temp = ((voltaje/10.00)-07.00);
sprintf(str,"%.1f",temp);
#if USE_UART
print("Temp:") ;
print(str) ;
print("\n") ;
#else
LCD_I2C_setCursor(6,1);
LCD_I2C_print(str);
#endif
}
int main(void)
{
uint32_t time = 0 ;
uint32_t delta = 1 ; /* time resolution 1ms */
CyGlobalIntEnable;
I2C_Start();
#if USE_UART
UART_Start() ;
#else
LCD_I2C_start();
#endif
Opamp_Start();
ADC_Start();
#if USE_UART
// print("Temp:") ;
#else
LCD_I2C_setCursor(0,1);
LCD_I2C_print("Temp:");
#endif
for(;;)
{
relay(time);
measure(time) ; /* measure every 1sec */
time = (time + delta) % 31000 ; /* 0 ~ 30999 = 31 sec cycle */
CyDelay(delta) ;
}
}
===============================
And the TeraTerm log was something like
Attached is my test project done with PSoC Creator v4.2.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are some ways out to have two different tasks running at the "same" time.
Using an RTOS (when taking the time to learn how to handle it) is a common solution.
Having a timer that wakes up and signals to handle a (short) task at periodic times
Designing one of the tasks to be interrupt driven thus running in the background
For the sake of compatibility; Can you please post your complete project so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
How about changing main.c like below?
=============================
#include "project.h"
#include "stdio.h"
int32 entero,voltaje;
float32 temp;
char str[16];
/**
* relay
* decide what to do depending on the accumulated time
*/
void relay(uint32_t time)
{
switch(time) {
case 0: // at 0sec
Test_Tube_Write(0);
break ;
case 3000: // at 3sec
Sample_Write(0);
break ;
case 8000: // at 8sec
Molish_Write(0);
break ;
case 10000: // at 10sec
Sample_Write(1);
Test_Tube_Write(1);
break ;
case 19000: // at 19sec
Molish_Write(0);
break ;
}
}
/**
* measure
* currently measure each sec
* the interval can be decided by changing 1000 of "if (time % 1000) {"
*/
void measure(uint32_t time)
{
if (time % 1000) { // measure only each 1sec => ((time % 1000) == 0)
return ;
}
/*SENSOR LM35*/
ADC_StartConvert();
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
entero = ADC_GetResult32();
ADC_StopConvert();
voltaje = ADC_CountsTo_mVolts(entero);
temp = ((voltaje/10.00)-07.00);
sprintf(str,"%.1f",temp);
LCD_I2C_setCursor(6,1);
LCD_I2C_print(str);
}
int main(void)
{
uint32_t time = 0 ;
uint32_t delta = 1 ; /* time resolution 1ms */
CyGlobalIntEnable;
I2C_Start();
LCD_I2C_start();
Opamp_Start();
ADC_Start();
LCD_I2C_setCursor(0,1);
LCD_I2C_print("Temp:");
for(;;)
{
relay(time);
measure(time) ; /* measure every 1sec */
time = (time + delta) % 31000 ; /* 0 ~ 30999 = 31 sec cycle */
CyDelay(delta) ;
}
}
=============================
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
My new CY8CKIT-059 has just arrived from Digi-Key, as my old one is occupied with another project,
I could not tested, but now I can 😉
So to use UART, I modified the main.c like below
===============================
#include "project.h"
#include "stdio.h"
#define USE_UART 1
#if USE_UART
void print(char *str)
{
UART_PutString(str) ;
}
#endif
int32 entero,voltaje;
float32 temp;
char str[16];
void relay(uint32_t time)
{
switch(time) {
case 0: // at 0sec
Test_Tube_Write(0);
print("\tTest_Tube_Write(0)\n") ;
break ;
case 3000: // at 3sec
Sample_Write(0);
print("\tSample_Write(0)\n") ;
break ;
case 8000: // at 8sec
Molish_Write(0);
print("\tMolish_Write(0)\n") ;
break ;
case 10000: // at 10sec
Sample_Write(1);
print("\tSample_Write(1)\n") ;
Test_Tube_Write(1);
print("\tTest_Tube_Write(1)\n") ;
break ;
case 19000: // at 19sec
Molish_Write(0);
print("\tMolish_Write(0)\n") ;
break ;
}
}
void measure(uint32_t time)
{
if (time % 1000) { // measure only each 1sec => ((time % 1000) == 0)
return ;
}
/*SENSOR LM35*/
ADC_StartConvert();
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
entero = ADC_GetResult32();
ADC_StopConvert();
voltaje = ADC_CountsTo_mVolts(entero);
temp = ((voltaje/10.00)-07.00);
sprintf(str,"%.1f",temp);
#if USE_UART
print("Temp:") ;
print(str) ;
print("\n") ;
#else
LCD_I2C_setCursor(6,1);
LCD_I2C_print(str);
#endif
}
int main(void)
{
uint32_t time = 0 ;
uint32_t delta = 1 ; /* time resolution 1ms */
CyGlobalIntEnable;
I2C_Start();
#if USE_UART
UART_Start() ;
#else
LCD_I2C_start();
#endif
Opamp_Start();
ADC_Start();
#if USE_UART
// print("Temp:") ;
#else
LCD_I2C_setCursor(0,1);
LCD_I2C_print("Temp:");
#endif
for(;;)
{
relay(time);
measure(time) ; /* measure every 1sec */
time = (time + delta) % 31000 ; /* 0 ~ 30999 = 31 sec cycle */
CyDelay(delta) ;
}
}
===============================
And the TeraTerm log was something like
Attached is my test project done with PSoC Creator v4.2.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
Thank you very much, you helped me to fix those errors that I had, thanks for your contribution.