2 Replies Latest reply on Jul 27, 2011 11:37 AM by troy.liebl

    Pointer problem

    kurt.labes

      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[] = {
          &PWM1_WritePulseWidth,
          &PWM2_WritePulseWidth,
          &PWM3_WritePulseWidth,
      }

         

      void main(void){

         

      SET_PWM[0](50);

         

      }

         

       

         

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

         

       PWM1_WritePulseWidth:
      _PWM1_WritePulseWidth:
         RAM_PROLOGUE RAM_USE_CLASS_1
         mov   reg[PWM1_COMPARE_REG], A                          using debug window register shows different value!!!???? not(0x32)
         RAM_EPILOGUE RAM_USE_CLASS_1
         ret
       

         

      Any ideas???

        • 1. Re: Pointer problem
          pmad

           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,

             

          Pushek

          • 2. Re: Pointer problem
            troy.liebl

            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); }