AnsweredAssumed Answered

PWM driver for MCF5225x

Question asked by gilles buloz on Nov 11, 2011
Latest reply on Oct 9, 2013 by gilles buloz

Yes, this is another PWM driver for MCF5225x, but when I wrote it no driver was available.

Snce this time a driver was posted on the forum by Myke (https://community.freescale.com/message/69804#69804)

I post mine now in cas it would help.

 

It only has 3 IOCTLs :

- one to init PWM module

- one to init a pin for PWM and set an initial period and duty

- one to update period/duty.

It has been written to drive some fans.

 

To use it :

 

- in  mqx/source/include/ioctl.h , add the following #define
#define IO_TYPE_GPTIN              0xNN
where 0xNN is an unused value for your BSP

- in mqx/source/psp/coldfire/mcf5225.h , in mcf5225_pwm_struct, replace :

    uchar    filler[0xFFDB];   

with

    uchar    filler3;
    uchar    PCME;            // PWM PCM Mode Enable register
    uchar    filler[0xFFD9];

- install the driver source files in mqx/source/io

 

- then use the driver using its simple API :

 

Install driver :
_io_pwm_install("pwm:");

Open device ;
FILE_PTR fdpwm;
if ((fdpwm = fopen("pwm:", NULL )) == NULL) {
  printf("Opening PWM device driver failed.\n");
}

Configure PWM module :
PWM_DEV_CONFIG_DATA pwm_conf_data;
pwm_conf_data.clock_Sys_to_A_divisor = 0;  /* 2**n, 0<=n<=7 */
pwm_conf_data.clock_Sys_to_B_divisor = 0;  /* 2**n, 0<=n<=7 */
pwm_conf_data.clock_A_to_AS_divisor = 60;   /* 2*n, or 512 if n=0 */
pwm_conf_data.clock_B_to_BS_divisor = 60;   /* 2*n, or 512 if n=0 */
if (ioctl(fdpwm, PWM_IOCTL_CONFIG, &pwm_conf_data)) {
  printf("PWM_IOCTL_CONFIG failed.\n");
}

Configure a pin and set initial period and duty cycle :
pwm_pin_data.pwm_pin = 2;         /* 0-7 */
pwm_pin_data.polarity = 1;        /* 1 for active high */
pwm_pin_data.xS_clock_select = 1; /* 1 for AS/BS clock instead of A/B; A for 0,1,4,5 / B for 2,3,6,7 */
pwm_pin_data.center_aligned = 0;  /* 1 for center aligned */
pwm_pin_data.concatenate = 0;     /* 1 to concatenate odd channel n with channel n-1 */
pwm_pin_data.stop_doze = 0;       /* stop PWM in doze mode */
pwm_pin_data.stop_debug = 0;      /* stop PWM in debug mode */
pwm_pin_data.pcm_enable = 0;      /* 1 to use PCM instead of PWM */
pwm_pin_data.period = 200;        /* 0-255, or 0-65535 if concatenate=1 */
pwm_pin_data.duty = 0;            /* 0-period; 0:0%; period:100% */
if (ioctl(fdpwm, PWM_IOCTL_ENABLE_PIN, &pwm_pin_data)) {
  printf("PWM_IOCTL_ENABLE_PIN failed.\n");
}

Change period and duty cycle :
pwm_change_data.pwm_pin = 2;
pwm_change_data.period = 200;
pwm_change_data.duty = 70; /* 35 % PWM (70 for 200) */
if (ioctl(fdpwm, PWM_IOCTL_CHANGE_DUTY, &pwm_change_data)) {
  printf("PWM_DEV_CHANGE_DUTY_DATA failed.\n");
  _mqx_exit(-1);
}


Outcomes