Init 7 seg display on esp32 gpios

McHarett
Posts: 1
Joined: Tue Jun 29, 2021 5:08 pm

Init 7 seg display on esp32 gpios

Postby McHarett » Tue Jun 29, 2021 5:22 pm

How can I run a seven-segment indicator on gpio esp32 without using additional ICs at 2000 Hz and above?
I tried to use the xtensa timer, but the indication was not work at frequencies more than 1500 Hz.

Enabled: wi fi, web server, adc, ssl connection.
Chip: ESP32 Pico D4 @ 240 MHz

Timer initialization example:

Code: Select all

#define TIMER_DIVIDER         	(80)   
#define TIMER_ALARM_VALUE		1000   
timer_config_t config = {
    .divider = TIMER_DIVIDER,
    .counter_dir = TIMER_COUNT_UP,
    .counter_en = TIMER_START,
    .alarm_en = TIMER_ALARM_EN,
    .auto_reload = TIMER_AUTORELOAD_EN,
}; 
timer_init(TIMER_GROUP_0, TIMER_0, &config);

timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0x00000000ULL);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, TIMER_ALARM_VALUE); 

timer_enable_intr(TIMER_GROUP_0, TIMER_0);
timer_isr_register(TIMER_GROUP_0, TIMER_0, timer_group0_isr,
                    NULL, ESP_INTR_FLAG_IRAM, NULL);
Timer interrupt handler example:

Code: Select all

void IRAM_ATTR timer_group0_isr(void *para){


    portMUX_TYPE timeCriticalMutex = portMUX_INITIALIZER_UNLOCKED;
    portENTER_CRITICAL(&timeCriticalMutex);

    /* 7 seg digit select and port write */

	timer_group_enable_alarm_in_isr(TIMER_GROUP_0, TIMER_0);
	timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, TIMER_0);

	ets_delay_us(10);

	portEXIT_CRITICAL(&timeCriticalMutex);

}

pratik2440
Posts: 25
Joined: Mon Jun 28, 2021 4:55 am

Re: Init 7 seg display on esp32 gpios

Postby pratik2440 » Wed Jun 30, 2021 3:13 pm

Curious, why do you have the 10us delay in the ISR?
The ESP32 has some significant interrupt latency, but 2 kHz should not be a big deal.

For something like this, you could probably use I2S parallel data output mode (Espressif calls it "LCD Master Transmitting mode" in the Technical Reference Manual. It can simply output data constantly via DMA and you can just write to the circular DMA buffer to change common pins and digit segments. You will not need to handle any ISR using this method and output data rate will be quite constant.
Hobbyist and electronic design consultant! (https://PCBArtists.com/)

Victoria Nope
Posts: 75
Joined: Fri Dec 04, 2020 9:56 pm

Re: Init 7 seg display on esp32 gpios

Postby Victoria Nope » Wed Jun 30, 2021 4:54 pm

For LED PWM control one can use the LED Control peripheral.

User avatar
mbratch
Posts: 302
Joined: Fri Jun 11, 2021 1:51 pm

Re: Init 7 seg display on esp32 gpios

Postby mbratch » Thu Jul 01, 2021 2:13 am

Can you clarify the configuration a little further? How many 7-segment digits are you driving? Just one, or more? Is the 2kHz the total cycle time you're trying to achieve for all digits? Why does it need to be that high?

Who is online

Users browsing this forum: No registered users and 63 guests