Blog List:
Garbage Collector #1 Introduction
Garbage Collector #2 Clamp testing
Garbage Collector #3 Seeking help from Infineon's Technical Supports
Garbage Collector #4 Some basic interactions with the shields
Garbage Collector #5 Base testing
Garbage Collector #6 Wireless Controller
Garbage Collector #7 Clamp and Base
Garbage Collector #8 Clamp Improvement
Garbage Collector #9 Doubling the maximum current
Garbage Collector #10 Summary
Hello guys, in this blog I will write about putting the base and clamp together and control them wirelessly.
In my previous blog, I have successfully control the base as well as clamp separately. However, when I put them all together, I have noticed that I will need too much of Interrupt pins ( an interrupt pin for each particular action ). Therefore, I have decided to do some improvement on my coding so that I can use fewer interrupt pins.
Since the "forward", "backward", "left", and "right" instructions are mutually exclusive, the solution that I can think of is that instead of using separate interrupt pins for "forward", "backward", "left", and "right", I will be sending a bus data from NodeMCU to the XMC4700 telling it that which direction should it go, then I can only use 1 interrupt for all of them.
For Example:
DIRECTION_Bus_IO [1:0] | Direction |
---|---|
00 | Forward |
01 | Backward |
10 | Left |
11 | Right |
Similarly:
CLAMP_Bus_IO [1:0] | Actions |
---|---|
00 | clamp up |
01 | clamp down |
10 | clamp open |
11 | clamp close |
The table below compares the pin count for the previous case and the new case:
Previous Interrupt | Previous GPIO | New Interrupt | New GPIO | |
---|---|---|---|---|
FORWARD | DIRECTION | DIRECTION_Bus_IO [0] | ||
FORWARD | CLAMP | DIRECTION_Bus_IO [1] | ||
LEFT | CLAMP_Bus_IO [0] | |||
RIGHT | CLAMP_Bus_IO [1] | |||
CLAMP UP | ||||
CLAMP DOWN | ||||
CLAMP OPEN | ||||
CLAMP CLOSE | ||||
Total | 8 | 0 | 2 | 4 |
Previous Case Total pins | 8 | New Case Total pins | 6 |
Using the new method not only reduces the interrupts pins but also decreases the total pins needed. The only thing I will have to sacrifice is that I can't give the instructions that use the same interrupt at the same time. Since I know that they are all mutually exclusive, that will do no harm to me and I'm literally sacrificing nothing and reduced the interrupt pin count as well as the total pin count.
As for the coding part, I have added 2 new FreeRTOS task to check the respective BUS_IO and call out the intended task:
void DIRECTION_Task(void *p){ while(1){ if (xSemaphoreTake(DIRECTION_interruptSemaphore, portMAX_DELAY) == pdPASS){ direction_status = BUS_IO_Read(&DIRECTION_BUS_IO); switch(direction_status){ case 0: xSemaphoreGiveFromISR(FORWARD_interruptSemaphore, NULL); break; case 1: xSemaphoreGiveFromISR(BACKWARD_interruptSemaphore, NULL); break; case 2: xSemaphoreGiveFromISR(LEFT_interruptSemaphore, NULL); break; case 3: xSemaphoreGiveFromISR(RIGHT_interruptSemaphore, NULL); break; } } } } void CLAMP_Task(void *p){ while(1){ if (xSemaphoreTake(CLAMP_interruptSemaphore, portMAX_DELAY) == pdPASS){ clamp_status = BUS_IO_Read(&CLAMP_BUS_IO); switch(clamp_status){ case 0: xSemaphoreGiveFromISR(UP_interruptSemaphore, NULL); break; case 1: xSemaphoreGiveFromISR(DOWN_interruptSemaphore, NULL); break; case 2: xSemaphoreGiveFromISR(OPEN_interruptSemaphore, NULL); break; case 3: xSemaphoreGiveFromISR(CLOSE_interruptSemaphore, NULL); break; } } } }
Under normal circumstances, the CLAMP_Task and DIRECTION_Task will not run since the respective semaphore are not available. When Interrupt occurs, the IRQ_Handler will give the respective semaphore so that the DIRECTION_Task or the CLAMP_task can in return give semaphore for the respective task based on the inputs in the BUS_IO.
Below are the codes for the IRQ_Handler:
void DIRECTION_IRQHandler(void){ xSemaphoreGiveFromISR(DIRECTION_interruptSemaphore, NULL); } void CLAMP_IRQHandler(void){ xSemaphoreGiveFromISR(CLAMP_interruptSemaphore, NULL); }
The project file can be cloned through the following Github link:
https://github.com/wanfp97/GarbageCollector
I have also uploaded the updated version of the Controller.ino file on the Github so that you guys can upload it to the NodeMCU.
The mobile application used to control the Garbage Collector has not been changed so the mobile application in the previous blog post can be used.
Putting the base and the clamp together:
Adding BMS module for balanced charging and discharge purpose:
I have soldered HX-2S-D20 BMS module and a switch to control the charging and discharging of the batteries.
I have uploaded everything to their respective Kit and below is the test
The Clamp is still not strong enough and there is some jitter on the servo. Hopefully, I can find a solution for these and update it in my next blog.
That's all for this blog, see you next blog.
Top Comments