don't have the LED blink, this distrubs the oscillator

This commit is contained in:
King Kévin 2016-04-16 11:33:16 +02:00
parent bc7191e2af
commit 63c17af691
2 changed files with 19 additions and 23 deletions

View File

@ -55,6 +55,7 @@ Connect one leg of a 1 kOhm resistor to ADC channel 0 on pin PA0 and the other t
This voltage divider allows to measure the photo-sensor's resistance and determine the luminance.
If you don't want to use this feature, connect PA1 to ground for the highest brightness or Vcc for the lowest brightness.
The blue pill has a 32.768 kHz oscillator for the internal RTC, but don't use the LED next to it as it disturbs the oscillator and the time won't stay right.
If the board does not provide a 32.768 kHz oscillator for the internal RTC it is also possible to use an external RTC such as the Maxim DS1307.
The time is then read over I2C and incremented using the square wave output.
A working example code is under the `DS1307_4096Hz_timer` tag, but needs to be integrated in the latest code state.

41
main.c
View File

@ -420,33 +420,28 @@ int main(void)
if (battery_voltage<1.0) {
printf("no battery detected\n");
} else {
if (battery_voltage<2.4) {
if (battery_voltage<2.4) { // low battery voltage
printf("/!\\ low ");
for (uint16_t led=0; led<2; led++) { // display red on 2 LEDs
clock_leds[led*3+0] = 0xff; // set red
}
} else if (battery_voltage>3.0) { // battery full
for (uint16_t led=0; led<WS2812B_LEDS; led++) { // display green on all LEDs
clock_leds[led*3+1] = 0xff; // set green
}
} else { // intermediate batter voltage
for (uint16_t led=0; led<(uint8_t)(WS2812B_LEDS*(battery_voltage-2.4)/0.6); led++) { // display blue on proportional LEDs
clock_leds[led*3+2] = 0xff; // set blue
}
}
printf("battery voltage: %.2fV\n", battery_voltage);
clock_leds_set(); // set the colors of all LEDs
ws2812b_transmit(); // transmit set color
for (uint32_t i=0; i<10000000; i++) { // display for a small while
__asm__("nop");
}
}
// show voltage on LEDs
if (battery_voltage<1.0) { // battery probable not connected
} else if (battery_voltage<2.4) { // low battery voltage
for (uint16_t led=0; led<2; led++) { // display red on 2 LEDs
clock_leds[led*3+0] = 0xff; // set red
}
} else if (battery_voltage>3.0) { // battery full
for (uint16_t led=0; led<WS2812B_LEDS; led++) { // display green on all LEDs
clock_leds[led*3+1] = 0xff; // set green
}
} else { // intermediate batter voltage
for (uint16_t led=0; led<(uint8_t)(WS2812B_LEDS*(battery_voltage-2.4)/0.6); led++) { // display blue on proportional LEDs
clock_leds[led*3+2] = 0xff; // set blue
}
}
clock_leds_set(); // set the colors of all LEDs
ws2812b_transmit(); // transmit set color
for (uint32_t i=0; i<10000000; i++) { // display for a small while
__asm__("nop");
}
// now use interrupts to only measure ambient luminosity
channels[0] = PHOTORESISTOR_ADC_CHANNEL; // only measure ambient luminosity
adc_set_regular_sequence(ADC1, 1, channels); // set now group
@ -504,7 +499,7 @@ int main(void)
adc_start_conversion_regular(ADC1); // start measuring ambient luminosity
}
if ((rtc_get_counter_val()%ticks_second)==0) { // one second passed
led_toggle(); // LED activity to show we are not stuck
//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
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