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; }
Hello Kobus, is your problem solved now? I would think about the UART as evil, since the CAPCOM part seems good. But I do not know your setup of the CAPCOM. I did a similar in center aligned mode, but with timer T2 to change the PWM's, that works fine. Think (or better) take care of your period value, because if the compare values are not in the range no shadow transfer will take place anymore and that's why your new pwm values will never become active. Thus with reference of counting rules. Stefan
Not yet. I'll check on your suggestions.