PWM with menu control - hangs up

Hi,

Using: Keil uvision3 with Infineon XC866 Easy kit development board.

I am trying to write a little menu function to controller the PWM generation via key stoke selections. The first few keystrokes are implemented and I can see the PWM signal changing. Then the micro hangs up.

Not sure what is wrong !?

Here is the code:

#include "MAIN.H"

void message( char *pucMessage );

void MAIN_vInit(void)
{
  ///  Initialization of module 'UART (Serial Interface)'
  UART_vInit();

  ///  Initialization of module 'Capture / Compare Unit 6 (CCU6)'
  CC6_vInit();

  //   Interrupt Priority

  IP            =  0x00;         // load Interrupt Priority Register
  IPH           =  0x00;         // load Interrupt Priority High Register
  IP1           =  0x00;         // load Interrupt Priority 1 Register
  IPH1          =  0x00;         // load Interrupt Priority 1 High Register

  //   globally enable interrupts
  EA            =  1;

} //  End of function MAIN_vInit


void main(void)
{
  char key;

  MAIN_vInit();

	message("\n\n\xd Welcome to MENU : PWM Control");
	message("\n\xd Please select on of the following:");
	message("\n\xd 1 -- 1.00 ratio");
	message("\n\xd 2 -- 0.75 ratio");
	message("\n\xd 3 -- 0.50 ratio");
	message("\n\xd 4 -- 0.25 ratio");
	message("\n\xd 5 -- 0.00 ratio");
	message("\n\xd Thank you for using XC866 \n\n");

  while(1)
  {

	while(!RI){};	 // Wait for keystroke

	key = SBUF;

	if(key == '1')
	{
		message("\xd 1 -- 1.00 ratio");
        CCU6_PAGE = 0x00; // switch to page 0
		CCU6_CC60SRL |= 0x00;
		CCU6_CC60SRH |= 0x00;
		CCU6_TCTR4L |= 0x40; // enable shadow transfer
	}

	if(key == '2')
	{
		message("\xd 2 -- 0.75 ratio");
 		CCU6_PAGE = 0x00; // switch to page 0
		CCU6_CC60SRL |= 0x00;
		CCU6_CC60SRH |= 0x40;
		CCU6_TCTR4L |= 0x40; // enable shadow transfer
	}

	if(key == '3')
	{
		message("\xd 3 -- 0.50 ratio");
		CCU6_PAGE = 0x00; // switch to page 0
		CCU6_CC60SRL |= 0x00;
		CCU6_CC60SRH |= 0x80;
		CCU6_TCTR4L |= 0x40; // enable shadow transfer
	}

	if(key == '4')
	{
		message("\xd 4 -- 0.25 ratio");
		CCU6_PAGE = 0x00; // switch to page 0
		CCU6_CC60SRL |= 0x00;
		CCU6_CC60SRH |= 0xC0;
		CCU6_TCTR4L |= 0x40; // enable shadow transfer
	}

	if(key == '5')
	{
		message("\xd 5 -- 0.00 ratio");
 		CCU6_PAGE = 0x00; // switch to page 0
		CCU6_CC60SRL |= 0xFF;
		CCU6_CC60SRH |= 0xFF;
		CCU6_TCTR4L |= 0x40; // enable shadow transfer
	}

	RI = 0;	 // Reset RI

  }

} //  End of function main


void message( char *pucMessage )
{
 // while the character is not 0
 while (*pucMessage)
 {
  SBUF = *pucMessage++;
  while (TI == 0) {;}
  TI = 0;
 }
 return;
}

Parents
  • I note that you are always OR-ing bits into CCU6_CC60SRL and CCU6_CC60SRH - so you never actually clear any bits in these registers. Is this really what you want?

    I don't know this particular chip, but it strikes me that you're going to end up with all bits set in both registers, and no way to clear any bits. Again, is this what you really want?

    In other words, Should you be using '=' rather than '|=' for these two registers?

    As an aside, don't you think a switch would be more appropriate here - or even a lookup table?

Reply
  • I note that you are always OR-ing bits into CCU6_CC60SRL and CCU6_CC60SRH - so you never actually clear any bits in these registers. Is this really what you want?

    I don't know this particular chip, but it strikes me that you're going to end up with all bits set in both registers, and no way to clear any bits. Again, is this what you really want?

    In other words, Should you be using '=' rather than '|=' for these two registers?

    As an aside, don't you think a switch would be more appropriate here - or even a lookup table?

Children
More questions in this forum