ISR counter value doesn't seem to have an effect

lunjius
Posts: 3
Joined: Tue Feb 26, 2019 4:55 pm

ISR counter value doesn't seem to have an effect

Postby lunjius » Fri Mar 01, 2019 10:03 pm

Hello everyone,

I am trying to fade an LED physically linear, means I increase the duty cycles exponential to make it look for the human eye as if the LED's brightness is growing linear.
This (and some others) are the reasons why I don't use the delivered hardware timer for automatic fades (which fades duty cycles linear), but use a timer's ISR to "set" the new duty cycle every so and so ticks. The number of ticks depends on the span fade duration and fade-brightness' start and end values.

Now the problem: The calculation of clock ticks and the ISR call work just fine. But the LED's brightness jumps from 0% to 100% immediately, although it should fade for 10 seconds. When trying to make some debugging outputs INSIDE the ISR with ets_printf(), the LED faded just as it should have done, the more I printed per ISR, the slower it faded. Just as if the previously set counter value (auto_reload on) had no effect/was equal to 0 and all the interrupts were thrown immediately.

I don't know what's wrong with my code, can anybody help? Thanks in advance!

Code: Select all

#include <stdio.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "driver/ledc.h"
#include "driver/timer.h"
#include "esp_err.h"

#define LEDC_LS_TIMER			LEDC_TIMER_0
#define LEDC_LS_MODE			LEDC_LOW_SPEED_MODE
#define LEDC_LS_GPIO 			(12)
#define LEDC_LS_CHANNEL			LEDC_CHANNEL_0
#define LEDC_TIMER_RESOLUTION	LEDC_TIMER_13_BIT

#define FRAME_REFR_TIMER_GROUP	TIMER_GROUP_0
#define FRAME_REFR_TIMER		TIMER_0

#define FADE_DURATION_MS		10000
#define FADE_START_BRIGHT_PERC	0.0
#define FADE_END_BRIGHT_PERC	1.0

typedef struct {
	uint16_t fade_step;
	uint16_t max_step;
	ledc_channel_config_t ledc_channel;
} isr_param_t;

uint64_t alarm_ticks = 0;

