cancel
Showing results for 
Search instead for 
Did you mean: 

PWM, STFLITE29

carter888
Associate II
Posted on June 15, 2004 at 10:55

PWM, STFLITE29

6 REPLIES 6
carter888
Associate II
Posted on June 10, 2004 at 12:07

Hello there,

I've got a question on PWM. If i load a value into the PWMxCSR, does it replace the previous value instantly or the next overflow event?

Thanks in advance,

Regards,

Ong

[ This message was edited by: tttiii on 10-06-2004 15:50 ]

[ This message was edited by: tttiii on 10-06-2004 16:51 ]
wolfgang2399
Associate II
Posted on June 14, 2004 at 07:36

Hi Ong,

please have a look at the transfer control register TRANCR. The description there (page 62 in the ST7LITE manual Rev.2.1) gives a hint:

''The OPx bits are transfered to the shadow OPx in the same way.'' -

means if you set the TRAN flag in TRANCR the changed OPx will be active after the next overflow.

Good luck!

woro
carter888
Associate II
Posted on June 14, 2004 at 14:18

Thank you, Woro.

Problem on the digital I/O pin

Digital input (PORTB,2) = Red colour PWM signal.

Digital Output (PORTB,6) = Green colour PWM signal.

The figures are in the document file. Please do have a look on them.

Basically, I would like to receive the PWM signal from the digital input pin and send it out to the digital output pin. However, an unwanted delay has occurred.

The following is my code,

if (PB1 != 0x02)

{

for (i=0; i

{}

PB1 = PBDR & 0x02;

if ( 0x02 != PB1)

PBDR = PBDR & 0xBF; else

PBDR = PBDR | 0x40;

}

else

PBDR = PBDR | 0x40; //

On the figure 1, A 1.6ms delay has happened in between the input and the output. How can I eliminate this delay?

If I increase the width of the pulses, the input PWM looks in the same shape with the output PWM (Figure 2 & 3).

Regards,

Ong

[ This message was edited by: tttiii on 14-06-2004 18:06 ]

________________

Attachments :

Doc1.doc : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0BB&d=%2Fa%2F0X0000000bUn%2Fh81I7IaQQuA5Gu3Sqtq1T_uPizrHCRvUZM6ZBgN_Ur8&asPdf=false
wolfgang2399
Associate II
Posted on June 15, 2004 at 07:12

Hi Ong,

can't understand how your program works. If once PB1 = 0x02 you can never change it in the given code because from then on you only reach the else statement.

Do you really mean

if (PB1 != 0x02)

in the first line?

Probably it could be

if ((PBDR & 0x02) == 0)

or something like this.(??)

Regards

woro
carter888
Associate II
Posted on June 15, 2004 at 07:40

Hi Woro,

Sorry, i forgot to add this line before the if-else statement

char PB1 = PBDR & 0x02;

My code will be as follow

while (1)

{

char PB1 = PBDR & 0x02;

if (PB1 != 0x02)

{

for (i=0; i

{}

PB1 = PBDR & 0x02;

if ( 0x02 != PB1)

PBDR = PBDR & 0xBF;

else

PBDR = PBDR | 0x40;

}

else

PBDR = PBDR | 0x40; //

}

Regards,

Ong
wolfgang2399
Associate II
Posted on June 15, 2004 at 10:55

Hi Ong,

I don't see the need of the char PB1. To write

if((PBDR & 0x02) == 0) ....

instead of

PB1 = PBDR & 0x02;

if(PBDR != 0x02) ...

can make your program a little more obvious.

Nevertheless I can't find any reason for the delay. Please check the handling of

- watchdog

- interrupt events

- is the variable 'i' declared as global and used/changed elsewhere?

Regards

woro