This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PWM Signal with variabel frequency

I am using Keil, C51 Compiler with Infineon XC886

I want to create a PWM signal at pin 3.0, where the frequency is variable and the on time Ton is constant. I wrote the code, I initialized CCU and the function (changeSignal) is called to change the PWM signal into main function. Because the period must change, I have assigned variable T_LB in register CCU6_T12PRL = T_LB and the other T_HB in register CCU6_T12PRH = T_HB. Finally, the shadow register is copied to the "real" register by using the CCU6_TCTR4L | = 0x42 command. Normally, the period must drop by 1e-6. But because the length of the code is greater than 2K while compiling, I could not debug my code. So I've commented T = T-1e-6 and replaced it with 40e-6 only to discover where the error is. After debugging, I have seen that the registers CCU6_T12PRL and CCU6_T12PRH contain their initial values and do not change their values even though they are assigned to the variables T_LB, T_HB. I have tried a long time but the signal does not change its period.

I would like to know if it would be possible for you to view my code. You might find out exactly where the error is. Of course if you have time and desire :).

Here is the code:

#include <xc886clm.h>       // Header Datei für XC886
//#include <xc886_lib.h>

void CCU_init(void);
void changeSignal(void);

void main(void)
{
//PORT_PAGE= 0;                                         //Port_Page per Default= 0
//EA=1;
CCU_init();
while(1)
{
        changeSignal();
}
}

void changeSignal(void)
{
  float T=65e-6;
        float Te=35e-6;
        unsigned int T_HB;
        unsigned int T_LB;
        unsigned int Tneu;
  //T=T-1e-6;
//      a=10000*Te/T;
//      aschritt=a*0.1024/840;
  //Tneu=1024/(10000*Te/T)*0.1024/840; Conversion T to steps where Te=840
        Tneu=840*40e-6/Te;
        T_LB = Tneu % 256;                                // Pulse Periode => Reload Value: LowByte
        T_HB = Tneu >> 8;                                         // Pulse Periode => Reload Value: HighByte,  /256;
        CCU6_PAGE = 1;
        CCU6_T12PRL =T_LB ;
        CCU6_T12PRH =T_HB;
//CCU6_PAGE = 0;
//CCU6_CC60SRL =a_LB;
//CCU6_CC60SRH = a_HB;
  CCU6_TCTR4L |= 0x42;                                          // Copy shadow register to "real" register
}
void CCU_init(void)
{
/***** Configuration Modul Port Control ***/
PORT_PAGE=0;
P3_DIR= 0xFF; // Port3 Output
PORT_PAGE=2;
P3_ALTSEL0=1;
P3_ALTSEL1=0;
PORT_PAGE=1;
P3_PUDEN=0x00;
PORT_PAGE=0;
/*****  Configuration Modul Input/Output Control ****/
CCU6_PAGE=2;
CCU6_T12MSELL=0x01;//Compare output on "logical pins"
// COUT60_0, COUT60_1, COUT60_2
CCU6_MODCTRL|=1;//  PWM activate
/***** Configuration Modul T12 und Clock Control****/
// a) Selection of counting frequency CCU6
// Register TCTR0L: Setting the prescaler bit to 0,
// because it is counted as t = t_PCLK = 24 MHz
CCU6_PAGE=1;
CCU6_TCTR0L |=0x00; // Set Prescaler to 0.The counting period lasts: 1 / 24MHz * 1 = 41.7 ns
// b) Determination period
// Register T12PR: Reset the timer to 0
// -> Period Register (PR) is responsible for the period
//65µs/(1/24MhZ)=1560(corresponds to 0x618)
CCU6_PAGE=1;
CCU6_T12PRL=0x18;
CCU6_T12PRH=0x06;
// Set compare value -> here output to 1
// -> Responsible for on-duration
// 35µs/(1/24MhZ)=840(corresponds to 0x348)
// Port 3.0 uses Channel 0
CCU6_PAGE = 0;
CCU6_CC60SRL =0x48;
CCU6_CC60SRH = 0x03;
// Initiate transfer of shadow register, timer start,
// Prepare the CCU register for transfer of values
// To the compare and period registers
CCU6_PAGE=0;
CCU6_TCTR4L |= 0x42;//Set Shadow-Transfer-Enable Bit
//STE12 by activating bit T12STR and start timer
/***** Configuration Modul Interrupt Control****/
CCU6_PAGE=2;
CCU6_IENL=0x80; // Enable Int bei Period-Match
IEN1 |= 0x40; // Enable Flag for Int-Knoten XINTR12

}

.

Parents
  • I am using Keil, C51 Compiler with Infineon XC886
    If you know what, what made you categorize your post "C166"?

    Normally, the period must drop by 1e-6.

    Say ... what? Do you seriously believe that floating point is something you should be doing on a '51, particularly if you're trying to keep within the 2 KiB evaluation limit? Have you any idea how much support code the compiler has to drag in for that, on this FPU-less 8-bit device?

    And anyway, 1e-6 of what is that?

    to discover where the error is.

    I'm reasonably sure you didn't. Your implied assumption that you can read from a timer/counter register what you wrote into it is most likely incorrect.

Reply
  • I am using Keil, C51 Compiler with Infineon XC886
    If you know what, what made you categorize your post "C166"?

    Normally, the period must drop by 1e-6.

    Say ... what? Do you seriously believe that floating point is something you should be doing on a '51, particularly if you're trying to keep within the 2 KiB evaluation limit? Have you any idea how much support code the compiler has to drag in for that, on this FPU-less 8-bit device?

    And anyway, 1e-6 of what is that?

    to discover where the error is.

    I'm reasonably sure you didn't. Your implied assumption that you can read from a timer/counter register what you wrote into it is most likely incorrect.

Children
No data