Chat freely about anything...

User avatar
By Narasing
#63186
EUA wrote:You need to edit some settings.
For example you need to pin # by::

Code: Select all#define PWM_0_OUT_IO_MUX  PERIPHS_IO_MUX_GPIO2_U
#define PWM_0_OUT_IO_NUM  2
#define PWM_0_OUT_IO_FUNC FUNC_GPIO2
#define PWM_CHANNEL 1

PWM_CHANNEL 1 means you are gonna use only one PWM in your program.

in user_init, you can:
Code: Select alluint8_t duty=0;
pwm_init( 150, &duty);
pwm_start();


Than in anywhere to adjust PWM:

Code: Select allpwm_set_duty(duty, 0);
pwm_start();

You have to run pwm_start function after changing duty cycle.
Otherwise it doesn't run.


Here is sample code:
Code: Select all#include <ets_sys.h>
#include <osapi.h>
#include <os_type.h>
#include <gpio.h>

#include "user_interface.h"

#define user_procTaskPrio        0
#define user_procTaskQueueLen    1
os_event_t    user_procTaskQueue[user_procTaskQueueLen];

// see eagle_soc.h for these definitions
#define PWM_0_OUT_IO_MUX  PERIPHS_IO_MUX_GPIO2_U
#define PWM_0_OUT_IO_NUM  2
#define PWM_0_OUT_IO_FUNC FUNC_GPIO2

#define PWM_CHANNEL 1

LOCAL uint8_t led_state=0;
LOCAL uint8_t duty=0;

//Main code function for heartbeat LED on GPIO2
void ICACHE_FLASH_ATTR
loop(os_event_t *events)
{
    os_delay_us(10000);

   led_state ? duty-- : duty++;

    if (duty >= 255 ) led_state=1;
    else if (duty <= 10 ) led_state=0;

   pwm_set_duty(duty, 0);
   pwm_start();

    system_os_post(user_procTaskPrio, 0, 0 );
}

void user_init(void)
{
   pwm_init( 150, &duty);
    pwm_start();

    //Start os task
    system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);

    system_os_post(user_procTaskPrio, 0, 0 );
}



#include "pwm.h" (in code i added pwm.h lib)
but when i'm using get_pwm_version(); or pwm_start();
or any pwm function then i'm getting following error---
/tmp/ccoG1uRV.ltrans0.ltrans.o:(.literal+0xc0): undefined reference to get_pwm_version' /tmp/ccoG1uRV.ltrans0.ltrans.o:(.literal+0xc4): undefined reference topwm_start'
/tmp/ccoG1uRV.ltrans0.ltrans.o: In function user_init': <artificial>:(.text+0x2c1): undefined reference toget_pwm_version'
:(.text+0x2c7): undefined reference to `pwm_start'
collect2: error: ld returned 1 exit status
make: *** [image.elf] Error 1
User avatar
By Abbiealaric
#71725 I think pwm is utilized as a part of an assortment of utilizations including advanced control hardware. A typical way we utilize them here at SparkFun is to control diminishing of RGB LEDs or to control the heading of a servo engine please let me am i wright?
User avatar
By suzainlian
#72158 in case you join a reasonably excessive-resistance resistor as opposed to the motor and examine the scope hint, what do you spot?
With the motor linked, what does the PWM sign appear like in the scope?
Can the motor motive force run the motor when not connected thru PWM?