Browse Source

modified code for final test

stepper_dev
Gregor Wüst 3 years ago
parent
commit
dea148ebc1
1 changed files with 20 additions and 15 deletions
  1. 20
    15
      RTC/Core/Src/main.c

+ 20
- 15
RTC/Core/Src/main.c View File

int DaysInMonthLeapYear[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int DaysInMonthLeapYear[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool leapYear = false; bool leapYear = false;
int stepsFor180Deg = 1600; // The stepper motor needs 200 single steps for 360 deg, equals 100 steps for 180 deg, 180 Deg in 1/16 steps equals 1600 1/16 steps int stepsFor180Deg = 1600; // The stepper motor needs 200 single steps for 360 deg, equals 100 steps for 180 deg, 180 Deg in 1/16 steps equals 1600 1/16 steps
int leapsFor180Deg = 5; // Determines how big the amount of single steps is to complete 180 degrees of rotation
int leapsFor180Deg = 80; // Determines how big the amount of single steps is to complete 180 degrees of rotation, 80 ^= 1600/80 1/16 Steps tom complete 180 deg
bool alarmSunriseFlag = false; bool alarmSunriseFlag = false;
bool alarmSunsetFlag = false; bool alarmSunsetFlag = false;
bool makeStepFlag = false; bool makeStepFlag = false;
int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){ int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){
int duration_h=0; int duration_h=0;
int duration_m=0; int duration_m=0;
int duration=0;


duration_h = sunset->hours - sunrise->hours; duration_h = sunset->hours - sunrise->hours;
duration_m = sunset->minutes - sunrise->minutes; duration_m = sunset->minutes - sunrise->minutes;
duration_m = 60 - sunrise->minutes + sunset->minutes; duration_m = 60 - sunrise->minutes + sunset->minutes;
} }


return (duration_h * 60 + duration_m) / leapsFor180Deg;
duration = (duration_h * 60 + duration_m) / leapsFor180Deg;

return duration;
} }


/******************************************************************************* /*******************************************************************************
0 0
}; };


uint32_t timeToNextStep_m=0;
uint32_t timeToNextStep=0;
uint32_t alarmB_h = 0; uint32_t alarmB_h = 0;
uint32_t alarmB_m = 0; uint32_t alarmB_m = 0;
uint32_t alarmB_wd = 0; uint32_t alarmB_wd = 0;
calc_sunrise_sunset(&initialDate, &sunrise, &sunset, &tomorrowsDate); calc_sunrise_sunset(&initialDate, &sunrise, &sunset, &tomorrowsDate);


//Test code //Test code
sunrise.hours = 14;
sunrise.minutes = 0;
sunrise.weekDay = 7;


sunset.hours = 16;
sunset.minutes = 00;
sunset.weekDay = 7;
sunrise.hours = 7;
sunrise.minutes = 25;
sunrise.weekDay = 1;

sunset.hours = 18;
sunset.minutes = 13;
sunset.weekDay = 1;



//Calculate the time for next motor step in minutes //Calculate the time for next motor step in minutes
timeToNextStep_m = calc_interval_duration(&sunrise, &sunset);
timeToNextStep = calc_interval_duration(&sunrise, &sunset);


// Set Alarm for sunrise // Set Alarm for sunrise
transmit_uart("Setting alarm for sunrise.\r\n"); transmit_uart("Setting alarm for sunrise.\r\n");


transmit_uart("|--------------------------------------------------------|\r\n\r\n"); transmit_uart("|--------------------------------------------------------|\r\n\r\n");
// Increment alarm time with the precalculated timeToNextStep // Increment alarm time with the precalculated timeToNextStep
int minAdd_tmp=0;
float minAdd_tmp=0;


minAdd_tmp = alarmB_m + timeToNextStep_m;
minAdd_tmp = alarmB_m + timeToNextStep;


// Consider minutes overflow ^= hours + 1 // Consider minutes overflow ^= hours + 1
if (minAdd_tmp > 60) { if (minAdd_tmp > 60) {


/** Initialize RTC and set the Time and Date /** Initialize RTC and set the Time and Date
*/ */
sTime.Hours = 13;
sTime.Minutes = 56;
sTime.Hours = 7;
sTime.Minutes = 20;
sTime.Seconds = 10; sTime.Seconds = 10;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET; sTime.StoreOperation = RTC_STOREOPERATION_RESET;
{ {
Error_Handler(); Error_Handler();
} }
sDate.WeekDay = RTC_WEEKDAY_SUNDAY;
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_FEBRUARY; sDate.Month = RTC_MONTH_FEBRUARY;
sDate.Date = 21; sDate.Date = 21;
sDate.Year = 21; sDate.Year = 21;

Loading…
Cancel
Save