2 Replies Latest reply on Jul 27, 2011 11:37 AM by userc_44553

    Pointer problem

      I added user module PWM8 3 times


      PWM1, PWM2,PWM3


      I wrote following code


      typedef void (* const Function_Pass_Char)(char i);


      static Function_Pass_Char SET_PWM[] = {


      void main(void){








      code compiles fine, but the PWM(Pulsewidth value is not passed into A when calling the asm function


         mov   reg[PWM1_COMPARE_REG], A                          using debug window register shows different value!!!???? not(0x32)


      Any ideas???

        • 1. Re: Pointer problem

           I tried the code snippet which you have provided and debugged the assembly code generated by the compiler. This is a compiler bug because when the function is called the values are always passed in A or X register but in the implementation of this routine the value is stored in stack. Thus, the code is not working as my function is taking the value of A and write into period register.




          I have reported this problem to Imagecraft.




          Best regards,



          • 2. Re: Pointer problem

            I had a similar problem, and solved by using the code keyword as follows:

            // Function pointer to PWM writes code void (code *pwm_ptr[])(uint8 compare) = {  PWM_1_WriteCompare,  PWM_2_WriteCompare,  PWM_3_WriteCompare };   void main() {  (*pwm_ptr[0])(50); }