Beispiel #1
0
/******************************************************************************
 * FunctionName : pwm_init
 * Description  : pwm gpio, params and timer initialization
 * Parameters   : uint16 freq : pwm freq param
 *                uint16 *duty : each channel's duty
 * Returns      : void
*******************************************************************************/
void ICACHE_FLASH_ATTR
pwm_init(uint16 freq, uint16 *duty)
{
    uint8 i;

    // PIN_FUNC_SELECT(PWM_0_OUT_IO_MUX, PWM_0_OUT_IO_FUNC);
    // PIN_FUNC_SELECT(PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC);
    // PIN_FUNC_SELECT(PWM_2_OUT_IO_MUX, PWM_2_OUT_IO_FUNC);
    // GPIO_OUTPUT_SET(GPIO_ID_PIN(PWM_0_OUT_IO_NUM), 0);
    // GPIO_OUTPUT_SET(GPIO_ID_PIN(PWM_1_OUT_IO_NUM), 0);
    // GPIO_OUTPUT_SET(GPIO_ID_PIN(PWM_2_OUT_IO_NUM), 0);
    
    for (i = 0; i < PWM_CHANNEL; i++) {
        // pwm_gpio |= (1 << pwm_out_io_num[i]);
        pwm_gpio = 0;
        pwm.duty[i] = 0;
    }

    pwm_set_freq(500, 0);
    // pwm_set_freq_duty(freq, duty);

    pwm_start();

    PWM_DBG("pwm_init returning\n");
}
Beispiel #2
0
/******************************************************************************
 * FunctionName : pwm_init
 * Description  : pwm gpio, params and timer initialization
 * Parameters   : uint16 freq : pwm freq param
 *                uint16 *duty : each channel's duty
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
pwm_init(uint16 freq, uint16 *duty)
{
    uint8 i;

    RTC_REG_WRITE(FRC1_CTRL_ADDRESS,  //FRC2_AUTO_RELOAD|
                  DIVDED_BY_16
                  | FRC1_ENABLE_TIMER
                  | TM_EDGE_INT);
    RTC_REG_WRITE(FRC1_LOAD_ADDRESS, 0);

    // PIN_FUNC_SELECT(PWM_0_OUT_IO_MUX, PWM_0_OUT_IO_FUNC);
    // PIN_FUNC_SELECT(PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC);
    // PIN_FUNC_SELECT(PWM_2_OUT_IO_MUX, PWM_2_OUT_IO_FUNC);
    // GPIO_OUTPUT_SET(GPIO_ID_PIN(PWM_0_OUT_IO_NUM), 0);
    // GPIO_OUTPUT_SET(GPIO_ID_PIN(PWM_1_OUT_IO_NUM), 0);
    // GPIO_OUTPUT_SET(GPIO_ID_PIN(PWM_2_OUT_IO_NUM), 0);
    
    for (i = 0; i < PWM_CHANNEL; i++) {
        // pwm_gpio |= (1 << pwm_out_io_num[i]);
        pwm_gpio = 0;
        pwm.duty[i] = 0;
    }

    pwm_set_freq(500, 0);
    // pwm_set_freq_duty(freq, duty);

    pwm_start();
    
    ETS_FRC_TIMER1_INTR_ATTACH(pwm_tim1_intr_handler, NULL);
    TM1_EDGE_INT_ENABLE();
    ETS_FRC1_INTR_ENABLE();
}
Beispiel #3
0
/**
 * PWM configuration.
 *
 * @param  ch    operation channel
 * @return none
 */
void pwm_config(enum pwm_channel ch)
{
	int mdl = pwm_channels[ch].channel;

	/* Disable PWM for module configuration */
	pwm_enable(mdl, 0);

	/* Set PWM heartbeat mode is no heartbeat */
	SET_FIELD(NPCX_PWMCTL(mdl), NPCX_PWMCTL_HB_DC_CTL_FIELD,
			NPCX_PWM_HBM_NORMAL);

	/* Select default CLK or LFCLK clock input to PWM module */
	SET_FIELD(NPCX_PWMCTLEX(mdl), NPCX_PWMCTLEX_FCK_SEL_FIELD,
			NPCX_PWM_CLOCK_APB2_LFCLK);

	/* Set PWM polarity normal first */
	CLEAR_BIT(NPCX_PWMCTL(mdl), NPCX_PWMCTL_INVP);

	/* Select PWM clock source */
	UPDATE_BIT(NPCX_PWMCTL(mdl), NPCX_PWMCTL_CKSEL,
			(pwm_channels[ch].flags & PWM_CONFIG_DSLEEP_CLK));

	/* Set PWM operation frequency */
	pwm_set_freq(ch, pwm_channels[ch].freq, DUTY_CYCLE_RESOLUTION);

}
Beispiel #4
0
/* 
 * sp_init()
 */
void sp_init()
{
    if( cfg.p.frequency < 0 )
        cfg.p.frequency = 0;
    
    pwm_set_freq(PWM_1, cfg.p.frequency);
    pwm_set_duty(PWM_1, cfg.p.phase_off);
}
Beispiel #5
0
void lcd_blt_set_freq(int no,unsigned int freq)
{
	if( lcd_pwm_enable ) return;
#ifdef CONFIG_LCD_BACKLIGHT_WMT
	pwm_set_freq(no,freq);
#endif	
	return;
}
Beispiel #6
0
/*
 * cm_spindle_init()
 */
