[ell-i-developers] PWM configuration

  • From: Ivan Raul <supra.material@xxxxxxxxx>
  • To: ell-i-developers@xxxxxxxxxxxxx
  • Date: Fri, 24 Jan 2014 14:33:27 +0200

Dear all.

I've been working with the testing of the PWM at the new runtime (ell-i-new
branch).

After solving the addressing problem of:

@ellduino_timer.c

# define D16(p, r, v) [offsetof(p, r)/2] = { v }

and reordering the declarations of the initialisation records:

@arduelli_timer.h

for obtaining the adequate order at the .hex file (shown by the nm command)

@sketch.lst

080003dc <TIM2_RCC_INIT>:
080003ec <TIM2_INIT1>:
080003fc <TIM2_INIT>:

the pwm still doesn't work.

In particular, I'm playing with the B3 pin (pin 13 in arduino), that
directly connects with the TIM2 Channel 2.

I've tried to initialize the timer manually, accessing the registers
directly.

Some highlights are that the TIM2 doesn't have a BDTR register, that the
initialization procedure tries to write. In the datasheet, it is regarded
as reserved. That register has the offset 0x44, and is mainly used for
advanced timers, like TIM1.

Another interesting point is that TIM2 in particular is able to count in 32
bits. For that reason, the CNT, ARR, and  CCRx registers are 32 bits.
Regarding that, it is true that after the initialization with 16bits
initialization routines, the ARR register does not have the desired value,
as the MSB are loaded with garbage.

For the reasons before, I tried to configure it by accessing the registers
directly. I had have no success. Another interesting fact is that in the
datasheet (reference manual) of the MCU (page 370), it is specified that
for PWM mode an update should be generated to update the real registers
(ARR), because it is double buffered.

The update is generated by writing the EGR register:

    TIM2->EGR |= TIM_EGR_UG;

Still, the system doesn't activate the timer. The counter stays at 0 all
the time.

I will continue by isolating the code to try to activate the timer by hand,
and then port that configuration to the initialization records.


With Warm Regards, Ivan Raul

Other related posts: