TA的每日心情 | 慵懒 2016-12-6 21:26 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
|
发表于 2016-12-6 13:58:13
|
显示全部楼层
网上对STM32F10X系列的RTC时钟有不少的议论,都觉得很不准确。有空做了一下试验,觉得还不错。下面先上程序,请各位不吝赐教。
//Analog Input speed test (STM32F103C8T6 AD RTC.ino)
#include <RTClock.h>
#define LED_PIN PC13
RTClock rt (RTCSEL_HSE); //RTClock rt (RTCSEL_LSE);
int i=0,THH,TMM,TSS;
int sensorPin0 = 0,sensorValue0;//
int sensorPin1 = 1,sensorValue1;
int sensorPin2 = 2,sensorValue2;
long TimeVar;
void blink () {
digitalWrite(LED_PIN,!digitalRead(LED_PIN));
//RTC_GetCounter() % 86400;
TimeVar=rt.getTime();
if (TimeVar>86399){rtc_set_count(0);}
THH = TimeVar / 3600;// Compute hours
TMM = TimeVar / 60;
while (TMM>59){TMM=TMM-60;}// Compute minutes
TSS = TimeVar % 60; // Compute seconds
Serial.print(THH);Serial.print(":");
Serial.print(TMM);Serial.print(":");
Serial.print(TSS);Serial.print(" ");
Serial.print(sensorValue0);Serial.print(" ");
Serial.print(sensorValue1);Serial.print(" ");
Serial.print(sensorValue2);Serial.print(" ");
Serial.println(i);
i=0;
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
//pinMode(sensorPin0, INPUT_ANALOG);
//pinMode(sensorPin1, INPUT_ANALOG);
//pinMode(sensorPin2, INPUT_ANALOG);
rtc_set_prescaler_load(62500); //rtc_set_prescaler_load(32768);
rtc_set_count(43199);//11:59:59
rt.attachSecondsInterrupt(blink);
Serial.println("start");
}
void loop() {
sensorValue0=analogRead(sensorPin0);
sensorValue1=analogRead(sensorPin1);
sensorValue2=analogRead(sensorPin2);
i=i+1;
}
程序里顺便把AD的读取速度测了。我用的是8M晶振分频方式,也可用32768晶振。原板上的晶振有问题,已换掉了。 |
|