Sleep after 5s of no RxMsg

Programmable 6-channel router and data logger for CAN and CAN FD with I/O and optional Ethernet interface
ln.brnds
Posts: 5
Joined: Tue 19. Dec 2023, 13:37

Sleep after 5s of no RxMsg

Post by ln.brnds » Tue 19. Dec 2023, 13:41

I want to shutdown the PCAN Router Pro FD after 5 seconds recieving no RxMsg. It is essential to have the possibility to wake it up when a new message is recieved. Can you give me a c-code example or a guide how to implement such thing?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Sleep after 5s of no RxMsg

Post by PEAK-Support » Wed 20. Dec 2023, 08:01

in the hardware.c you find a function

Code: Select all

//! @brief      enter power down
//!             we will enter power down by removing conditions forcing the
//!             power supply to work. You have to remove the external wake-IN
//!             condition (e.g. terminal 15) too. Otherwise the supply will stay
//!             active.
void  HW_EnterPowerDown ( void)
{
    ...

	// put all CANs into sleep.
	// Only affecting wake-up capable PHYs like TJA1043.
    .......
}
call this when you like to put the device to sleep mode. Keep in mind that the physical Wake Up Pin (Pin 1 - next to the Supply Pin) must be disconnect at this time!
Per default the device come with a NXP TJA1043 CAN transceiver with wake-up function. Other Transceiver Types are possible - see matrix
As we have all functions as source code in our sample projects, you also could disable the wake up for some CAN Channels - see code - all is explained in the code itself.

The first received CAN Frame, which "wake up" the system will not be received as CAN Data.
If you need to "clean up" something before you shut down the device, call the "HW_DIS_SELFHOLD" after this is done in your main.c (do not forget to remove the line from hardware.c)
WakeUp_CAN.png
WakeUp_CAN.png (50.67 KiB) Viewed 4844 times
To call this function after 5 seconds of the last received CAN Frame, simply use a timer function to compare if the last message is older as the 5 seconds. (using SYSTIME_NOW )
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

ln.brnds
Posts: 5
Joined: Tue 19. Dec 2023, 13:37

Re: Sleep after 5s of no RxMsg

Post by ln.brnds » Tue 9. Jan 2024, 09:49

Thanks, that helped so far.

Now I want to wake up the Router again but when theres a Message on CAN 3 or 4. Do I also have to put them to sleep? With this configuration the router does NOT wake up anymore. I've looked inside and on the transmitters theres the text FD-1043 WU printed. I think that these ones are the Wake-Up capable PCAN transceivers TJA1043?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Sleep after 5s of no RxMsg

Post by PEAK-Support » Tue 9. Jan 2024, 12:49

The Device will be wake up again when receiving a single CAN Frame on any of the used CAN Ports.
This first message is only for wake up, and could not be received as a real CAN-Frame.

The default CAN Transceivers (if you did not order other Transceivers) are the TJA1034, which are able to bring back the Device to work.

As we do not know your code and also do not know the complete setup, incl. how you use the Wake Up Pin on the power connector, we could not give you a answer why your device do not wake up again.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

ln.brnds
Posts: 5
Joined: Tue 19. Dec 2023, 13:37

Re: Sleep after 5s of no RxMsg

Post by ln.brnds » Tue 9. Jan 2024, 13:35

I now have firgured out, that the Power-LED does not turn off. I think the transcievers are in Sleep-Mode but the router isn't. I just use the predefined function to put the router to sleep mode. The Wake-Up-Pin on the phoenix connector is not connected at any time.
Can you tell me the expected behaviour when the device wakes up again? Does the program restart from the very beginning?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Sleep after 5s of no RxMsg

Post by PEAK-Support » Wed 10. Jan 2024, 08:15

You need to call the HW_EnterPowerDown(); from hardware.c , clean up what you need to do (or do nothing) and then call the macro HW_DIS_SELFHOLD;
Look like you did not call this ! It is the needed part to cut the selfhold line in the supply for the CPU board.
After that all LEDs are of and only a minimum part of the supply board is working and could detect if one CAN Interface have received a Frame. Then it will be wake up the complete Device again.
As i wrote - you never send your real setup or your used code - without information it is hard to find what you missed.
Check the code that i have sent in one of my last posts that is all you need to do - do not change any other settings in hardware.c. Only REMARK the last Line so that you could call the selfhold in our main file:
WakeUp_CAN2.png
WakeUp_CAN2.png (76.86 KiB) Viewed 4434 times
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

ln.brnds
Posts: 5
Joined: Tue 19. Dec 2023, 13:37

Re: Sleep after 5s of no RxMsg

Post by ln.brnds » Wed 10. Jan 2024, 09:22

I do have activated the Macro to disable Selfhold as i do not have manipulated the hardware.c file. I call the HW_EnterPowerDown method from an timer as a callback-function. as shown below.
Screenshot 2024-01-10 091943.png
Screenshot 2024-01-10 091943.png (9.01 KiB) Viewed 4432 times
Maybe the Timer is the Problem?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Sleep after 5s of no RxMsg

Post by PEAK-Support » Wed 10. Jan 2024, 09:25

Attached a sample project that works - please check if your sleep / wake up problem is solved
But the sample use no timer - if it works as expected, also on your system, we need to go deeper into the the timer problem
Attachments
Sleep_Mode-CAN_WakeUp.zip
(7.31 KiB) Downloaded 498 times
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Sleep after 5s of no RxMsg

Post by PEAK-Support » Wed 10. Jan 2024, 12:15

Here a sample how to use the Timer with Power Down Option

Code: Select all

// count val in milliseconds
uint32_t   pwr_down_count_ms =5000;

// callback every 1 millisecond
static void  pwr_down_callback ( void *argument)
{
    if ( pwr_down_count_ms) {
        pwr_down_count_ms -= 1;
        if ( pwr_down_count_ms == 0) {
            HW_EnterPowerDown();
        }
    }
}

// main or thread
int  main_or_thread ( void *arg)
{
    thandle = osTimerNew ( &pwr_down_callback, osTimerPeriodic, NULL, NULL);
    ...
    osTimerStart ( thandle, MY_PERIOD_MS);
}
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

ln.brnds
Posts: 5
Joined: Tue 19. Dec 2023, 13:37

Re: Sleep after 5s of no RxMsg

Post by ln.brnds » Thu 11. Jan 2024, 07:53

Thank you so much. I think the use of the Timer was the issue. I think i just started the Sleep too early and one of the CANs was still active. I now managed to enable the sleep-mode this way:
Screenshot 2024-01-11 075252.png
Screenshot 2024-01-11 075252.png (27.17 KiB) Viewed 4414 times
The function time_routines is called every cycle in my while(true) at the beginning.

Locked