static const uint16_t duty_cycles[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0,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 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 97, 97, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, 99, 99, 99, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 101, 101, 101, 101, 101, 101, 101, 101, 101, 102, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103, 103, 103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 104, 105, 105, 105, 105, 105, 105, 105, 105, 106, 106, 106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107, 107, 107, 107, 107, 108, 108, 108, 108, 108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109, 109, 109, 110, 110, 110, 110, 110, 110, 110, 110, 111, 111, 111, 111, 111, 111, 111, 111, 112, 112, 112, 112, 112, 112, 112, 112, 113, 113, 113, 113, 113, 113, 113, 113, 114, 114, 114, 114, 114, 114, 114, 114, 115, 115, 115, 115, 115, 115, 115, 115, 116, 116, 116, 116, 116, 116, 116, 116, 117, 117, 117, 117, 117, 117, 117, 118, 118, 118, 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 120, 120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 121, 122, 122, 122, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 127, 127, 127, 127, 127, 127, 127, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 130, 130, 130, 130, 130, 130, 130, 131, 131, 131, 131, 131, 131, 131, 132, 132, 132, 132, 132, 132, 132, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134, 134, 134, 134, 135, 135, 135, 135, 135, 135, 135, 136, 136, 136, 136, 136, 136, 136, 137, 137, 137, 137, 137, 137, 138, 138, 138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 139, 140, 140, 140, 140, 140, 140, 140, 141, 141, 141, 141, 141, 141, 142, 142, 142, 142, 142, 142, 143, 143, 143, 143, 143, 143, 143, 144, 144, 144, 144, 144, 144, 145, 145, 145, 145, 145, 145, 146, 146, 146, 146, 146, 146, 147, 147, 147, 147, 147, 147, 147, 148, 148, 148, 148, 148, 148, 149, 149, 149, 149, 149, 149, 150, 150, 150, 150, 150, 150, 151, 151, 151, 151, 151, 151, 152, 152, 152, 152, 152, 152, 153, 153, 153, 153, 153, 153, 154, 154, 154, 154, 154, 154, 155, 155, 155, 155, 155, 156, 156, 156, 156, 156, 156, 157, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 158, 159, 159, 159, 159, 159, 160, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 161, 162, 162, 162, 162, 162, 163, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 165, 165, 165, 165, 165, 165, 166, 166, 166, 166, 166, 167, 167, 167, 167, 167, 168, 168, 168, 168, 168, 168, 169, 169, 169, 169, 169, 170, 170, 170, 170, 170, 170, 171, 171, 171, 171, 171, 172, 172, 172, 172, 172, 173, 173, 173, 173, 173, 174, 174, 174, 174, 174, 174, 175, 175, 175, 175, 175, 176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 178, 178, 178, 178, 178, 179, 179, 179, 179, 179, 180, 180, 180, 180, 180, 181, 181, 181, 181, 181, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183, 184, 184, 184, 184, 184, 185, 185, 185, 185, 185, 186, 186, 186, 186, 186, 187, 187, 187, 187, 188, 188, 188, 188, 188, 189, 189, 189, 189, 189, 190, 190, 190, 190, 190, 191, 191, 191, 191, 191, 192, 192, 192, 192, 193, 193, 193, 193, 193, 194, 194, 194, 194, 194, 195, 195, 195, 195, 196, 196, 196, 196, 196, 197, 197, 197, 197, 198, 198, 198, 198, 198, 199, 199, 199, 199, 199, 200, 200, 200, 200, 201, 201, 201, 201, 201, 202, 202, 202, 202, 203, 203, 203, 203, 203, 204, 204, 204, 204, 205, 205, 205, 205, 206, 206, 206, 206, 206, 207, 207, 207, 207, 208, 208, 208, 208, 209, 209, 209, 209, 209, 210, 210, 210, 210, 211, 211, 211, 211, 212, 212, 212, 212, 212, 213, 213, 213, 213, 214, 214, 214, 214, 215, 215, 215, 215, 216, 216, 216, 216, 216, 217, 217, 217, 217, 218, 218, 218, 218, 219, 219, 219, 219, 220, 220, 220, 220, 221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 224, 224, 224, 224, 225, 225, 225, 225, 226, 226, 226, 226, 227, 227, 227, 227, 228, 228, 228, 228, 229, 229, 229, 229, 230, 230, 230, 230, 231, 231, 231, 231, 232, 232, 232, 232, 233, 233, 233, 233, 234, 234, 234, 234, 235, 235, 235, 235, 236, 236, 236, 236, 237, 237, 237, 238, 238, 238, 238, 239, 239, 239, 239, 240, 240, 240, 240, 241, 241, 241, 242, 242, 242, 242, 243, 243, 243, 243, 244, 244, 244, 244, 245, 245, 245, 246, 246, 246, 246, 247, 247, 247, 247, 248, 248, 248, 249, 249, 249, 249, 250, 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 254, 254, 254, 254, 255, 255, 255, 255, 256, 256, 256, 257, 257, 257, 257, 258, 258, 258, 259, 259, 259, 259, 260, 260, 260, 261, 261, 261, 261, 262, 262, 262, 263, 263, 263, 264, 264, 264, 264, 265, 265, 265, 266, 266, 266, 266, 267, 267, 267, 268, 268, 268, 269, 269, 269, 269, 270, 270, 270, 271, 271, 271, 271, 272, 272, 272, 273, 273, 273, 274, 274, 274, 275, 275, 275, 275, 276, 276, 276, 277, 277, 277, 278, 278, 278, 278, 279, 279, 279, 280, 280, 280, 281, 281, 281, 282, 282, 282, 283, 283, 283, 283, 284, 284, 284, 285, 285, 285, 286, 286, 286, 287, 287, 287, 288, 288, 288, 288, 289, 289, 289, 290, 290, 290, 291, 291, 291, 292, 292, 292, 293, 293, 293, 294, 294, 294, 295, 295, 295, 296, 296, 296, 297, 297, 297, 298, 298, 298, 299, 299, 299, 300, 300, 300, 301, 301, 301, 302, 302, 302, 303, 303, 303, 304, 304, 304, 305, 305, 305, 306, 306, 306, 307, 307, 307, 308, 308, 308, 309, 309, 309, 310, 310, 310, 311, 311, 311, 312, 312, 312, 313, 313, 313, 314, 314, 314, 315, 315, 315, 316, 316, 317, 317, 317, 318, 318, 318, 319, 319, 319, 320, 320, 320, 321, 321, 321, 322, 322, 323, 323, 323, 324, 324, 324, 325, 325, 325, 326, 326, 326, 327, 327, 328, 328, 328, 329, 329, 329, 330, 330, 330, 331, 331, 332, 332, 332, 333, 333, 333, 334, 334, 334, 335, 335, 336, 336, 336, 337, 337, 337, 338, 338, 339, 339, 339, 340, 340, 340, 341, 341, 342, 342, 342, 343, 343, 343, 344, 344, 345, 345, 345, 346, 346, 346, 347, 347, 348, 348, 348, 349, 349, 350, 350, 350, 351, 351, 351, 352, 352, 353, 353, 353, 354, 354, 355, 355, 355, 356, 356, 357, 357, 357, 358, 358, 359, 359, 359, 360, 360, 361, 361, 361, 362, 362, 363, 363, 363, 364, 364, 365, 365, 365, 366, 366, 367, 367, 367, 368, 368, 369, 369, 369, 370, 370, 371, 371, 371, 372, 372, 373, 373, 373, 374, 374, 375, 375, 376, 376, 376, 377, 377, 378, 378, 378, 379, 379, 380, 380, 381, 381, 381, 382, 382, 383, 383, 383, 384, 384, 385, 385, 386, 386, 386, 387, 387, 388, 388, 389, 389, 389, 390, 390, 391, 391, 392, 392, 392, 393, 393, 394, 394, 395, 395, 396, 396, 396, 397, 397, 398, 398, 399, 399, 399, 400, 400, 401, 401, 402, 402, 403, 403, 403, 404, 404, 405, 405, 406, 406, 407, 407, 407, 408, 408, 409, 409, 410, 410, 411, 411, 412, 412, 412, 413, 413, 414, 414, 415, 415, 416, 416, 417, 417, 417, 418, 418, 419, 419, 420, 420, 421, 421, 422, 422, 423, 423, 423, 424, 424, 425, 425, 426, 426, 427, 427, 428, 428, 429, 429, 430, 430, 431, 431, 432, 432, 432, 433, 433, 434, 434, 435, 435, 436, 436, 437, 437, 438, 438, 439, 439, 440, 440, 441, 441, 442, 442, 443, 443, 444, 444, 445, 445, 446, 446, 447, 447, 447, 448, 448, 449, 449, 450, 450, 451, 451, 452, 452, 453, 453, 454, 454, 455, 455, 456, 456, 457, 457, 458, 458, 459, 459, 460, 461, 461, 462, 462, 463, 463, 464, 464, 465, 465, 466, 466, 467, 467, 468, 468, 469, 469, 470, 470, 471, 471, 472, 472, 473, 473, 474, 474, 475, 475, 476, 477, 477, 478, 478, 479, 479, 480, 480, 481, 481, 482, 482, 483, 483, 484, 484, 485, 486, 486, 487, 487, 488, 488, 489, 489, 490, 490, 491, 491, 492, 493, 493, 494, 494, 495, 495, 496, 496, 497, 497, 498, 499, 499, 500, 500, 501, 501, 502, 502, 503, 504, 504, 505, 505, 506, 506, 507, 507, 508, 509, 509, 510, 510, 511, 511, 512, 512, 513, 514, 514, 515, 515, 516, 516, 517, 518, 518, 519, 519, 520, 520, 521, 522, 522, 523, 523, 524, 524, 525, 526, 526, 527, 527, 528, 529, 529, 530, 530, 531, 531, 532, 533, 533, 534, 534, 535, 536, 536, 537, 537, 538, 539, 539, 540, 540, 541, 542, 542, 543, 543, 544, 544, 545, 546, 546, 547, 548, 548, 549, 549, 550, 551, 551, 552, 552, 553, 554, 554, 555, 555, 556, 557, 557, 558, 558, 559, 560, 560, 561, 562, 562, 563, 563, 564, 565, 565, 566, 567, 567, 568, 568, 569, 570, 570, 571, 572, 572, 573, 573, 574, 575, 575, 576, 577, 577, 578, 579, 579, 580, 580, 581, 582, 582, 583, 584, 584, 585, 586, 586, 587, 588, 588, 589, 589, 590, 591, 591, 592, 593, 593, 594, 595, 595, 596, 597, 597, 598, 599, 599, 600, 601, 601, 602, 603, 603, 604, 605, 605, 606, 607, 607, 608, 609, 609, 610, 611, 611, 612, 613, 613, 614, 615, 615, 616, 617, 617, 618, 619, 619, 620, 621, 621, 622, 623, 624, 624, 625, 626, 626, 627, 628, 628, 629, 630, 630, 631, 632, 633, 633, 634, 635, 635, 636, 637, 637, 638, 639, 640, 640, 641, 642, 642, 643, 644, 644, 645, 646, 647, 647, 648, 649, 649, 650, 651, 652, 652, 653, 654, 654, 655, 656, 657, 657, 658, 659, 660, 660, 661, 662, 662, 663, 664, 665, 665, 666, 667, 668, 668, 669, 670, 671, 671, 672, 673, 674, 674, 675, 676, 676, 677, 678, 679, 679, 680, 681, 682, 682, 683, 684, 685, 685, 686, 687, 688, 689, 689, 690, 691, 692, 692, 693, 694, 695, 695, 696, 697, 698, 698, 699, 700, 701, 702, 702, 703, 704, 705, 705, 706, 707, 708, 709, 709, 710, 711, 712, 712, 713, 714, 715, 716, 716, 717, 718, 719, 720, 720, 721, 722, 723, 724, 724, 725, 726, 727, 728, 728, 729, 730, 731, 732, 732, 733, 734, 735, 736, 736, 737, 738, 739, 740, 740, 741, 742, 743, 744, 745, 745, 746, 747, 748, 749, 749, 750, 751, 752, 753, 754, 754, 755, 756, 757, 758, 759, 759, 760, 761, 762, 763, 764, 764, 765, 766, 767, 768, 769, 770, 770, 771, 772, 773, 774, 775, 775, 776, 777, 778, 779, 780, 781, 781, 782, 783, 784, 785, 786, 787, 788, 788, 789, 790, 791, 792, 793, 794, 795, 795, 796, 797, 798, 799, 800, 801, 802, 802, 803, 804, 805, 806, 807, 808, 809, 810, 810, 811, 812, 813, 814, 815, 816, 817, 818, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1049, 1050, 1051, 1052, 1053, 1054, 1056, 1057, 1058, 1059, 1060, 1061, 1063, 1064, 1065, 1066, 1067, 1068, 1070, 1071, 1072, 1073, 1074, 1076, 1077, 1078, 1079, 1080, 1081, 1083, 1084, 1085, 1086, 1087, 1089, 1090, 1091, 1092, 1093, 1095, 1096, 1097, 1098, 1099, 1101, 1102, 1103, 1104, 1106, 1107, 1108, 1109, 1110, 1112, 1113, 1114, 1115, 1117, 1118, 1119, 1120, 1121, 1123, 1124, 1125, 1126, 1128, 1129, 1130, 1131, 1133, 1134, 1135, 1136, 1138, 1139, 1140, 1141, 1143, 1144, 1145, 1146, 1148, 1149, 1150, 1151, 1153, 1154, 1155, 1157, 1158, 1159, 1160, 1162, 1163, 1164, 1166, 1167, 1168, 1169, 1171, 1172, 1173, 1175, 1176, 1177, 1178, 1180, 1181, 1182, 1184, 1185, 1186, 1188, 1189, 1190, 1191, 1193, 1194, 1195, 1197, 1198, 1199, 1201, 1202, 1203, 1205, 1206, 1207, 1209, 1210, 1211, 1213, 1214, 1215, 1217, 1218, 1219, 1221, 1222, 1223, 1225, 1226, 1227, 1229, 1230, 1231, 1233, 1234, 1236, 1237, 1238, 1240, 1241, 1242, 1244, 1245, 1246, 1248, 1249, 1251, 1252, 1253, 1255, 1256, 1257, 1259, 1260, 1262, 1263, 1264, 1266, 1267, 1269, 1270, 1271, 1273, 1274, 1276, 1277, 1278, 1280, 1281, 1283, 1284, 1285, 1287, 1288, 1290, 1291, 1293, 1294, 1295, 1297, 1298, 1300, 1301, 1303, 1304, 1305, 1307, 1308, 1310, 1311, 1313, 1314, 1316, 1317, 1318, 1320, 1321, 1323, 1324, 1326, 1327, 1329, 1330, 1332, 1333, 1335, 1336, 1337, 1339, 1340, 1342, 1343, 1345, 1346, 1348, 1349, 1351, 1352, 1354, 1355, 1357, 1358, 1360, 1361, 1363, 1364, 1366, 1367, 1369, 1370, 1372, 1373, 1375, 1376, 1378, 1379, 1381, 1382, 1384, 1385, 1387, 1388, 1390, 1392, 1393, 1395, 1396, 1398, 1399, 1401, 1402, 1404, 1405, 1407, 1408, 1410, 1412, 1413, 1415, 1416, 1418, 1419, 1421, 1422, 1424, 1426, 1427, 1429, 1430, 1432, 1433, 1435, 1437, 1438, 1440, 1441, 1443, 1445, 1446, 1448, 1449, 1451, 1453, 1454, 1456, 1457, 1459, 1461, 1462, 1464, 1465, 1467, 1469, 1470, 1472, 1473, 1475, 1477, 1478, 1480, 1482, 1483, 1485, 1487, 1488, 1490, 1491, 1493, 1495, 1496, 1498, 1500, 1501, 1503, 1505, 1506, 1508, 1510, 1511, 1513, 1515, 1516, 1518, 1520, 1521, 1523, 1525, 1526, 1528, 1530, 1531, 1533, 1535, 1536, 1538, 1540, 1542, 1543, 1545, 1547, 1548, 1550, 1552, 1553, 1555, 1557, 1559, 1560, 1562, 1564, 1565, 1567, 1569, 1571, 1572, 1574, 1576, 1578, 1579, 1581, 1583, 1585, 1586, 1588, 1590, 1592, 1593, 1595, 1597, 1599, 1600, 1602, 1604, 1606, 1607, 1609, 1611, 1613, 1614, 1616, 1618, 1620, 1622, 1623, 1625, 1627, 1629, 1631, 1632, 1634, 1636, 1638, 1640, 1641, 1643, 1645, 1647, 1649, 1650, 1652, 1654, 1656, 1658, 1659, 1661, 1663, 1665, 1667, 1669, 1670, 1672, 1674, 1676, 1678, 1680, 1682, 1683, 1685, 1687, 1689, 1691, 1693, 1695, 1696, 1698, 1700, 1702, 1704, 1706, 1708, 1710, 1711, 1713, 1715, 1717, 1719, 1721, 1723, 1725, 1727, 1728, 1730, 1732, 1734, 1736, 1738, 1740, 1742, 1744, 1746, 1748, 1750, 1751, 1753, 1755, 1757, 1759, 1761, 1763, 1765, 1767, 1769, 1771, 1773, 1775, 1777, 1779, 1781, 1783, 1785, 1786, 1788, 1790, 1792, 1794, 1796, 1798, 1800, 1802, 1804, 1806, 1808, 1810, 1812, 1814, 1816, 1818, 1820, 1822, 1824, 1826, 1828, 1830, 1832, 1834, 1836, 1838, 1840, 1842, 1844, 1846, 1848, 1851, 1853, 1855, 1857, 1859, 1861, 1863, 1865, 1867, 1869, 1871, 1873, 1875, 1877, 1879, 1881, 1883, 1885, 1888, 1890, 1892, 1894, 1896, 1898, 1900, 1902, 1904, 1906, 1908, 1911, 1913, 1915, 1917, 1919, 1921, 1923, 1925, 1927, 1930, 1932, 1934, 1936, 1938, 1940, 1942, 1944, 1947, 1949, 1951, 1953, 1955, 1957, 1960, 1962, 1964, 1966, 1968, 1970, 1972, 1975, 1977, 1979, 1981, 1983, 1986, 1988, 1990, 1992, 1994, 1997, 1999, 2001, 2003, 2005, 2008, 2010, 2012, 2014, 2016, 2019, 2021, 2023, 2025, 2028, 2030, 2032, 2034, 2036, 2039, 2041, 2043, 2045, 2048, 2050, 2052, 2054, 2057, 2059, 2061, 2064, 2066, 2068, 2070, 2073, 2075, 2077, 2079, 2082, 2084, 2086, 2089, 2091, 2093, 2096, 2098, 2100, 2102, 2105, 2107, 2109, 2112, 2114, 2116, 2119, 2121, 2123, 2126, 2128, 2130, 2133, 2135, 2137, 2140, 2142, 2145, 2147, 2149, 2152, 2154, 2156, 2159, 2161, 2164, 2166, 2168, 2171, 2173, 2175, 2178, 2180, 2183, 2185, 2187, 2190, 2192, 2195, 2197, 2200, 2202, 2204, 2207, 2209, 2212, 2214, 2217, 2219, 2221, 2224, 2226, 2229, 2231, 2234, 2236, 2239, 2241, 2244, 2246, 2248, 2251, 2253, 2256, 2258, 2261, 2263, 2266, 2268, 2271, 2273, 2276, 2278, 2281, 2283, 2286, 2288, 2291, 2293, 2296, 2299, 2301, 2304, 2306, 2309, 2311, 2314, 2316, 2319, 2321, 2324, 2327, 2329, 2332, 2334, 2337, 2339, 2342, 2344, 2347, 2350, 2352, 2355, 2357, 2360, 2363, 2365, 2368, 2370, 2373, 2376, 2378, 2381, 2384, 2386, 2389, 2391, 2394, 2397, 2399, 2402, 2405, 2407, 2410, 2413, 2415, 2418, 2421, 2423, 2426, 2429, 2431, 2434, 2437, 2439, 2442, 2445, 2447, 2450, 2453, 2455, 2458, 2461, 2464, 2466, 2469, 2472, 2474, 2477, 2480, 2483, 2485, 2488, 2491, 2494, 2496, 2499, 2502, 2505, 2507, 2510, 2513, 2516, 2518, 2521, 2524, 2527, 2529, 2532, 2535, 2538, 2541, 2543, 2546, 2549, 2552, 2555, 2557, 2560, 2563, 2566, 2569, 2572, 2574, 2577, 2580, 2583, 2586, 2589, 2591, 2594, 2597, 2600, 2603, 2606, 2609, 2611, 2614, 2617, 2620, 2623, 2626, 2629, 2632, 2635, 2637, 2640, 2643, 2646, 2649, 2652, 2655, 2658, 2661, 2664, 2667, 2670, 2673, 2675, 2678, 2681, 2684, 2687, 2690, 2693, 2696, 2699, 2702, 2705, 2708, 2711, 2714, 2717, 2720, 2723, 2726, 2729, 2732, 2735, 2738, 2741, 2744, 2747, 2750, 2753, 2756, 2759, 2762, 2765, 2768, 2771, 2774, 2777, 2781, 2784, 2787, 2790, 2793, 2796, 2799, 2802, 2805, 2808, 2811, 2814, 2817, 2821, 2824, 2827, 2830, 2833, 2836, 2839, 2842, 2846, 2849, 2852, 2855, 2858, 2861, 2864, 2868, 2871, 2874, 2877, 2880, 2883, 2887, 2890, 2893, 2896, 2899, 2902, 2906, 2909, 2912, 2915, 2918, 2922, 2925, 2928, 2931, 2935, 2938, 2941, 2944, 2947, 2951, 2954, 2957, 2960, 2964, 2967, 2970, 2974, 2977, 2980, 2983, 2987, 2990, 2993, 2997, 3000, 3003, 3006, 3010, 3013, 3016, 3020, 3023, 3026, 3030, 3033, 3036, 3040, 3043, 3046, 3050, 3053, 3056, 3060, 3063, 3067, 3070, 3073, 3077, 3080, 3083, 3087, 3090, 3094, 3097, 3101, 3104, 3107, 3111, 3114, 3118, 3121, 3124, 3128, 3131, 3135, 3138, 3142, 3145, 3149, 3152, 3156, 3159, 3163, 3166, 3169, 3173, 3176, 3180, 3183, 3187, 3190, 3194, 3198, 3201, 3205, 3208, 3212, 3215, 3219, 3222, 3226, 3229, 3233, 3236, 3240, 3244, 3247, 3251, 3254, 3258, 3261, 3265, 3269, 3272, 3276, 3279, 3283, 3287, 3290, 3294, 3298, 3301, 3305, 3308, 3312, 3316, 3319, 3323, 3327, 3330, 3334, 3338, 3341, 3345, 3349, 3352, 3356, 3360, 3364, 3367, 3371, 3375, 3378, 3382, 3386, 3390, 3393, 3397, 3401, 3404, 3408, 3412, 3416, 3419, 3423, 3427, 3431, 3435, 3438, 3442, 3446, 3450, 3454, 3457, 3461, 3465, 3469, 3473, 3476, 3480, 3484, 3488, 3492, 3496, 3499, 3503, 3507, 3511, 3515, 3519, 3523, 3526, 3530, 3534, 3538, 3542, 3546, 3550, 3554, 3558, 3562, 3565, 3569, 3573, 3577, 3581, 3585, 3589, 3593, 3597, 3601, 3605, 3609, 3613, 3617, 3621, 3625, 3629, 3633, 3637, 3641, 3645, 3649, 3653, 3657, 3661, 3665, 3669, 3673, 3677, 3681, 3685, 3689, 3693, 3697, 3701, 3705, 3710, 3714, 3718, 3722, 3726, 3730, 3734, 3738, 3742, 3746, 3751, 3755, 3759, 3763, 3767, 3771, 3775, 3780, 3784, 3788, 3792, 3796, 3800, 3805, 3809, 3813, 3817, 3821, 3826, 3830, 3834, 3838, 3842, 3847, 3851, 3855, 3859, 3864, 3868, 3872, 3876, 3881, 3885, 3889, 3894, 3898, 3902, 3906, 3911, 3915, 3919, 3924, 3928, 3932, 3937, 3941, 3945, 3950, 3954, 3958, 3963, 3967, 3971, 3976, 3980, 3985, 3989, 3993, 3998, 4002, 4007, 4011, 4015, 4020, 4024, 4029, 4033, 4038, 4042, 4046, 4051, 4055, 4060, 4064, 4069, 4073, 4078, 4082, 4087, 4091, 4096, 4100, 4105, 4109, 4114, 4118, 4123, 4127, 4132, 4136, 4141, 4146, 4150, 4155, 4159, 4164, 4168, 4173, 4178, 4182, 4187, 4191, 4196, 4201, 4205, 4210, 4215, 4219, 4224, 4228, 4233, 4238, 4242, 4247, 4252, 4256, 4261, 4266, 4271, 4275, 4280, 4285, 4289, 4294, 4299, 4304, 4308, 4313, 4318, 4323, 4327, 4332, 4337, 4342, 4346, 4351, 4356, 4361, 4366, 4370, 4375, 4380, 4385, 4390, 4394, 4399, 4404, 4409, 4414, 4419, 4424, 4428, 4433, 4438, 4443, 4448, 4453, 4458, 4463, 4468, 4473, 4477, 4482, 4487, 4492, 4497, 4502, 4507, 4512, 4517, 4522, 4527, 4532, 4537, 4542, 4547, 4552, 4557, 4562, 4567, 4572, 4577, 4582, 4587, 4592, 4597, 4602, 4607, 4612, 4618, 4623, 4628, 4633, 4638, 4643, 4648, 4653, 4658, 4663, 4669, 4674, 4679, 4684, 4689, 4694, 4700, 4705, 4710, 4715, 4720, 4725, 4731, 4736, 4741, 4746, 4752, 4757, 4762, 4767, 4772, 4778, 4783, 4788, 4794, 4799, 4804, 4809, 4815, 4820, 4825, 4831, 4836, 4841, 4847, 4852, 4857, 4863, 4868, 4873, 4879, 4884, 4889, 4895, 4900, 4906, 4911, 4916, 4922, 4927, 4933, 4938, 4943, 4949, 4954, 4960, 4965, 4971, 4976, 4982, 4987, 4993, 4998, 5004, 5009, 5015, 5020, 5026, 5031, 5037, 5042, 5048, 5053, 5059, 5065, 5070, 5076, 5081, 5087, 5093, 5098, 5104, 5109, 5115, 5121, 5126, 5132, 5138, 5143, 5149, 5155, 5160, 5166, 5172, 5177, 5183, 5189, 5194, 5200, 5206, 5212, 5217, 5223, 5229, 5235, 5240, 5246, 5252, 5258, 5263, 5269, 5275, 5281, 5287, 5292, 5298, 5304, 5310, 5316, 5322, 5328, 5333, 5339, 5345, 5351, 5357, 5363, 5369, 5375, 5381, 5386, 5392, 5398, 5404, 5410, 5416, 5422, 5428, 5434, 5440, 5446, 5452, 5458, 5464, 5470, 5476, 5482, 5488, 5494, 5500, 5506, 5512, 5518, 5524, 5531, 5537, 5543, 5549, 5555, 5561, 5567, 5573, 5579, 5586, 5592, 5598, 5604, 5610, 5616, 5623, 5629, 5635, 5641, 5647, 5654, 5660, 5666, 5672, 5679, 5685, 5691, 5697, 5704, 5710, 5716, 5722, 5729, 5735, 5741, 5748, 5754, 5760, 5767, 5773, 5779, 5786, 5792, 5798, 5805, 5811, 5818, 5824, 5830, 5837, 5843, 5850, 5856, 5863, 5869, 5876, 5882, 5888, 5895, 5901, 5908, 5914, 5921, 5927, 5934, 5941, 5947, 5954, 5960, 5967, 5973, 5980, 5986, 5993, 6000, 6006, 6013, 6019, 6026, 6033, 6039, 6046, 6053, 6059, 6066, 6073, 6079, 6086, 6093, 6099, 6106, 6113, 6120, 6126, 6133, 6140, 6147, 6153, 6160, 6167, 6174, 6181, 6187, 6194, 6201, 6208, 6215, 6221, 6228, 6235, 6242, 6249, 6256, 6263, 6270, 6276, 6283, 6290, 6297, 6304, 6311, 6318, 6325, 6332, 6339, 6346, 6353, 6360, 6367, 6374, 6381, 6388, 6395, 6402, 6409, 6416, 6423, 6430, 6437, 6444, 6451, 6459, 6466, 6473, 6480, 6487, 6494, 6501, 6509, 6516, 6523, 6530, 6537, 6544, 6552, 6559, 6566, 6573, 6581, 6588, 6595, 6602, 6610, 6617, 6624, 6631, 6639, 6646, 6653, 6661, 6668, 6675, 6683, 6690, 6697, 6705, 6712, 6720, 6727, 6734, 6742, 6749, 6757, 6764, 6771, 6779, 6786, 6794, 6801, 6809, 6816, 6824, 6831, 6839, 6846, 6854, 6861, 6869, 6877, 6884, 6892, 6899, 6907, 6914, 6922, 6930, 6937, 6945, 6953, 6960, 6968, 6976, 6983, 6991, 6999, 7006, 7014, 7022, 7030, 7037, 7045, 7053, 7061, 7068, 7076, 7084, 7092, 7099, 7107, 7115, 7123, 7131, 7139, 7146, 7154, 7162, 7170, 7178, 7186, 7194, 7202, 7210, 7218, 7226, 7234, 7241, 7249, 7257, 7265, 7273, 7281, 7289, 7297, 7305, 7314, 7322, 7330, 7338, 7346, 7354, 7362, 7370, 7378, 7386, 7394, 7403, 7411, 7419, 7427, 7435, 7443, 7452, 7460, 7468, 7476, 7484, 7493, 7501, 7509, 7517, 7526, 7534, 7542, 7551, 7559, 7567, 7576, 7584, 7592, 7601, 7609, 7617, 7626, 7634, 7643, 7651, 7659, 7668, 7676, 7685, 7693, 7702, 7710, 7719, 7727, 7736, 7744, 7753, 7761, 7770, 7778, 7787, 7795, 7804, 7813, 7821, 7830, 7838, 7847, 7856, 7864, 7873, 7882, 7890, 7899, 7908, 7916, 7925, 7934, 7943, 7951, 7960, 7969, 7978, 7986, 7995, 8004, 8013, 8022, 8030, 8039, 8048, 8057, 8066, 8075, 8084, 8092, 8101, 8110, 8119, 8128, 8137, 8146, 8155, 8164, 8173, 8182, 8191};