void cm_spindle_init()
{
	if( pwm.c[PWM_1].frequency < 0 )
		pwm.c[PWM_1].frequency = 0;

    pwm_set_freq(PWM_1, pwm.c[PWM_1].frequency);
    pwm_set_duty(PWM_1, pwm.c[PWM_1].phase_off);
}
Beispiel #7
0
/******************************************************************************
 * FunctionName : user_light_set_duty
 * Description  : set pwm frequency
 * Parameters   : uint16 freq : 100hz typically
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_light_set_freq(uint16 freq)
{
    if (freq != light_param.pwm_freq) {
        pwm_set_freq(freq);

        light_param.pwm_freq = pwm_get_freq();
    }
}
Beispiel #8
0
/******************************************************************************
 * FunctionName : pwm_set_freq_duty
 * Description  : set pwm frequency and each channel's duty
 * Parameters   : uint16 freq : 100hz typically
 *                uint8 *duty : each channel's duty
 * Returns      : NONE
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
pwm_set_freq_duty(uint16 freq, uint8 *duty)
{
    uint8 i;

    pwm_set_freq(freq);

    for (i = 0; i < PWM_CHANNEL; i++) {
        pwm_set_duty(duty[i], i);
    }
}
Beispiel #9
0
// Set the PWM clock
uint32_t platform_pwm_set_clock( unsigned pin, uint32_t clock )
{
  // NODE_DBG("Function platform_pwm_set_clock() is called.\n");
  if( pin >= NUM_PWM)
    return 0;
  if(!pwm_exist(pin))
    return 0;

  pwm_set_freq((uint16_t)clock, pin);
  pwm_start();
  return (uint32_t)pwm_get_freq( pin );
}
Beispiel #10
0
/* initialize the motor driver. */
void motor_init() {
   // pwm pin as output
   DDRL |= (1 << 3) | (1 << 4) | (1 << 5);
   DDRL &= ~( (1 << 6) | (1 << 7) );

   PORTL |= (1 << 5);

   // motor pwm setup
   pwm_init(PWM16);
   pwm_set_freq(5, 10000); // 10kHz frequency
   pwm_set_duty(PWM16, 0.0);

}
Beispiel #11
0
/******************************************************************************
 * FunctionName : pwm_set_freq_duty
 * Description  : set pwm frequency and each channel's duty
 * Parameters   : uint16 freq : 100hz typically
 *                uint16 *duty : each channel's duty
 * Returns      : NONE
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
pwm_set_freq_duty(uint16 freq, uint16 *duty)
{
    uint8 i;

    pwm_set_freq(freq, 0);

    for (i = 0; i < PWM_CHANNEL; i++) {
        // pwm_set_duty(duty[i], i);
        if(pwm_out_io_num[i] != -1)
            pwm_set_duty(duty[i], pwm_out_io_num[i]);
    }
}
void ICACHE_FLASH_ATTR
peri_motor_double_set( struct PWM_APP_PARAM motor_param)
{
    pwm_set_freq(motor_param.pwm_freq);
    pwm_set_duty(motor_param.pwm_duty[0], 0);
    pwm_set_duty(motor_param.pwm_duty[1], 1);
   // pwm_set_duty(motor_param.pwm_duty[2], 2);

    pwm_start();

//    spi_flash_erase_sector(PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE);
//	spi_flash_write((PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE,
//	    (uint32 *)&motor_param, sizeof(struct PWM_APP_PARAM));
}
void ICACHE_FLASH_ATTR 
peri_rgb_light_param_set( struct LIGHT_PARAM light_param)
{
    pwm_set_freq(light_param.pwm_freq);
    pwm_set_duty(light_param.pwm_duty[0], 0); // red colour.
    pwm_set_duty(light_param.pwm_duty[1], 1); // green colour.
    pwm_set_duty(light_param.pwm_duty[2], 2); // blue colour.
    
    pwm_start();
    
    spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE);
	spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE,
	    (uint32 *)&light_param, sizeof(struct LIGHT_PARAM));
}
Beispiel #14
0
int main(void)
{
	init();

	pwm_start(&pwm1);
	sys_spin(2); // adds a phase shift that should go away in SYNC mode
	pwm_start(&pwm0);
	pwm_start(&pwm3);
	pwm_set_freq(&pwm3, 50000); // test overriding hw.c freq and ensure pwm2 updates duty too
		
	while (1)
	{}

	return 0;
}
Beispiel #15
0
/*
 * cm_spindle_init()
 */
