use rtc_ticks to trigger actions
This commit is contained in:
parent
f16994617c
commit
0a12fc9cf0
31
main.c
31
main.c
@ -48,7 +48,6 @@
|
||||
* @{
|
||||
*/
|
||||
volatile bool button_flag = false; /**< flag set when board user button has been pressed/released */
|
||||
volatile bool time_flag = false; /**< flag set when time changed */
|
||||
volatile bool photoresistor_flag = false; /**< flag set when ambient luminosity is measured */
|
||||
/** @} */
|
||||
|
||||
@ -57,8 +56,8 @@ volatile bool photoresistor_flag = false; /**< flag set when ambient luminosity
|
||||
* @note I have to use type variables because defines would be stored in signed integers, leading to an overflow it later calculations
|
||||
* @{
|
||||
*/
|
||||
/** the number of ticks in one second (a divisor of 32768 greater than 256*WS2812B_LEDS/60) */
|
||||
#define TICKS_PER_SECOND 256
|
||||
/** the number of ticks in one second (greater than 256*WS2812B_LEDS/60) */
|
||||
#define TICKS_PER_SECOND SQUARE_WAVE_FREQUENCY/SQUARE_WAVE_TICKS
|
||||
/** number of ticks in one second */
|
||||
const uint32_t ticks_second = TICKS_PER_SECOND;
|
||||
/** number of ticks in one minute */
|
||||
@ -371,8 +370,6 @@ int main(void)
|
||||
|
||||
// setup internal RTC
|
||||
rtc_auto_awake(RCC_LSE, 32768/ticks_second-1); // ensure RTC is on, uses the 32.678 kHz LSE, and the prescale is set to our tick speed, else update backup registers accordingly (power off the micro-controller for the change to take effect)
|
||||
rtc_interrupt_enable(RTC_SEC); // enable RTC interrupt on "seconds"
|
||||
nvic_enable_irq(NVIC_RTC_IRQ); // allow the RTC to interrupt
|
||||
|
||||
// setup external RTC
|
||||
rtc_setup(); // setup RTC module
|
||||
@ -479,27 +476,22 @@ int main(void)
|
||||
while (rtc_tick_flag) { // the RTC tick four our counter passed
|
||||
rtc_tick_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
led_toggle();
|
||||
}
|
||||
while (time_flag) { // time passed
|
||||
time_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
if ((rtc_get_counter_val()%(ticks_second/10))==0) { // one tenth of a second passed
|
||||
if ((rtc_ticks%(ticks_second/10))==0) { // one tenth of a second passed
|
||||
adc_start_conversion_regular(ADC1); // start measuring ambient luminosity
|
||||
}
|
||||
if ((rtc_get_counter_val()%ticks_second)==0) { // one second passed
|
||||
if ((rtc_ticks%ticks_second)==0) { // one second passed
|
||||
//led_toggle(); // don't use the LED, this confuses the 32.768 kHz oscillator
|
||||
}
|
||||
if ((rtc_get_counter_val()%ticks_minute)==0) { // one minute passed
|
||||
if ((rtc_ticks%ticks_minute)==0) { // one minute passed
|
||||
printf("%02lu:%02lu:%02lu\n", rtc_get_counter_val()/ticks_hour, (rtc_get_counter_val()%ticks_hour)/ticks_minute, (rtc_get_counter_val()%ticks_minute)/ticks_second); // display time
|
||||
}
|
||||
if ((rtc_get_counter_val()%ticks_hour)==0) { // one hours passed
|
||||
if ((rtc_ticks%ticks_hour)==0) { // one hours passed
|
||||
clock_hours(); // show hour markers
|
||||
}
|
||||
if (rtc_get_counter_val()>=ticks_midday*2) { // one day passed
|
||||
if (rtc_ticks>=ticks_midday*2) { // one day passed
|
||||
rtc_set_counter_val(rtc_get_counter_val()%ticks_midday); // reset time counter
|
||||
}
|
||||
clock_set_time(rtc_get_counter_val()); // set time
|
||||
clock_set_time(rtc_ticks); // set time
|
||||
}
|
||||
while (photoresistor_flag) { // new photo-resistor value has been measured
|
||||
photoresistor_flag = false; // reset flag
|
||||
@ -535,13 +527,6 @@ void BUTTON_ISR(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @brief interrupt service routine called when tick passed on RTC */
|
||||
void rtc_isr(void)
|
||||
{
|
||||
rtc_clear_flag(RTC_SEC); // clear flag
|
||||
time_flag = true; // notify to show new time
|
||||
}
|
||||
|
||||
/** @brief interrupt service routine called when ADC conversion completed */
|
||||
void adc1_2_isr(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user