# [Moved]Mathematical formula for this sequence of time?

1. ## [Moved]Mathematical formula for this sequence of time?

Hello!! Everyone,

I have to write to memory card with the following frequency
 100 ms
 200 ms
 250 ms
 500 ms
 1 sec
 2 sec
 2.5 sec
 5 sec
 10 sec
 15 sec
 30 sec
 1 min
 2 min
 2.5 min
 5 min
 10 min

This time is selected by Lcd Menu, as these are 16 entries, a variable is used suppose frequency whose value goes from 0-15, for each particular time.

I have a task which write to memory card at a rate of 100 msec
How can use this variable frequency to evaluate the time which is selected and do logging.
Please suggest me some better way to do this.

•

2. ## Re: [Moved]Mathematical formula for this sequence of time?

Please suggest me some better way to do this.
Better than whΰt? You didn't yet tell your method to implement the timing.

I don't see particularly mathematical problem, it's just a regular programming job.

Have a table of time values in 100 ms units, e.g. 10 min = 6000. Count 100 ms intervals and compare it against the table value according to frequency.

•

3. ## Re: [Moved]Mathematical formula for this sequence of time?

Yes i am doing it in this way.

For timing of the task, smal rtos (Task Manager) is used.

```Code C - [expand]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
static u16_t timeKeeping = 0;
static boolean writeToSd = FALSE;
timeKeeping++;
switch(loggingFrequency)
{
case LOG_100MS:
if(timeKeeping >= SD_TIME_100MS)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_200MS:
if(timeKeeping >= SD_TIME_200MS)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_250MS:
if(timeKeeping >= SD_TIME_250MS)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_500MS:
if(timeKeeping >= SD_TIME_500MS)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_1SEC:
if(timeKeeping >= SD_TIME_1SEC)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_2SEC:
if(timeKeeping >= SD_TIME_2SEC)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_2_5SEC:
if(timeKeeping >= SD_TIME_2_5SEC)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_5SEC:
if(timeKeeping >= SD_TIME_5SEC)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_10SEC:
if(timeKeeping >= SD_TIME_10SEC)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_15SEC:
if(timeKeeping >= SD_TIME_15SEC)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_30SEC:
if(timeKeeping >= SD_TIME_30SEC)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_1MIN:
if(timeKeeping >= SD_TIME_1MIN)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_2MIN:
if(timeKeeping >= SD_TIME_2MIN)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_2_5MIN:
if(timeKeeping >= SD_TIME_2_5MIN)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_5MIN:
if(timeKeeping >= SD_TIME_5MIN)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
case LOG_10MIN:
if(timeKeeping >= SD_TIME_10MIN)
{
timeKeeping = SD_TIME_RESET;
writeToSd = TRUE;
}
break;
default:
loggingFrequency = LOG_10SEC;
break;
}```

•

4. ## Re: [Moved]Mathematical formula for this sequence of time?

Using a case structure with fixed time constant literals is an option. As said, I would use a constant array instead.
Code:
```if(timeKeeping >= SD_TIME[frequency])
{
timeKeeping = 0;
writeToSd = TRUE;
}```

1 members found this post helpful.

5. ## Re: [Moved]Mathematical formula for this sequence of time?

Thanks, this is what i am looking for.

6. ## Re: [Moved]Mathematical formula for this sequence of time?

Make a 100 ms Timer using 8 bit timer. If in LCD menu 100 ms is selected then set a variable say x to 1. Use a counter and increment it on every 100 ms Timer0 interrupt. If counter value is 1 and also x was set to 1 (write every 100 ms) then set a flag write2SD in ISR and in while(1) check if this flag is set and if set call writeToSD function. If x is set to 10 (from LCD menu) then counter has to become 10 and then it matches with x and when this happens it writes to SD Card. So, it will be write every 1 sec.

1 members found this post helpful.

•

7. ## Re: [Moved]Mathematical formula for this sequence of time?

I am having a task which is already executed in 100msec, so i need any separate timer for that, the method works for me.
Thanks for your help sir, will try it somewhere else.

8. ## Re: [Moved]Mathematical formula for this sequence of time?

If you already have a 100 ms timer then you can use it but if you use my method then when SD Card write duration is selected through LCD menu then you have to clear counter and timer registers and set x to required value.

--[[ ]]--