void IRAM_ATTR refresh_frame_isr(void *param) {
	
	isr_param_t *isr_param = (isr_param_t *) param;
	
	/* refresh frame */
	
		uint16_t cycle_index = round((double) FADE_START_BRIGHT_PERC*isr_param->max_step + isr_param->fade_step);
		if ( cycle_index > isr_param->max_step) cycle_index = isr_param->max_step;
	
		ledc_set_duty(isr_param->ledc_channel.speed_mode, isr_param->ledc_channel.channel, duty_cycles[cycle_index]);
		ledc_update_duty(isr_param->ledc_channel.speed_mode, isr_param->ledc_channel.channel);
		
	isr_param->fade_step++;
	
	/* clear interrupt */
		TIMERG0.int_clr_timers.t0 = 1;	// @TODO: make 0 and 1 dynamic according to FRAME_REFR_TIMER_GROUP and FRAME_REFR_TIMER
	
	/* After the alarm has been triggered
      we need enable it again, so it is triggered the next time */
		if ( cycle_index < isr_param->max_step ) TIMERG0.hw_timer[TIMER_0].config.alarm_en = TIMER_ALARM_EN;	// @TODO: Make 0 in TIMERG0 dynamic
		
}

void app_main()
{

    /*
     * Prepare and set configuration of ledc_timers
     * that will be used by LED Controller
     */
    ledc_timer_config_t ledc_timer = {
        .duty_resolution = LEDC_TIMER_RESOLUTION, // resolution of PWM duty
        .freq_hz = 5000,                      // frequency of PWM signal
        .speed_mode = LEDC_LS_MODE,           // timer mode
        .timer_num = LEDC_LS_TIMER            // timer index
    };
    // Set configuration of ledc_timer0 for high speed channels
    ledc_timer_config(&ledc_timer);
    
    ledc_channel_config_t ledc_channel = {
		.channel    = LEDC_LS_CHANNEL,
		.duty       = 0,
		.gpio_num   = LEDC_LS_GPIO,
		.speed_mode = LEDC_LS_MODE,
		.hpoint     = 0,
		.timer_sel  = LEDC_LS_TIMER
	};
	// Set LED Controller with previously prepared configuration
    ledc_channel_config(&ledc_channel);
	
	
	/*
	 * Prepare and set configuration of timers
	 * that will be used to refresh frames
	 */
	timer_config_t frame_timer = {
		.divider = 8000,					// counter ticking speed: 80Mhz / divider -> desired: 100us, 10kHz
		.counter_en = TIMER_PAUSE,			// not counting yet
		.alarm_en = TIMER_ALARM_EN,			// alarm enabled
		.intr_type = TIMER_INTR_LEVEL, 		// interrupt mode
		.counter_dir = TIMER_COUNT_DOWN,	// count timer down
		.auto_reload = TIMER_AUTORELOAD_EN	// reload initial value after alarm occured
	};
	if ( ESP_OK != timer_init(FRAME_REFR_TIMER_GROUP, FRAME_REFR_TIMER, &frame_timer) ) {
		printf("Config timer failed.\n");
	} else {
		printf("Timer configured.\n");
	}
	
	/* set alarm value */
		/* calculate delay between each frame */
			uint16_t max_step = pow(2, LEDC_TIMER_RESOLUTION)-1;
			printf("max_step: %u\n", max_step);
			double frame_delay_ms = (double) FADE_DURATION_MS / ( (double) FADE_END_BRIGHT_PERC*max_step - (double) FADE_START_BRIGHT_PERC*max_step);
			printf("frame_delay_ms: %f\n", frame_delay_ms);
		
		/* calculate ticks to be performed by timer for reaching frame_delay */
			alarm_ticks = round(frame_delay_ms * (80000000 / (double) frame_timer.divider));
	
		timer_set_alarm_value(FRAME_REFR_TIMER_GROUP, FRAME_REFR_TIMER, alarm_ticks);	// set alarm value
		timer_set_counter_value(FRAME_REFR_TIMER_GROUP, FRAME_REFR_TIMER, alarm_ticks);	// value loaded on auto_reload

		printf("alarm set to %llu ticks.\n", alarm_ticks);
		
	/* register refresh interrupt */
		isr_param_t isr_param = {
			.max_step = max_step,
			.fade_step = 0,
			.ledc_channel = ledc_channel
		};
		timer_enable_intr(FRAME_REFR_TIMER_GROUP, FRAME_REFR_TIMER);
		timer_isr_register(FRAME_REFR_TIMER_GROUP, FRAME_REFR_TIMER, refresh_frame_isr, (void *) &isr_param, 
			ESP_INTR_FLAG_IRAM, NULL);
		printf("interrupts enabled.\n");
		
		

    /* start alarm */
		if ( ESP_OK != timer_start(FRAME_REFR_TIMER_GROUP, FRAME_REFR_TIMER) ) {
			printf("Starting timer failed.\n");
		}
	
}

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ISR counter value doesn't seem to have an effect

