Error in example: Buzzer with PWM


#1

Hello.
I’ve cloned the PWM sample for testing in ESP32 DevKitC, but the message appears:
[error] Can´t find name [This board does not support such pin function! D8.PWM] in [] at line 16
In the device pins, this pin (D8) is free to use.
How to solve ?


#2

Hi,
this incorrect behaviour is due to a bug. We have already solved it and the fix will be available in the next patch.

However please note that pins from D6 to D11 included are used by the esp32 internal flash and, as reported in the Zerynth pin map should not be used. 


#3

Hi cesarbudaye,

the new patch is out:
https://community.zerynth.com/discussion/550/patch-p02-for-zerynth-r2-0-10-is-available-with-support-for-nodemcu-esp-32s-and-bug-fixes

Enjoy!


#4

Hi,
PWM in test D2 not work.


#5

I did download, update, register, virtualize, recompile the buzzer example in D2, but it did not work.


#6

Hi cesarbudaye,

after you download and install the new rolling updates, you have also to create again the virtual machine for your ESP32 DevKitC (don’t worry the number of consumed free VMs doesn’t increase).

Virtualizing again the ESP32 DevKitC with the new VM, you should be enabled to use D2.PWM function without problems.

Let me know if this can help you :slight_smile:


#7

It worked! Thank you for your patience with me.
Now I go to the next stage of the project.


#8

Hi.
At low frequencies it is working.
But I’m going to need a 12MHz clock signal from another chip. So I tried this code, but it failed. Is this possible?

import streams
import pwm

#create a serial port stream with default parameters  
streams.serial()
SAMpin = D2.PWM 
pinMode(SAMpin,OUTPUT)
frequency=12000000

while True:
    period=1000000000//frequency
    print(“frequency is”, frequency,“Hz”)
    pwm.write(SAMpin,period,period//2,NANOS)

    sleep(1000) 

Error in console:

frequency is 12000000 Hz
Guru Meditation Error of type IntegerDivideByZero occurred on core  0. Exception was unhandled.
Register dump:
PC      : 0x40151f58  PS      : 0x00060a30  A0      : 0x80151dec  A1      : 0x3ffd6400  
A2      : 0x00000000  A3      : 0x00002f10  A4      : 0x00000000  A5      : 0x00000000  
A6      : 0xffffffff  A7      : 0x00000002  A8      : 0x00000000  A9      : 0x00000053  
A10     : 0xffffffff  A11     : 0x00000000  A12     : 0x00000053  A13     : 0x00000005  
A14     : 0xc003ff10  A15     : 0x00000024  SAR     : 0x00000008  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x40151e64  LEND    : 0x40151e72  LCOUNT  : 0x00000000  
Backtrace: 0x40151f58:0x3ffd6400 0x40151de9:0x3ffd6450 0x400e2b8d:0x3ffd64a0 0x400df6fd:0x3ffd6500 0x400df712:0x3ffd6520 0x400d0d5a:0x3ffd6540
Rebooting…



#9

Hi cesarbudaye,

The PWM driver for ESP32 devices allows at most a microsecond resolution.
We have in pipeline to expand this resolution to nanoseconds; in the meantime, you can check and modify the vhal_pwm.c under “~/zerynth2/vhal/xtensa-lx6/esp32/” folder to call the low-level esp32 sdk functions.

Stay tuned :slight_smile:


#10
Hi
I do not know how to program in low level, so I'll wait for the next updates.
I tried in MICROS and 20khz, but I also could not.
I'm going to need these high frequencies, so I'll wait.


import streams
import pwm

#create a serial port stream with default parameters  
streams.serial()
SAMpin = D2.PWM 
pinMode(SAMpin,OUTPUT)
frequency=20000

while True:
    period=1000000//frequency
    print("frequency is", frequency,"Hz")
    pwm.write(SAMpin,period,period//2,MICROS)

    sleep(1000) 

#11

Hello.
I did the p3 upgrade but it still did not work.
Here is the code and the error.
If anyone knows how to solve this, please help me.

import streams
import pwm

streams.serial()
SAMpin = D2.PWM 
pinMode(SAMpin,OUTPUT)
frequency=3000

while True:
    try:
        period=1000000//frequency
        print(“frequency is”, frequency,“Hz”)
        pwm.write(SAMpin,period,period//2,MICROS)
    except Exception as e:
        print(e)
    sleep(1000) 

console error:
frequency is 3000 Hz
E (60519) ledc: requested frequency and bit depth can not be achieved, try reducing freq_hz or bit_num. div_param=208
InvalidHardwareStatusError @[0033:001D:0000:005F:0000:0000:0000:0000]


#12

p4 upgrade = same limit.
No clock or audio frequencies.


#13

Hi cesarbudaye,

unfortunately not :s
We understand your need and we have reported adding this feature on esp32 devices in pipeline but I cannot sure if this will be included in the next patch.

Please be patient and stay tuned :slight_smile: