Page 1 of 1

Fastest clock generated by GPIO

Posted: Mon Jul 15, 2019 2:10 am
by whoyoume
Hello people,

I think a clock 2.66MHz would be too slow which is generated by a code shown below, under the condition of 240MHz CPU.

Q1. Is it too slow?
Q2. If so, could anybody show source code for faster?

Thank you.

void test(void)
{
gpio_set_direction(22, GPIO_MODE_OUTPUT);
gpio_set_direction(23, GPIO_MODE_OUTPUT); // LED

PORT |= (1 << 23);
vTaskDelay(1000 / portTICK_RATE_MS);
PORT &= ~(1 << 23);

portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
portENTER_CRITICAL(&mutex);

tag_loop:
PORT |= (1 << 22);
PORT &= ~(1 << 22);
goto tag_loop;

portEXIT_CRITICAL(&mutex);
}

void app_main()
{
test();
}

Re: Fastest clock generated by GPIO

Posted: Mon Jul 15, 2019 2:44 am
by WiFive
There are many topics about this, for a clock you can use ledc. If you are trying to do something else you can use rmt, ulp, or high level ints.

Re: Fastest clock generated by GPIO

Posted: Mon Jul 15, 2019 3:03 am
by username
I get 10mhz doing this.

Code: Select all

void app_main()
{
	gpio_pad_select_gpio(BLINK_GPIO);
	gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
	
	
	while (1)
	{
		GPIO.out_w1ts = (1 << BLINK_GPIO);
		GPIO.out_w1tc = (1 << BLINK_GPIO);
	}


}

Re: Fastest clock generated by GPIO

Posted: Tue Jul 16, 2019 5:54 pm
by whoyoume
Thank you for your advice. I've got 9.908MHz.