Low freq (below 1Hz) PWM / Timers

KanyeKanye
Posts: 54
Joined: Mon Dec 05, 2016 12:34 am

Low freq (below 1Hz) PWM / Timers

Postby KanyeKanye » Sat Sep 21, 2019 7:12 am

I am looking for an example of low frequency (below 1Hz) PWM.
Frequencies below 1Hz are impossible using LEDC driver and it's code (/components/driver/ledc.c) is rather ununderstandable for me.
Technical Reference shows general diagram (page 379) but I do not know exact way to set mentioned registers

My little attempt:

Code: Select all

	// Enable PWM peripheral
	DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_LEDC_CLK_EN);
	DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_LEDC_RST);

	// LEDC_TICK_SEL_HSTIMER0: 0:ref_tick, 1:apb_clk
	// REF_CLK_FREQ=1Mhz(20bit). Division 18bit.
	uint16_t division = (REF_CLK_FREQ >> 4); // Period 16s
	WRITE_PERI_REG(LEDC_HSTIMER0_CONF_REG, LEDC_HSTIMER0_RST | (division<<LEDC_DIV_NUM_HSTIMER0_S) | (8<<LEDC_HSTIMER0_DUTY_RES_S));

	WRITE_PERI_REG(LEDC_HSCH0_CONF0_REG, (1<<LEDC_IDLE_LV_HSCH0) | (1<<LEDC_SIG_OUT_EN_HSCH0));
	WRITE_PERI_REG(LEDC_HSCH0_HPOINT_REG, 0);
	WRITE_PERI_REG(LEDC_HSCH0_DUTY_REG, 0);
	WRITE_PERI_REG(LEDC_HSCH0_CONF1_REG, (LEDC_DUTY_START_HSCH0));

	PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[PIN_NUM_PWM_OUTPUT], PIN_FUNC_GPIO);
	gpio_set_direction(PIN_NUM_PWM_OUTPUT, GPIO_MODE_OUTPUT);
	gpio_matrix_out(PIN_NUM_PWM_OUTPUT, LEDC_HS_SIG_OUT0_IDX, PWM_OUTPUT_INVERTED, 0);

Who is online

Users browsing this forum: Google [Bot], igormoo and 121 guests