User avatar
By de1m
#54492 I wrote this example, but I've a problem:
Code: Select all
#define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U //R -Red
#define PWM_1_OUT_IO_NUM 13
#define PWM_1_OUT_IO_FUNC FUNC_GPIO15

#define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_GPIO4_U //G - Green
#define PWM_2_OUT_IO_NUM 4
#define PWM_2_OUT_IO_FUNC FUNC_GPIO4

#define PWM_3_OUT_IO_MUX PERIPHS_IO_MUX_GPIO5_U //B - Blue
#define PWM_3_OUT_IO_NUM 5
#define PWM_3_OUT_IO_FUNC FUNC_GPIO5

#define PWM_CHANNEL 3
int ledinvert = 1; //1 = (+); 0 = (-)

uint32 duty[] = {0, 0, 0};
uint32 freq = 1000;

uint32 io_info[][3] = {
  {PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC, PWM_1_OUT_IO_NUM},
  {PWM_2_OUT_IO_MUX, PWM_2_OUT_IO_FUNC, PWM_2_OUT_IO_NUM},
  {PWM_3_OUT_IO_MUX, PWM_3_OUT_IO_FUNC, PWM_3_OUT_IO_NUM}
};

     pwm_init(freq, duty, 3, io_info);
     uint8 test[3] = {100, 0, 0};
     //pwm_write(test);
     pwm_set_duty(10, 0);
     pwm_set_duty(22222, 1);
     pwm_set_duty(0, 2);
   pwm_start();


If I use as a value of "pwm_set_dyty" 0 or 22222 its working, but if I choose (show "pwm_set_duty(10,0) a value between 0 and 22222, the value of duty jump to 22222.
Can you maybe provide a working example?
I think my code is wrong.
User avatar
By de1m
#54510
eriksl wrote:These defines are correct (according to eagle_soc.h).

Can you give some context of how you call pwm_init and pwm_start?


I define this at the beginning of user_main.c
Code: Select all#define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U //R -Red
#define PWM_1_OUT_IO_NUM 13
#define PWM_1_OUT_IO_FUNC FUNC_GPIO15

#define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_GPIO4_U //G - Green
#define PWM_2_OUT_IO_NUM 4
#define PWM_2_OUT_IO_FUNC FUNC_GPIO4

#define PWM_3_OUT_IO_MUX PERIPHS_IO_MUX_GPIO5_U //B - Blue
#define PWM_3_OUT_IO_NUM 5
#define PWM_3_OUT_IO_FUNC FUNC_GPIO5

#define PWM_CHANNEL 3
int ledinvert = 1; //1 = (+); 0 = (-)

uint32 duty[] = {0, 0, 0};
uint32 freq = 1000;

uint32 io_info[][3] = {
  {PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC, PWM_1_OUT_IO_NUM},
  {PWM_2_OUT_IO_MUX, PWM_2_OUT_IO_FUNC, PWM_2_OUT_IO_NUM},
  {PWM_3_OUT_IO_MUX, PWM_3_OUT_IO_FUNC, PWM_3_OUT_IO_NUM}
};


and then I call this in user_init function:
Code: Select all     pwm_init(freq, duty, 3, io_info);
     uint8 test[3] = {100, 0, 0};
     //pwm_write(test);
     pwm_set_duty(10, 0);
     pwm_set_duty(22222, 1);
     pwm_set_duty(0, 2);
     pwm_start();

For example, if I set only one channel duty to 10, then all channels will be jumping to 22222.
I've a "inverted" LED, it's mean 22222 is OFF and 0 is ON.
I can enable the DEBUG in pwm.c, but not now (I'm at work)
User avatar
By eriksl
#54516 Using a duty cycle of 22222 suggests you want to use a 15 bit (max 32767) or 16 bit (max 65535) range. With this pwm implementation, you need to set the period accordingly, to either 32768 or 65536, not 1000. And of course do not #define the compatibility mode definitions. At least I couldn't get it working.