|
|
View previous topic :: View next topic |
Author |
Message |
no username Guest
|
lost parameter when I call a function |
Posted: Fri Apr 06, 2007 11:14 am |
|
|
Hi folks,
i have a problem with the CCS 3.227. This is my function definition:
Code: | void set_rgb(int address, int pwm0, int pwm1, int pwm2)
{
//code
}
|
And in my main.c I have:
Code: | set_rgb(1,200,200,200); |
But I only get a result for pwm1 and pwm2. It seems that the 2nd parameter get lost. I have renamed the parameter e.g. pwm_0 and I have changed the order of the parameter. Always the 2nd parameter get lost!
I have copyed the code out of the function into the main.c than my code works.
I’m open for all suggestions and recommendations!! thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 06, 2007 12:09 pm |
|
|
Put a printf statement at the start of the function and display all four
of the parameters. What does it show ? |
|
|
no username Guest
|
|
Posted: Sat Apr 07, 2007 9:51 am |
|
|
Thanks PCM programmer.
I have used the I2C bus because I don’t use RS232 in my application.
I have removed the code of my function. Now the function is only the I2C report of the parameters.
Code: | void set_rgb(int address, int pwm0, int pwm1, int pwm2) {
i2c_start();
i2c_write(address);
i2c_write(pwm0);
i2c_write(pwm1);
i2c_write(pwm2);
i2c_stop();
delay_us(1000);
} | When I call the function then I can see all 4 parameters on the I2C bus.
But when I remove the delay_us(1000); then pwm0 is always reported as 0x00 independent from the parameter that I give to the function.
Always the 2nd parameter get lost! Is it a bug in CCS? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Apr 07, 2007 11:05 am |
|
|
How do you see the parameters on the i2c bus ? Are you using an i2c
bus monitor ?
Is this project being done using real hardware, or is this being done
in an emulator such as Proteus ? |
|
|
no username Guest
|
|
Posted: Mon Apr 09, 2007 5:04 am |
|
|
Sorry for the delay. It took some time to isolate failure.
Now my code is: Code: | void set_rgb(int address, int pwm0, int pwm1, int pwm2) {
pwm0_v=pwm_0;
pwm1_v=pwm_1;
pwm2_v=pwm_2;
i2c_start();
pwm0_n=pwm_0;
pwm1_n=pwm_1;
pwm2_n=pwm_2;
i2c_write(address);
i2c_write(pwm0);
i2c_write(pwm1);
i2c_write(pwm2);
i2c_stop();
delay_us(1000);
} | pwmx_v and pwmx_n are global variables so I can debug them in the main file. I have debugged the 16F88 with ICD2 with the following main file:
Code: | while (1)
{
set_rgb(1,200,200,200);
delay_ms(500);
} | The first time in the while loop I see in the watch window:
pwm0_v= pwm1_v= pwm2_v= pwm0_n= pwm1_n= pwm2_n=200
BUT beginning on the 2nd time in the loop I see:
pwm0_v= pwm1_v= pwm2_v= pwm1_n= pwm2_n=200
pwm0_n=0
So for me it seems to be a problem with the build in function i2cstart() starting by the 2nd time it is called.
Can someone test it with the latest CCS version and on a other device? I can send the source files via mail. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 09, 2007 8:26 am |
|
|
What if this whole thing is a Watch window problem with ICD2 and your
version of MPLAB ?
Put a printf statement in there, and run the program in standalone mode
(not in Debugger mode). See if the parameters are displayed on the
terminal window in your PC.
Also, post your version of MPLAB. |
|
|
no username Guest
|
|
Posted: Wed Apr 11, 2007 2:49 pm |
|
|
No it is defiantly a problem in real HW. I have made all the Tests with a standalone 16F88. Only the last test was done in debug mode with MPLAB v7.20.
Today I have tested the program with printf(): Code: | void set_rgb(int address, int pwm0, int pwm1, int pwm2) {
printf("%u ",pwm0);
printf("%u ",pwm1);
printf("%u ",pwm2);
i2c_start();
printf("%u ",pwm0);
printf("%u ",pwm1);
printf("%u ",pwm2);
i2c_write(address);
i2c_write(pwm0);
i2c_write(pwm1);
i2c_write(pwm2);
i2c_stop();
delay_us(1000);
} | The result is the same as in the debug mode. Before i2c_start() I have the correct parameters pwm0, pwm1, pwm2 = 200. After i2c_start() the parameter are pwm0=200, pwm1=0, pwm2=200.
Strange things are going on… |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 11, 2007 3:02 pm |
|
|
If you can post a very small test program that just calls that routine
and demonstrates the failure, then the problem can likely be found by
examining the .LST file.
By a test program, I mean a program that has the #include statement for the PIC, and also #fuses, #use delay(), and code in main() that demonstrates the problem (or calls the routine that demonstrates it).
The posted code should compile with no errors. |
|
|
no username Guest
|
|
Posted: Thu Apr 12, 2007 1:16 pm |
|
|
So this is my test program. It is as short as possible. With the CCS Compiler Version 3.227 I can compile the code without errors. Code: | #include <16F88.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No Low Voltage Programming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#use delay(clock=4000000)
#use i2c(Master,fast,sda=PIN_B1,scl=PIN_B4)
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B2)
void set_rgb(int address, int pwm0, int pwm1, int pwm2) {
printf("%u ",pwm0);
printf("%u ",pwm1);
printf("%u ",pwm2);
i2c_start();
printf("%u ",pwm0);
printf("%u ",pwm1);
printf("%u ",pwm2);
i2c_write(address);
i2c_write(0xA2);
i2c_write(pwm0);
i2c_write(pwm1);
i2c_write(pwm2);
i2c_stop();
}
void main()
{
setup_oscillator(OSC_4MHZ|OSC_INTRC);
while (1)
{
set_rgb(0b11100010,200,200,200);
delay_ms(500);
set_rgb(0b11100010,10,10,10);
delay_ms(500);
}
} | If it is helpful I can also post the *.LST file. I am looking forward to your results.
Many thanks in ahead! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 12, 2007 1:23 pm |
|
|
Post the output of the program that's displayed on your terminal window.
Also tell what pass it fails on. Does it fail on the very first pass through
the while() loop. |
|
|
no username Guest
|
|
Posted: Thu Apr 12, 2007 2:05 pm |
|
|
In Hyper Terminal I get reported:200 200 200 200 200 200 10 10 10 0 10 10 200 200 200 0 200 200
10 10 10 0 10 10 and so on ... So the first loop goes well. BUT beginning by the 2nd time in the loop pwm0 becomes 0. pwm0 is the 2nd parameter (1st is address). |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|