I am using CodeWarrior 5.1 Special Edition and am having trouble passing a value to a function.
The call from main()
setLEDDutyCycle(ATD1DR2L);
(Value of ATD1DR2L = 0xA0) as read from an external pot.
The function is as follows:
static void setLEDDutyCycle(uint8_t dc){
PWMCTY5 = dc;
PWMDTY4 = dc;
}
When stepping through the function in the Simulator/Debugger the value of the local variable dc in the DATA1 window shows as
dc <not allocated> unsigned char
Other functions that I have are working, but confused about this one.
Any ideas where I am off track?
Solved! Go to Solution.
Hello Tim,
For in the function of "setLEDDutyCycle()" , dc do nothing , only be given to other variable or
register , so the compiler optimize it .
For example add dc++; in that function , it will not optimize it .
Hope it helps
Have a great day,
Alice Yang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Alice,
Sorry that was a typo it is actually PWMDTY5 which is the PWM Duty Cycle Register 5 as defined in MC9S12XDP512.h.
The problem though is why is dc not assigned the value passed as the function argument.
When stepping through the function in the Simulator/Debugger the value of the local variable dc in the DATA1 window shows as
dc <not allocated> unsigned char
The call from main()
setLEDDutyCycle(ATD1DR2L);
(Value of ATD1DR2L = 0xA0) as read from the Data->Locals window.
Hello Tim,
For in the function of "setLEDDutyCycle()" , dc do nothing , only be given to other variable or
register , so the compiler optimize it .
For example add dc++; in that function , it will not optimize it .
Hope it helps
Have a great day,
Alice Yang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Alice,
Interesting, but dc is passed in and is being used to set PWM port parameters. In all cases the code executed properly as indicated by the ability to set the LED brightness from the pot attached to ATD1DR2L.
So the IDE optimized it to <NULL> basically? I did the following to test.
1) Tried to declare as volatile in the parameter listing - Same result
2) Added the statement dc %= 0xff; - Same result
3) Added the statement dc++; before dc %= 0xff; - dc is now assigned the passed value in the Data1 -Locals window.
However the only time the correct passed value shows up in the Data1-Locals window is when the value is incremented.
Thanks
Hello Tim,
What about the type of PWMCTY5 ?
Could you please share your project , or there is some confidential about the project,
you can delete some code , then only remain the code which can show the error .
BR
Alice