Postby WiFive » Sat Mar 02, 2019 12:57 pm

isr_param is a stack variable when it should be heap or static/global

lunjius
Posts: 3
Joined: Tue Feb 26, 2019 4:55 pm

Re: ISR counter value doesn't seem to have an effect

Postby lunjius » Sun Mar 03, 2019 12:10 pm

Thank your for your answer!
Would you mind to explain how I can do any of that? I tried to define

Code: Select all

isr_param
right under beneath the struct definition (instead of inside the main function), both with and without a static keyword. It never had an effect on the result.

I also don't see the problem with the current way of doing it. A log of the isr_param over time shows, that isr_param->fade_step properly increases on every ISR. Would you explain what is wrong there?

lunjius

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ISR counter value doesn't seem to have an effect

Postby WiFive » Tue Mar 05, 2019 11:54 am

Code: Select all

alarm_ticks = round(frame_delay_ms * (80000 / (double) frame_timer.divider));

Code: Select all

timer_set_alarm_value(FRAME_REFR_TIMER_GROUP, FRAME_REFR_TIMER, 0);	// set alarm value

lunjius
Posts: 3
Joined: Tue Feb 26, 2019 4:55 pm

Re: ISR counter value doesn't seem to have an effect

Postby lunjius » Tue Mar 05, 2019 10:10 pm

Thank you so much! Feeling stupid for not getting the concept of alarm_value, although it was so simple (in case anyone else struggles: The counter counts down until passing alarm_value, so in my case I want to count from alarm_ticks to 0, not alarm_ticks to alarm_ticks).
Leaving aside that I couldnt calc the alarm_ticks properly...

Who is online

Users browsing this forum: Bing [Bot], ESP_Roland, MicroController, nopnop2002 and 148 guests