void cm_spindle_init()
{
	if( pwm.c[PWM_1].frequency < 0 )
		pwm.c[PWM_1].frequency = 0;

    pwm_set_freq(PWM_1, pwm.c[PWM_1].frequency);
    pwm_set_duty(PWM_1, pwm.c[PWM_1].phase_off);
    
	// make sure spindle is turned off at init
	if (cm.gm.spindle_active_dir == SPINDLE_ACTIVE_LOW) {
		gpio_set_bit_on(SPINDLE_BIT);	
	} else {
		gpio_set_bit_off(SPINDLE_BIT);	
	}

}
static long mini2451_pwm_ioctl(struct file *filep, unsigned int cmd,
		unsigned long arg)
{
	switch (cmd) {
		case PWM_IOCTL_SET_FREQ:
			if (arg == 0)
				return -EINVAL;
			pwm_set_freq(arg);
			break;

		case PWM_IOCTL_STOP:
		default:
			pwm_stop();
			break;
	}

	return 0;
}
Beispiel #17
0
void
app_demo(void)
{
    uint16_t adc_result = avg_get(&(app.adc_avg)) << 4;

    if (tick_is_expired(&(app.adc_tick))) {
        app.adc_tick = tick_from_ms(1);

        avg_moving(&(app.adc_avg), adc_sample(ADC_0));
    }

    if (tick_is_expired(&(app.tlc5971_tick))) {
        app.tlc5971_tick = tick_from_ms(50);

        //for (i=0; i<12; i++) {
        //    app.bgr_buf[i] = adc_result;
        //}
        tlc5971_show(&(app.bgr_buf[0]), 4);
        //tlc5971_testpattern(&(app.bgr_buf[0]), 12);

        tlc5971_set_bgr(&(app.tlc), &(app.bgr_buf[0]));

        gpio_toggle(GPIO_LED_R);

        //max31855_read(&app.max31855);
    }

    if (tick_is_expired(&(app.servo_tick))) {
        app.servo_tick = tick_from_ms(30);

        /* Small deadband */
        /* TODO: Add deadband to PWM? */
        if ((adc_result > servo_last+16) || (adc_result < servo_last-16)) {
            pwm_set_freq(&(app.pwm_servo), 50000+(((190000-50000)/0xFFFF)*adc_result));
            servo_last = adc_result;
        }
    }

    if (tick_is_expired(&(app.lcd_tick))) {
        app.lcd_tick = tick_from_ms(500);
        serlcd_set_cursor(&(app.serlcd), SERLCD_ROW1_POS);
        serlcd_print_decimal(&(app.serlcd), adc_result);
    }
}
uint32_t platform_pwm_setup( unsigned pin, uint32_t frequency, unsigned duty )
{
  uint32_t clock;
  if ( pin < NUM_PWM)
  {
    platform_gpio_mode(pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT);  // disable gpio interrupt first
    if(!pwm_add(pin)) 
      return 0;
    // pwm_set_duty(DUTY(duty), pin);
    pwm_set_duty(0, pin);
    pwms_duty[pin] = duty;
    pwm_set_freq((uint16_t)frequency, pin);
  } else {
    return 0;
  }
  clock = platform_pwm_get_clock( pin );
  pwm_start();
  return clock;
}
Beispiel #19
0
void user_init(void)
{
    uint8_t pins[1];
    uart_set_baud(0, 115200);

    printf("SDK version:%s\n", sdk_system_get_sdk_version());

    printf("pwm_init(1, [14])\n");
    pins[0] = 14;
    pwm_init(1, pins);

    printf("pwm_set_freq(1000)     # 1 kHz\n");
    pwm_set_freq(1000);

    printf("pwm_set_duty(UINT16_MAX/2)     # 50%%\n");
    pwm_set_duty(UINT16_MAX/2);

    printf("pwm_start()\n");
    pwm_start();

    xTaskCreate(task1, (signed char *)"tsk1", 256, NULL, 2, NULL);
}
Beispiel #20
0
int main(int ac, char** av)
{
  unsigned int i = 0;
  pwm_t pwm;

  if (pwm_init(&pwm) == -1)
  {
    return -1;
  }

  if (pwm_mux_init() == -1)
  {
    pwm_fini(&pwm);
    return -1;
  }

  pwm_disable(&pwm);
  pwm_set_clk_div(&pwm, (unsigned int)(19200000.0 / 19200.0));
  pwm_set_freq(&pwm, 500);
#if 0
  /* problem */
  pwm_mux_sel(0);
#else
  /* no problem */
  pwm_mux_sel(1);
#endif

  while (1)
  {
    static unsigned int i = 0;
    unsigned int delay_us;
    /* const char c = getchar(); */
    static const char fu[] = { 'l', 'r' };
    const char c = fu[(++i) & 1];
    unsigned int do_pwm = 0;
    if (c == 'l')
    {
      printf("-- l\n");
      pwm_set_duty(&pwm, 39);
      delay_us = 50000;
/*       delay_us = 10000; */
      do_pwm = 1;
    }
    else if (c == 'r')
    {
      printf("-- r\n");
      pwm_set_duty(&pwm, 10);
      delay_us = 10000;
      do_pwm= 1;
    }

    if (do_pwm)
    {
      pwm_enable(&pwm);
      usleep(delay_us);
      pwm_disable(&pwm);
      usleep(1000000);
    }
  }

  pwm_mux_fini();
  pwm_fini(&pwm);

  return 0;
}