LEDC: The values of "ledc_timer_bit_t"

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

LEDC: The values of "ledc_timer_bit_t"

Postby kolban » Sun May 14, 2017 3:48 pm

While studying LEDC, I was looking at the "ledc_timer_bit_t". This has a set of predefined values of:
  • LEDC_TIMER_10_BIT
  • LEDC_TIMER_11_BIT
  • LEDC_TIMER_12_BIT
  • LEDC_TIMER_13_BIT
  • LEDC_TIMER_14_BIT
  • LEDC_TIMER_15_BIT
These are used to determine the granularity of the counter within the period cycle. For example, if I have a 10 bit granularity, the counter increments from 0 to 1023 and then resets. Since the clock speed is 80MHz this gives a maximum frequency of 78.125KHz (80MHz/1024) with a clock divisor of 1. However, what I want is a 10MHz frequency and that would appear to be too high.

Hunting around, I found this fragment of source:

https://github.com/igrr/esp32-cam-demo/ ... era.c#L100

... and working backwards from there, I find that the defined values for "ledc_timer_bit_t" are actually simple numerics giving:
  • LEDC_TIMER_10_BIT = 10
  • LEDC_TIMER_11_BIT = 11
  • LEDC_TIMER_12_BIT = 12
  • LEDC_TIMER_13_BIT = 13
  • LEDC_TIMER_14_BIT = 14
  • LEDC_TIMER_15_BIT = 15
Looking at the fragment sample from Ivan, it then dawned on me that these values for LEDC APIs might not be the **only** allowable values and that we can go lower!!

Am I on a good path here? Is there some merit in using low bit numbers ... for example, to achieve high frequency / low granularity (eg. a high speed square wave).

For example ... (and this is theory) ...

A bit size of 3 would seem to give me 10MHz period?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Sprite
Posts: 9769
Joined: Thu Nov 26, 2015 4:08 am

Re: LEDC: The values of "ledc_timer_bit_t"

Postby ESP_Sprite » Mon May 15, 2017 1:39 am

Yes, from memory all values from 1 bit and up should work.

qjones
Posts: 15
Joined: Sun Feb 19, 2017 12:17 am

Re: LEDC: The values of "ledc_timer_bit_t"

Postby qjones » Thu May 18, 2017 11:34 pm

I have a question somewhat in reference to this. I am aware that recently there has been an implementation of the Low Speed Timer portion of the LEDC driver. I am curious as I have not exactly seen any use cases yet of what exactly this feature does vs the High Speed Timer modes? Does this also let you get different resolutions and speed ranges for a given timer bit count? Sorry for maybe a basic question as I have not gotten a chance to play with this yet since the updates.

Thanks,

Who is online

Users browsing this forum: Corand, Google [Bot], MicroController and 102 guests