stm32 rtc how to set timer alarm not time and date alarm - stm32

I'm using Stm32f101vbt6 i want to set rtc alarm every 25 second.because i want to wake up microcontroller from stop mode to reset the watchdog.
in HAL libraries i can set rtc alarm by this command:
HAL_RTC_SetAlarm_IT(&hrtc, &RTC_Alarm_Time, RTC_FORMAT_BIN);
but for this command i have to get time from rtc which is hour min and sec and calculate 25 second after and then write the command above.
what should i do if i don't want to calculate time each time and set rtc alarm just by adding numbers to RTC alarm register.
Thank you.

Related

How to reset time for data logging in micro:bit micropython

I would like to start data logging in a bbc micro:bit with the press of its button_a, in order to be able to synchronize the timestamps with an external clock.
The idea is that, if I press the button at 12:10 o'clock, I would know that the first row of data (with 0.00 timestamp) was taken at that time (+/- human reaction time, of course).
The problem is that the zero time of the timestamps begin when the bbc micro:bit is turn on (or reset); so the first timestamp in the log file is not 0.00.
Of course, I could synchronize with that turning-on, but I think it would not be that accurate (I'm using the micro:bit with a robotbit board, which has a big 'on-off' switch.)
What I would like would be some kind of reset_time() method. :)
The code is this:
from microbit import *
import log
log.set_labels('altitude', 'azimuth', 'measure', timestamp=log.SECONDS)
# Wait until Button 'A' is pressed. This way, we can sinchronize the measures with an external clock or watch
while not button_a.was_pressed():
pass
for altitude in...
for azimuth in...
measure=take_reading()
log.add({
'altitude': altitude,
'azimuth': azimuth,
'measure': measure
})
The full code is here: https://github.com/lopezsolerluis/foto-teodolito-log

Auto shut down for KDB instance

I am trying to set an auto shutdown on a KDB instance 24 hours after the launch.
I have been playing around with the .z.exit and \t but could not figure it out.
You need to set the timer function .z.ts (https://code.kx.com/q/ref/dotz/#zts-timer) which is triggered at each interval set by \t to terminate the q process using exit (https://code.kx.com/q/ref/exit/), e.g.
q) set timer to 24 hours (milliseconds)
q)\t 24*60*60*1000
q).z.ts:{exit 0}
On startup you could define your start time, then set a timer to check if the current time is 24 hours later and then exit.
startTime:.z.P;
.z.exit:{"Whatever you want to happen on exit"};
.z.ts:{if[1D<.z.P-startTime;exit 0]};
system"t 60000"; /set timer to whatever frequency

Calculate the time available in the service block in anylogic

Hi working on Production Model where I am working in shifts( 8:00AM to 4:30PM) and the requirement is that work should be done in one shift only otherwise shift it to next day. so for example lets say my agent enter the service block at 4:00 PM and shift end at 4:30 PM, the average time require to complete this task is 3hours, What I want to do is to check the available time and if time is not sufficient ( like in this case i have only 30 mins) the agent should be sent to waiting area and next day service block should start working on that agent first.
One way: Add A SelectOutput block ahead of the Service. In the condition, check
mySchedule.getTimeOfNextValue() - time() > x
Where x is the remaining time window you allow, i.e. the task duration the agent will require once entering the servive.
If there is not enough x left, you send the agent to some Wait block, else they are allowed to enter
PS: Also check the other functions that Schedule allows, might be you need some of them. Always check all capabilities a block offers you via code-complete (ctrl+space or Option+space on Mac)

How do I use system time as a trigger in codesys ladder?

Programming a raspberry pi with codesys, using mostly ladder, basically I need to write all data that is currently in a couple arrays to a csv file at midnight, so i'd like to be able to use a dt value as a trigger. I can't figure out how to use that value in ladder, however. I can display the local time on visualizer, but if i wanted something like "if localTime=#value" then coil 'Write' turns on, where is the actual variable for system time?
As far as I know, you need to read the clock from local system using function blocks, for example GetDateAndTime from CAA DTUtil Extern Library. Then you need to keep it up-to-date by using a function block, for example RTC from Standard libary
The following reads the system local time and then updates it with a RTC function block. Works at least on Windows, couldn't test with Raspberry. Please note that if the local time changes for some reason, this won't update it again. So you need to run the GetDateAndTime call every now and then, for example.
First, a program that updates and provides the local time:
PROGRAM PRG_UpdateSystemTime
VAR_OUTPUT
SystemDateTime : DT;
END_VAR
VAR
ReadLocalTime : DTU.GetDateAndTime; //Reads local time from system
RtcBlock : RTC; //Real-time clock - updates the previously received local time
END_VAR
//NOTE: Output is UTC time
//The block that reads local time. NOTE: Error handling is missing
ReadLocalTime(xExecute:= TRUE);
//Running real-time clock
RtcBlock(
EN := ReadLocalTime.xDone AND NOT ReadLocalTime.xError,
PDT := ReadLocalTime.dtDateAndTime,
CDT => SystemDateTime
);
And then one example for ladder. I think there are millions of ways. Note that the "DoSomething" will be TRUE for the whole second, so you should probably use rising edge detection.

JDY-08 w/HM10 firmware won't change any parameters

I have a custom circuit with STM32F030F4P6 as a main controller and HDY-08 flashed with HM-10 firmware as a Bluetooth LE transmitter.
What I wanted to do on circuit power on is to manually set the module up with custom parameters (name, baud, mode) and then proceed to the main calculating part.
However, what I noticed is that module won't act after any of the AT commands received, though it responds with OK+... strings.
For example, I send "AT+NAMEmyname" and receive "OK+Set:myname", however, the name doesn't change at all and remains HMSoft in Bluetooth scan on my phone.
Being on baudrate of 9600 I send "AT+BAUD4" and receive "OK+Set:4", then I send "AT+BAUD?" STILL on the baud of 9600 and receive the same: "OK+BAUD4" - the module keeps working on 9600, however, says it is on 115200. Tried playing with pulling reset and sys_key up and down for different time intervals, which results in nothing but not working AT commands.
Currently I have my module with RESET pin pulled up and SYS_KEY pulled up for 1200 milliseconds at start, then it is pulled down and then I proceed to send AT commands with delays of 250 milliseconds between Transmitting/Receiving sessions:
HAL_GPIO_WritePin(SYSTEM_KEY_GPIO_Port, SYSTEM_KEY_Pin, 1);
HAL_Delay(1200);
HAL_GPIO_WritePin(SYSTEM_KEY_GPIO_Port, SYSTEM_KEY_Pin, 0);
HAL_UART_Transmit(&huart1, (uint8_t*)setup, 8, 100);
HAL_UART_Receive(&huart1, (uint8_t*)response, 8, 100);
HAL_Delay(250);
HAL_UART_Transmit(&huart1, (uint8_t*)reset, 8, 100);
HAL_UART_Receive(&huart1, (uint8_t*)response2, 8, 100);
HAL_Delay(250);
HAL_UART_Transmit(&huart1, (uint8_t*)check, 8, 100);
HAL_UART_Receive(&huart1, (uint8_t*)response3, 8, 100);
The problem was solved:
I don't know why, but after several times of dragging the same code here and there, I got the working solution:
RESET Pin 1
SYSTEM_KEY Pin 1
PWR 1
SYSTEM_KEY Pin 0
Delay 1200 millis
SYSTEM_KEY Pin 1
AT+BAUD4 -> OK+Set:4
Delay 250 millis
Reinitialize UART on STM, now with baudrate of 115200
AT+BAUD? -> OK+Get:4
It works, data flows as needed.
Thank you me for answering <3