fix not precise second issue

This commit is contained in:
King Kévin 2016-04-11 22:05:17 +02:00
parent ae6037e5ca
commit 1afcc94011
1 changed files with 3 additions and 4 deletions

7
main.c
View File

@ -57,8 +57,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 (depend on the number of LED since it tries to have 255 tick per LED per second) */
#define TICKS_PER_SECOND 256*WS2812B_LEDS/60
/** the number of ticks in one second (a powe or 2 > 256*WS2812B_LEDS/60) */
#define TICKS_PER_SECOND 256
/** number of ticks in one second */
const uint32_t ticks_second = TICKS_PER_SECOND;
/** number of ticks in one minute */
@ -371,7 +371,7 @@ int main(void)
#endif
// setup 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
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
@ -502,7 +502,6 @@ int main(void)
adc_start_conversion_regular(ADC1); // start measuring ambient luminosity
}
if ((rtc_get_counter_val()%ticks_second)==0) { // one second passed
//printf("ticks: %lu\n", rtc_get_counter_val());
led_toggle(); // LED activity to show we are not stuck
}
if ((rtc_get_counter_val()%ticks_minute)==0) { // one minute passed