Page 2 of 2

Re: halconf and mcuconf for pwm: #error compile time

Posted: Tue Mar 15, 2016 4:53 pm
by Giovanni
It is a good idea to reduce the tick rate.

Giovanni

Re: halconf and mcuconf for pwm: #error compile time

Posted: Tue Mar 15, 2016 5:45 pm
by enrico.dallavia
So, i have to change
#define CH_CFG_ST_FREQUENCY 10000
to
#define CH_CFG_ST_FREQUENCY 1000

right?

Re: halconf and mcuconf for pwm: #error compile time

Posted: Tue Mar 15, 2016 5:54 pm
by enrico.dallavia
Now that the pwm on TIM2 in working I have a little double about the duty cycle

I need a pwm from 1Hz to 20kHz.
I set the frequency of the timer to 1MHz

Code: Select all

static PWMConfig pwmcfg = {
  1000000,                                    /* 1MHz PWM clock frequency.   */
  50,                                    /* Initial PWM period .       50  is for 20kHz , 1000000 is for 1 Hz*/
  NULL,//no callback
  {
    {PWM_OUTPUT_DISABLED, NULL},//CH 1
    {PWM_OUTPUT_ACTIVE_HIGH, NULL},//CH 2
    {PWM_OUTPUT_DISABLED, NULL},//CH 3
    {PWM_OUTPUT_DISABLED, NULL}//CH 4
  },
  0,
  0
};


with a constant duty cycle of 50%

from the example

Code: Select all

 pwmStart(&PWMD2, &pwmcfg);

 pwmEnableChannel(&PWMD2, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 5000));//DC 50%


the 5000 parameter should be constant, since the formula is
tick = period * 5000/10000
so with period of 50 I need (I suppose) a result of 25 so the argument must be 5000
with a period of 1000000 I need a result of 500000 so the argument must be 5000
but with a 1Hz I got a duty cycle far shorter than 50%. Could it be the result of 500000 causes an overflow of the results?

but the argument of the width is typedef uint32_t pwmcnt_t; so I don't think it is an overflow

Re: halconf and mcuconf for pwm: #error compile time

Posted: Tue Mar 15, 2016 6:04 pm
by enrico.dallavia
I think in my particular case of 50% fixed, I can use:

Code: Select all

pwmStart(&PWMD2, &pwmcfg);

pwmEnableChannel(&PWMD2, 1, pwmcfg.period/2);


it seems to work with an oscilloscope

Re: halconf and mcuconf for pwm: #error compile time

Posted: Tue Mar 15, 2016 6:12 pm
by Giovanni
Even if pwmcnt_t is 32 bits, the timer is not necessarily 32 bits.

Giovanni