Sleep after 5s of no RxMsg
Sleep after 5s of no RxMsg
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?
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Sleep after 5s of no RxMsg
in the hardware.c you find a function
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)
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 )
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.
.......
}
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)
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
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: Sleep after 5s of no RxMsg
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?
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?
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Sleep after 5s of no RxMsg
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.
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
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: Sleep after 5s of no RxMsg
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?
Can you tell me the expected behaviour when the device wakes up again? Does the program restart from the very beginning?
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Sleep after 5s of no RxMsg
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:
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:
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: Sleep after 5s of no RxMsg
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.
Maybe the Timer is the Problem?- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Sleep after 5s of no RxMsg
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
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
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Sleep after 5s of no RxMsg
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
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: Sleep after 5s of no RxMsg
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:
The function time_routines is called every cycle in my while(true) at the beginning.