2004-06-15 01:55 AM
2004-06-10 03:07 AM
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 ]2004-06-13 10:36 PM
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! woro2004-06-14 05:18 AM
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=false2004-06-14 10:12 PM
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 woro2004-06-14 10:40 PM
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, Ong2004-06-15 01:55 AM
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