cancel
Showing results for 
Search instead for 
Did you mean: 

PWM generation using ARTIMER

info47
Associate II
Posted on March 31, 2003 at 21:33

PWM generation using ARTIMER

4 REPLIES 4
info47
Associate II
Posted on March 30, 2003 at 22:36

Hi Forum,

I have the following problem: I try to use the ARTIMER of ST6230B for PWM generation. But after reading the databook and every application note I found I was not succesful in finding the correct parameters and settings for the timer.

For example the databook specifies that the PWM frequency is determined by the clock frequency, the prescaler and the RLCP register (Tpwm=(RLCP+1) x Psc x Tclk). If I try to set it to 100kHz I calculated RLCP to 79 (Fclock=8MHz). The result was a frequency of 31,25kHz. (!?!) I feel anything is going wrong!

It would be very helpful if anybody could help me with the correct settings of the ARTIMER registers (MASK, CMP, CP, RCLP, SCRx) for my PWM problem (frequency fixed 100kHz, duty variable from 10%...90%, Fclk=8MHz).

Thanks in advance for your help!

Regards,

Leines
the2nd
Associate II
Posted on March 31, 2003 at 11:54

You have to determine the values of following registers: rc (RLCP), cp (CMP), sc1 (SCR1) and finally mc (MASK). At the most cases you don't need to set the value of sc0.

First determine the frequency.

Fpwm=Fin/(256-RLCP)

Fin=fosc/prescaler

To calculate the prescaler ratio use the following table:

Bit 0 SC1Bit 7 SC1Bit 6 SC1Bit 5 SC1Prescaler Ratio

00001

00012

00104

00118

010016

010132

011064

0111128

10003

10016

101012

101124

110048

110196

1110192

1111384

To become 100kHz you can choose the prescaler ratio of 2, that makes

ldi SCR1, 20h (set the 5th bit).

Then RLCP=256-8000/100*2=256-40=216

The duty cycle you can determine with the help of this formula:

DC=(CMP-RLCP)/(256-RLCP)

To start the timer in autoreload mode with output and without interrup you have to set the value of MASK to 11100000b.

I hope it will help you...

henrik239955
Associate II
Posted on March 31, 2003 at 12:30

Hi,

SCR1 = 60h (Prescale by 1, Reload enable)

SCR2= 00h

SCR3=00h

SCR4=02h

RLCP (High) = 00h

RLCP (Low) = 4Fh

MASK (High) = FFh

MASK (Low) = FFh

CMP (High) = 00h

CMP (Low) = 00h - 4Fh for 0-100% duty

To start PWM generation set bit 4 in SCR1 and bit 0 in SCR4

Works for me...

Regards

Bood

info47
Associate II
Posted on March 31, 2003 at 21:33

Thanks, forum,

it works!!! Yipiiieee!

Nice story: I recognized that I had calculated the same settings as those supplied by Bood (thanks!). Why should they work in Sweden but not in Germany? So I followed Bood's information and changed the order of my program lines to match his order. And: It worked!

Small things can cause big problems...

So, I assume that it is important to set the SCRx registers first and then the RLCP, CMP and MASK registers!!!!!

Thanks to Mudator and Bood for their help!

Leines