Pointer problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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???

0 Likes
2 Replies
pushekm_21
Employee
Employee
10 likes received 5 likes given First like received

 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

0 Likes
Anonymous
Not applicable

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