Added PWM diagnostic messages and chip-specific maximum duty resolution
This commit is contained in:
parent
7469ab8a93
commit
6c9bf39f54
|
|
@ -31,6 +31,7 @@
|
|||
#include <WiFi.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <esp_ota_ops.h>
|
||||
#include <driver/ledc.h>
|
||||
|
||||
#include "HomeSpan.h"
|
||||
#include "HAP.h"
|
||||
|
|
@ -107,6 +108,9 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
|||
Serial.print(ARDUINO_VARIANT);
|
||||
#endif
|
||||
|
||||
Serial.printf("\nPWM Resources: %d channels, %d timers, max %d-bit duty resolution",
|
||||
LEDC_SPEED_MODE_MAX*LEDC_CHANNEL_MAX,LEDC_SPEED_MODE_MAX*LEDC_TIMER_MAX,LEDC_TIMER_BIT_MAX-1);
|
||||
|
||||
Serial.print("\nSketch Compiled: ");
|
||||
Serial.print(__DATE__);
|
||||
Serial.print(" ");
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ LedC::LedC(uint8_t pin, uint16_t freq){
|
|||
timerList[nTimer][nMode]->timer_num=(ledc_timer_t)nTimer;
|
||||
timerList[nTimer][nMode]->freq_hz=freq;
|
||||
|
||||
int res=20; // find the maximum possible resolution
|
||||
int res=LEDC_TIMER_BIT_MAX-1; // find the maximum possible resolution
|
||||
while(getApbFrequency()/(freq*pow(2,res))<1)
|
||||
res--;
|
||||
|
||||
|
|
@ -51,7 +51,16 @@ LedPin::LedPin(uint8_t pin, float level, uint16_t freq) : LedC(pin, freq){
|
|||
|
||||
if(!channel)
|
||||
Serial.printf("\n*** ERROR: Can't create LedPin(%d) - no open PWM channels and/or Timers ***\n\n",pin);
|
||||
|
||||
else
|
||||
Serial.printf("LedPin=%d: mode=%d channel=%d, timer=%d, freq=%d Hz, resolution=%d bits\n",
|
||||
channel->gpio_num,
|
||||
channel->speed_mode,
|
||||
channel->channel,
|
||||
channel->timer_sel,
|
||||
timer->freq_hz,
|
||||
timer->duty_resolution
|
||||
);
|
||||
|
||||
set(level);
|
||||
|
||||
}
|
||||
|
|
@ -135,7 +144,16 @@ ServoPin::ServoPin(uint8_t pin, double initDegrees, uint16_t minMicros, uint16_t
|
|||
|
||||
if(!channel)
|
||||
Serial.printf("\n*** ERROR: Can't create ServoPin(%d) - no open PWM channels and/or Timers ***\n\n",pin);
|
||||
|
||||
else
|
||||
Serial.printf("ServoPin=%d: mode=%d channel=%d, timer=%d, freq=%d Hz, resolution=%d bits\n",
|
||||
channel->gpio_num,
|
||||
channel->speed_mode,
|
||||
channel->channel,
|
||||
channel->timer_sel,
|
||||
timer->freq_hz,
|
||||
timer->duty_resolution
|
||||
);
|
||||
|
||||
this->minMicros=minMicros;
|
||||
this->maxMicros=maxMicros;
|
||||
this->minDegrees=minDegrees;
|
||||
|
|
|
|||
|
|
@ -11,12 +11,6 @@
|
|||
// ServoPin(pin) - controls a Servo Motor on specified pin with frequency=50 Hz
|
||||
// - use set(degrees) to set position to degrees
|
||||
//
|
||||
// Max number of LedPin instantiations: 16
|
||||
// Max number of ServoPin instantiatons: 8
|
||||
// Max combined limit (LedPins+ServoPins): 16
|
||||
//
|
||||
// Instantiation of an LedPin or ServoPin that causes any of the maximums above to be exceeded throws
|
||||
// an error message. The object will still be created, but calls to set(level) or set(degrees) are ignored.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ void setup(){
|
|||
LedPin led1(19,100,2000);
|
||||
LedPin led2(16,10,80000);
|
||||
LedPin led3(17,100,2000);
|
||||
LedPin led4(23);
|
||||
LedPin led4(23,100,2);
|
||||
LedPin led5(22,0,3000);
|
||||
LedPin led6(14,0,1);
|
||||
LedPin led7(32,0,1850);
|
||||
|
|
@ -37,15 +37,15 @@ void setup(){
|
|||
led14.set(100);
|
||||
|
||||
Serial.println(led0.getPin());
|
||||
Serial.println(led14.getPin());
|
||||
Serial.println(led15.getPin());
|
||||
Serial.println(led16.getPin());
|
||||
// Serial.println(led14.getPin());
|
||||
// Serial.println(led15.getPin());
|
||||
// Serial.println(led16.getPin());
|
||||
|
||||
uint32_t v=REG_READ(LEDC_HSTIMER0_CONF_REG);
|
||||
Serial.printf("HS %d %d %d %d\n",(v>>25)&1,v&0x1f,(v>>13)&0x3FF,(v>>5)&0xFF);
|
||||
// uint32_t v=REG_READ(LEDC_HSTIMER0_CONF_REG);
|
||||
// Serial.printf("HS %d %d %d %d\n",(v>>25)&1,v&0x1f,(v>>13)&0x3FF,(v>>5)&0xFF);
|
||||
|
||||
v=REG_READ(LEDC_LSTIMER0_CONF_REG);
|
||||
Serial.printf("LS %d %d %d %d %d\n",(v>>25)&1,v&0x1f,(v>>13)&0x3FF,(v>>5)&0xFF,REG_READ(LEDC_CONF_REG));
|
||||
// v=REG_READ(LEDC_LSTIMER0_CONF_REG);
|
||||
// Serial.printf("LS %d %d %d %d %d\n",(v>>25)&1,v&0x1f,(v>>13)&0x3FF,(v>>5)&0xFF,REG_READ(LEDC_CONF_REG));
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue