PWM on Atmega256rfr2

Hi,

I recently started using RIOT OS for my Bachelor Thesis. My first task is to implement the pwm periphal in order to use it with an rgb led. And that already is where my problems start: I don’t understand how the functions in pwm.h are supposed to work and therefore can’t implement them in my pwm.c.

Can anybody provide more information than the comments in the pwm.h?

Any help will be appriciated.

Best regards,

Steffen

Hi Steffen,

Have you taken a look at existing implementations? For instance, the PWM driver for the STM32 [1, 2]?

  • The pwm_init enables the PWM peripheral, given a frequency and resolution. Frequency and resolution relate [3].
  • The number of available channels is returned by pwm_channels. Many MCUs have multiple channels (outputs) for one timer/counter.
  • A value is set via pwm_set.
  • The pwm_start/pwm_stop should start/stop the PWM, without disabling the peripheral.
  • The pwm_poweron/pwm_poweroff should power-on/power-off the peripheral.

Hi,

thanks for your response. Now i got all basic features to work. But I still have a Question:

In [1] pwm_config is initialized as a const. On the atmega256rfr2 i would need to save the calculated prescaler, so i can set it again on pwm_start() since there isn’t a enable bit. The only way I know of is to disconnect the clock on pwm_stop() and then to enable it using the prescaler, calculated on pwm_init() again on pwm_start(). Therefore i would add another field to the struct and couldn’t use it as a const anymore. Is this a valid approach or is there a different preferred way?

Thanks,

Steffen Robertz

Just a quick fix. I forgot to put the link in:

[1] https://github.com/RIOT-OS/RIOT/blob/master/boards/stm32f3discovery/include/periph_conf.h#L126-L147