Consider the motor control conditions!

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Communication
Level 5
Level 5
100 replies posted First solution authored 250 sign-ins

Hello!
I'm doing a project in which I read the sensors and compare it with the value I set earlier to control the motor!
However, it doesn't work again. I create conditions like the image below. I initialized P10_6 in the main part

Communication_0-1684058065600.png

Communication_1-1684058127173.png

It doesn't work. I tried concatenating all the code in #2 together into a separate subroutine but it still doesn't work! Please someone help me! It's very important to me right now! It determined my graduation decision!
Thank you!

 

0 Likes
1 Solution

Hello @Communication ,

Based on your truth table, your code was still not match with that.
You only need to use OR logic for your conditions. No need to use multiple tasks.

For your reference, you can learn on:
https://www.allaboutcircuits.com/textbook/digital/chpt-7/converting-truth-tables-boolean-expressions...
and
https://www.electronics-tutorials.ws/boolean/bool_6.html

If you still confused, please feel free to ask. 🙂

Best regards,
Muhammad Nanda

View solution in original post

0 Likes
11 Replies
MuhammadNanda_K
Moderator
Moderator
Moderator
250 sign-ins 250 replies posted 50 likes received

Hello @Communication,

Can you print the value of temperature, humidity and ADC ?
I suspect that the values make cancellation each other since the same GPIO will be written.

Also, can you provide sample data for your test case like:
Value Temperature = a, Humidity = b --> rotate the motor.
Value Temperature = c, Humidity = d --> stop the motor.
etc.
?
Sample values will be good for us to analyze that.

Best regards,
Muhammad Nanda

I could in the value of all external sensors

I have tried putting them in the same program instead of separating them into separate programs, however they just turn on the engine and nothing next!

0 Likes

I am sorry @Communication,

Can you put some debug print to see which task currently running like:

void control_task(void *pvParam)
{
	for(;;)
	{
		ulTaskNotifyTake(pdTRUE, portMAX_DELAY)
		
		DBG_PRINTF("Temperature = %f\r\n", notify_temperature);
		if(notify_temperature < 35)
		{
			DBG_PRINTF("Temperature < 35\r\n");
			cyhal_gpio_write(P10_6, true);
			DBG_PRINTF("TURN ON MOTOR with temperature condition\r\n");
		}
		else
		{
			DBG_PRINTF("Temperature >= 35\r\n");
			cyhal_gpio_write(P10_6, false);
			DBG_PRINTF("turn OFF motor...., in temperature condition\r\n");
		}
		
		vTaskDelay(pdMS_TO_TICKS(200));
	}
}

Do that in all your conditions.

Also do you have data reference (expected output) for all your conditions (temperature, humidity and ADC percentage) together e.g.:

Temperature > 35 Humidity < 60 ADC < 50% Engine
FALSE FALSE FALSE OFF / ON  ??
FALSE FALSE TRUE OFF / ON  ??
FALSE TRUE FALSE OFF / ON  ??
FALSE TRUE TRUE OFF / ON  ??
TRUE FALSE FALSE OFF / ON  ??
TRUE FALSE TRUE OFF / ON  ??
TRUE TRUE FALSE OFF / ON  ??
TRUE TRUE TRUE OFF / ON  ??


You can complete ON or OFF (choose one) in Engine column on the table.
After you have the table, you can modify your condition in your code to make it follow the expected output on the table.

Please inform your workaround after this.

Thank you and regards,
Muhammad Nanda

0 Likes

I will try to break all my conditions into 1 program! and try removing the error as you suggested!

Nhiệt độ > 35 Độ ẩm < 60 ADC < 50% Động cơ
SAI SAI SAI TẮT
SAI SAI ĐÚNG VẬY MỞ
SAI ĐÚNG VẬY SAI MỞ
SAI ĐÚNG VẬY ĐÚNG VẬY MỞ
ĐÚNG VẬY SAI SAI MỞ
ĐÚNG VẬY SAI ĐÚNG VẬY MỞ
ĐÚNG VẬY ĐÚNG VẬY SAI MỞ
ĐÚNG VẬY ĐÚNG VẬY ĐÚNG VẬY MỞ

I did as the table gave but to no avail. We are not done a condition.

I tried to get past them to be a single program but the condition just activates the engine and then does nothing.
Thanks!

0 Likes

Hello @Communication,

I am sorry, your table output converted to non English:

nandax_0-1684166028065.png

 

Can you check again, so I can read better. 🙂

Thank you and regards,
Muhammad Nanda

0 Likes

Oh sorry! I forgot about the language check! I'm sorry!

Temperature > 35 Humidity < 60 ADC < 50% Engine
FALSE FALSE FALSE OFF
FALSE FALSE TRUE ON
FALSE TRUE FALSE ON
FALSE TRUE TRUE ON
TRUE FALSE FALSE ON
TRUE FALSE TRUE ON
TRUE TRUE FALSE ON
TRUE TRUE TRUE ON
0 Likes

Hello @Communication ,

Based on your truth table, your code was still not match with that.
You only need to use OR logic for your conditions. No need to use multiple tasks.

For your reference, you can learn on:
https://www.allaboutcircuits.com/textbook/digital/chpt-7/converting-truth-tables-boolean-expressions...
and
https://www.electronics-tutorials.ws/boolean/bool_6.html

If you still confused, please feel free to ask. 🙂

Best regards,
Muhammad Nanda

0 Likes

Thanks for supporting me!

0 Likes

You are welcome @Communication ,

Have you updating the code then see if it already meet your expectation or not ?
Or if you have different issue, you can also create new thread.

Best regards,
Muhammad Nanda

0 Likes

My problem is solved!
Thank you!

0 Likes

Glad to hear that!
I will lock this thread.

Any other issue, please do not hesitate to create new thread(s).

Best regards,
Muhammad Nanda