Change output state by a timing table/array centred on a period

Hello,

Firstly - im not new, been using Arduino for 7-8 years and normally get on fine, well enough for my needs and so long long since i needed to ask a question i had to re-register on the forum!

I may be overcomplicating this in my mind which is causing me not to know where to start.

I have a table (array) of 64 values which range from 0 to 60 (more or less following the SIN of 90deg) and these values represent the time period i want a digital output to be high for.

Add to that, i want the "high" period to be central within the step time, this is what my starting info is and this is all in msec:

Step	High Period	Go high at	Go low at
0	0	30	30
1	1	29	31
2	3	29	31
3	4	28	32
4	6	27	33
5	7	26	34
6	9	26	34
7	10	25	35
8	12	24	36
9	13	24	36
10	15	23	37
11	16	22	38
12	17	21	39
13	19	21	39
14	20	20	40
15	21	19	41
16	23	19	41
17	24	18	42
18	25	17	43
19	27	17	43
20	28	16	44
21	29	15	45
22	31	15	45
23	32	14	46
24	33	13	47
25	34	13	47
26	36	12	48
27	37	12	48
28	38	11	49
29	39	11	49
30	40	10	50
31	41	9	51
32	42	9	51
33	43	8	52
34	44	8	52
35	45	7	53
36	46	7	53
37	47	6	54
38	48	6	54
39	49	6	54
40	50	5	55
41	50	5	55
42	51	4	56
43	52	4	56
44	53	4	56
45	53	3	57
46	54	3	57
47	55	3	57
48	55	2	58
49	56	2	58
50	56	2	58
51	57	2	58
52	57	1	59
53	58	1	59
54	58	1	59
55	58	1	59
56	59	1	59
57	59	0	60
58	59	0	60
59	59	0	60
60	60	0	60
61	60	0	60
62	60	0	60
63	60	0	60
64	60	0	60
![image|105x500](upload://iN8MmGto02wfoAKdq8bQtbcJvIJ.png)

My array would only have the "high period" values in an array of 64.

Each "period" or window is 60msec, and if we take step 7 as a example:

I want the high period to be 10msec and the pin turns high 25msec into the 60 period and off at 35msec.

This means the high period is always central within the 60msec.

Thats the first part of the issue, the next part is i need to reverse and once i get the the 64th value, reverse though the array back to the start and this would be a repeating cycle.

I can think of a few ways but i dont get far in my concept before i just dont think ive got the right angle on tackling this.

So, does anybody know of any examples or libraries or posts ive not found in searches which do this or something similar? I want it to be non-blocking as i avoid delays in the main loop and subtract from millis or micros and this would be my preferred method too here.

Lots of things writing PWM values from arrays to LEDs or motors etc, but nothing i see which directly times a pins high/low transition timings.

Once i have something i will of course share code.

Thanks!

Start with blink without delay. Use it to increment an index from zero to 64 and back to zero changing every 60mS.

Once that is working, whenever you change the index, use the value in the array to calculate on and off times within the window.

When that tests out ok, use millis and the window start time to turn the output on and off.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.