Control multiple device using Timer

Trupal
Posts: 19
Joined: Wed Aug 16, 2023 10:54 am

Control multiple device using Timer

Postby Trupal » Mon Sep 04, 2023 4:51 am

Hello ,

I have connected the IO expander (PI4IOE5V96248) with the ESP32 s3 by using the I2C protocol, and I have generated a pwm signal on the IO expander, but I cannot control the multiple devices at the same time. If I am on any bulb, and at the same time, if I am on another device, let’s say another bulb, then the first device is turned off and the new device is turned on.

So, how can I do that by using ESP32 Timer and one more thing I have 10 devices for the application.


Thank you

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Control multiple device using Timer

Postby ESP_Sprite » Mon Sep 04, 2023 6:14 am

Your code probably has a bug. Suggest you post that, at the very least; we don't have a crystal ball and as such can't divine what's wrong with your setup without it.

Trupal
Posts: 19
Joined: Wed Aug 16, 2023 10:54 am

Re: Control multiple device using Timer

Postby Trupal » Mon Sep 04, 2023 6:39 am

This is my files for project...


Thank you
Attachments
esp32idfDimmer.c
(10.22 KiB) Downloaded 201 times
main.c
(8.42 KiB) Downloaded 211 times
PI4IOE5V96248.c
(4.74 KiB) Downloaded 186 times

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Control multiple device using Timer

Postby ESP_Sprite » Mon Sep 04, 2023 12:27 pm

Question for you: How is the code supposed to remember the PWM value for channels other than the latest? Does it store that anywhere?

Trupal
Posts: 19
Joined: Wed Aug 16, 2023 10:54 am

Re: Control multiple device using Timer

Postby Trupal » Tue Sep 05, 2023 3:43 am

Yes this is stored in Power_buffer ,which is shown in main file I have attached

see this file please

thank you
Attachments
main.c
(9.66 KiB) Downloaded 479 times

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Control multiple device using Timer

Postby ESP_Sprite » Tue Sep 05, 2023 4:07 am

Okay. That is an entirely different version of the code than you attached previously. Sorry, but I'm not gonna help you debug a moving target.

I'm not gonna lie: your code is a bit of a mess and it's a bit hard to figure out what you *intend* it to do, rather than what it actually does. What I'd suggest you should do is to write out the architecture, as in how you envision it should work, somewhere. What are the interactions, what happens after what, which variables are involved etc. Then check if the code actually does that. For instance, I imagine that something is supposed to take ProcessSignal_on while another thing is supposed to give that semaphore. What actually does do the taking and what actually does do the giving in your code?

Trupal
Posts: 19
Joined: Wed Aug 16, 2023 10:54 am

Re: Control multiple device using Timer

Postby Trupal » Tue Sep 05, 2023 4:30 am

ESP_Sprite wrote:
Tue Sep 05, 2023 4:07 am
Okay. That is an entirely different version of the code than you attached previously. Sorry, but I'm not gonna help you debug a moving target.

I'm not gonna lie: your code is a bit of a mess and it's a bit hard to figure out what you *intend* it to do, rather than what it actually does. What I'd suggest you should do is to write out the architecture, as in how you envision it should work, somewhere. What are the interactions, what happens after what, which variables are involved etc. Then check if the code actually does that. For instance, I imagine that something is supposed to take ProcessSignal_on while another thing is supposed to give that semaphore. What actually does do the taking and what actually does do the giving in your code?
I will tell you all those things Firstly, I received channel and power from the UART (task) .After receive the channel and power I will change in the channel_buffer array which is initially -1 and call the Power function, in this I set the power with the respective channel by using the SetPower function. another thing I attached the ZCD with my controller so every Zero crossing It it generate the Interrupt and at that time I am doing Semaphore as a pdTrue (this thing is in esp32idfDimmer.c file) . Well in the main file when the Semaphore is taken by ProccessSignal_on and ProccessSignal_off Function I just doing HIGH and LOW by using writepin function which is basically set and Reset the IO expander Pin . but what happened is that When I turn on the 1st device with power let say 2 and at the same time If I turn on 2nd Device with another power then It is not happening (Like transfer the present Power to the all the Device).

So can I do this thing By using the Timer (esp_timer_start_periodic();) this API ? should I create 10 timer for each Channel ?and It is possible or not ?

thank you

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Control multiple device using Timer

Postby ESP_Sprite » Tue Sep 05, 2023 6:24 am

Okay, gotcha. So you're not trying to generate a PWM signal per se (which would be free-running), you're tyring to do phase control dimming (which is synced to the zero-crossing).

Yes, you could use ten ESP_Timers to do this. Note that your software can only process one timer at a time, though, so if multiple timers fire at or around the same time, they will still processed after eachother, meaning some will 'lag' a bit. If this lag is acceptable depends on your application, obviously.

Trupal
Posts: 19
Joined: Wed Aug 16, 2023 10:54 am

Re: Control multiple device using Timer

Postby Trupal » Tue Sep 05, 2023 6:45 am

Okay thank you !

One more thing how can I handle this I mean when Zero crossing Detector detect the Zero at that time I call the semaphore and Semaphore is taken by my task so can you please tell me that where I can Start my Timer of specific channel and Where I can Stop my timer ?

Thank you

Trupal
Posts: 19
Joined: Wed Aug 16, 2023 10:54 am

Re: Control multiple device using Timer

Postby Trupal » Tue Sep 05, 2023 6:48 am

ESP_Sprite wrote:
Tue Sep 05, 2023 6:24 am
Okay, gotcha. So you're not trying to generate a PWM signal per se (which would be free-running), you're tyring to do phase control dimming (which is synced to the zero-crossing).

Yes, you could use ten ESP_Timers to do this. Note that your software can only process one timer at a time, though, so if multiple timers fire at or around the same time, they will still processed after eachother, meaning some will 'lag' a bit. If this lag is acceptable depends on your application, obviously.
I can not call esp_timer_start_periodic(); function in my Task So where It will be called?

Who is online

Users browsing this forum: forrest, Google [Bot] and 92 guests