cancel
Showing results for 
Search instead for 
Did you mean: 

ST7LITE2, PWM programming in C

delser9
Associate II
Posted on June 27, 2003 at 07:27

ST7LITE2, PWM programming in C

7 REPLIES 7
delser9
Associate II
Posted on June 26, 2003 at 11:34

Using the ST7LITE2 ARTimer in PWM mode:

1) Is there any order in writing the DCRxx, ATCSR, ATRxx and PWMCR registers?

2) My program looks like that:

PADDR=0x04; // PA2 (PWM0) = output

PAOR=0x04; // PA2 = pullup

SetBit(ATCSR,FOUR); // Counter Clk = fCPU

ClrBit(ATCSR,THREE);

ATRH=0x00;

ATRL=0x00;

DCR0H=0x05;

PWMCR=0x01; // PWM0 enable

What is wrong with that? There is no signal at the pin which is connected to a LED on the in-DART-STX Demo-board. Do I need the Overflow/Compare interrupts?

Are there any examples for ST7Lite2 PWM mode in C?

Thanks for any help!

bleumers_j
Associate II
Posted on June 26, 2003 at 11:48

Hi,

When you write ''DCR0H=0x05;'', the 0x05 are placed into temporaly registers, not in the ''real'' PWM register.

By adding TRANCR=0x01 after the DCR0H=0x05 the data is copied into the ''real'' PWM registers. Do not forget to do this later on in your program every time a PWM value has to be changed!

Maybe you should place ''PWMCR=0x01'' before the DCR0H=0x05. But i'm not sure.

When it still doesn't work i can give a part of code you can use. Just ask.

Greets.
delser9
Associate II
Posted on June 26, 2003 at 12:20

Hello joble

Thank you very much for your help!

Indeed, it's important to set the TRAN bit, what i didn't! (With the LITE0, that ARTimer is quite different, unfortunately I have only LITE0 examples). But even with that bit set, it still doesn't work. I tried also to toggle position between the PWMCR and the DCR0H line, but there is still no effect!

For the 'DCRxx' lines I disable the interrupts, and enable afterwards, but that doesn't help neither.

Do have any other ideas?

Thanks again, and have a nice evening!
bleumers_j
Associate II
Posted on June 26, 2003 at 12:38

This should work, it's copied from a program that works fine. I do not see any difference with your program.

init:

PADDR=0x7F;

PAOR=0x7F;

ATCSR=0x10;

ATRH=0x00;

ATRL=0x00;

PWMCR=0x15;

in the program:

DCR0H=10;

DCR0L=128;

TRANCR=0x01;

Hope this helps...
delser9
Associate II
Posted on June 27, 2003 at 04:32

Thank you very much for your help. You thought me about the TRAN bit. Although I have exactly the same program as you, it still doesn't work.

Even with a new uController it is still the same. Maybe there is someone out there from ST interested in helping their costumer? Up to now ST just pointed me to this forum.
delser9
Associate II
Posted on June 27, 2003 at 07:11

Problem partially resolved!

The PWM function works well on PWM1 but not on PWM0, although they have absolutely the same configuration (Soft-and Hardware)!

Anybody an idea why it is so?
bleumers_j
Associate II
Posted on June 27, 2003 at 07:27

Hi,

Maybe something wrong with the definition of DCR0H and DCROL? Maybe a stupid idea, but i can't find another possible reason.

Part of the IO7Flite2.h file:

@tiny volatile char DCR0H @0x17; /* PWM 0 Duty Cycle Register High */

@tiny volatile char DCR0L @0x18; /* PWM 0 Duty Cycle Register Low */

@tiny volatile char DCR1H @0x19; /* PWM 0 Duty Cycle Register High */

@tiny volatile char DCR1L @0x1A; /* PWM 0 Duty Cycle Register Low */

@tiny volatile char DCR2H @0x1B; /* PWM 0 Duty Cycle Register High */

@tiny volatile char DCR2L @0x1C; /* PWM 0 Duty Cycle Register Low */

@tiny volatile char DCR3H @0x1D; /* PWM 0 Duty Cycle Register High */

@tiny volatile char DCR3L @0x1E; /* PWM 0 Duty Cycle Register Low

Or a hardware fault (try swapping the pins).

Greets.