ECIO40 delay and variables
ECIO40 delay and variables
I tried to write some simple code to flash the on-board LED according to a DELAY programmed by variables. Although I have selected INT variables, I can see that the code goes wrong above 255, indicating it is using a BYTE variable. Are there known problem with this. BTW - I am currently using the demo version of FlowcodeV3.
Tony
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Tony
Can you email me your code and I will have a look for you. There are no known issues regarding the INT variables and the demo version of Flowcode.
Can you email me your code and I will have a look for you. There are no known issues regarding the INT variables and the demo version of Flowcode.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Hello.
I see the problem. The "C" functions used by the DELAY icon (i.e. delay_ms and delay_s) accept "unsigned char" values.
If a constant number is used within Flowcode, then this results in more than 1 call to these functions if the value is above 255. So, entering a delay of 800 gives the following code:
But there is still a limit on the maximum delay value allowed (it must be below 1000).
When a variable is used, as in your case, Flowcode just passes it straight to the function. If you have allowed all compiler warnings (using the "-W2" switch), you will see the following:
So to be safe, make sure you use only "BYTE" variables in the DELAY icon.
I hope this explains things.
I see the problem. The "C" functions used by the DELAY icon (i.e. delay_ms and delay_s) accept "unsigned char" values.
If a constant number is used within Flowcode, then this results in more than 1 call to these functions if the value is above 255. So, entering a delay of 800 gives the following code:
Code: Select all
//Delay
//Delay: 800 ms
delay_ms(255);
delay_ms(255);
delay_ms(255);
delay_ms(35);
When a variable is used, as in your case, Flowcode just passes it straight to the function. If you have allowed all compiler warnings (using the "-W2" switch), you will see the following:
Code: Select all
warning: conversion from 'signed short' to 'unsigned char', possible loss of data
I hope this explains things.
ECIO40 delay and variables
Hi Benj
Not quite sure how to attach code to the reply, so I guess I just embed it. The code used Macros, so I wonder if they can cause problems. Anyway, it flashes morse "SOS" on the built in LED, and works if delay1 is less than 255/3.
Sorry - dont know how to embed the .fcf file, and I dont have a direct email address for you so I can send the attachment.
I'll describe the code:
delay1 and delay2 are INT, and if I raise delay1 > 85, the dashes get shorter
BEGIN
delay1 = 80
delay2 = 3 * delay1
while....
Call Macro dot
Call Macro dash
etc
END
Macro dot:
BEGIN
Output 1
Delay delay1 ms
Output 0
Delay delay1 ms
END
Macro dash - same but using delay2 for the firat delay
[/img]
Not quite sure how to attach code to the reply, so I guess I just embed it. The code used Macros, so I wonder if they can cause problems. Anyway, it flashes morse "SOS" on the built in LED, and works if delay1 is less than 255/3.
Sorry - dont know how to embed the .fcf file, and I dont have a direct email address for you so I can send the attachment.
I'll describe the code:
delay1 and delay2 are INT, and if I raise delay1 > 85, the dashes get shorter
BEGIN
delay1 = 80
delay2 = 3 * delay1
while....
Call Macro dot
Call Macro dash
etc
END
Macro dot:
BEGIN
Output 1
Delay delay1 ms
Output 0
Delay delay1 ms
END
Macro dash - same but using delay2 for the firat delay
[/img]
Tony
ECIO40 delay and variables
THanks STeve
Your reply came as I was composing the last post. I enabled the W2 switch and can see the warnings. However, I dont understand what to do - tried BYTE variables, and I think they just get truncated to 255. Are you saying that to get more than a 255 delay, I have to put in several delay 255 icons adding up to the required delay?
ps - how do I attach my .fcf code?
Your reply came as I was composing the last post. I enabled the W2 switch and can see the warnings. However, I dont understand what to do - tried BYTE variables, and I think they just get truncated to 255. Are you saying that to get more than a 255 delay, I have to put in several delay 255 icons adding up to the required delay?
ps - how do I attach my .fcf code?
Tony
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Tony
The delay icons will accept fixed numbers up to 999. For type INT variables which are less then 1000, it is probably worth dividing by 3 or 4 and then calling 3 or 4 delay icons with the result.
Sorry but you cannot attach files to the forum as of yet.
My email is ben@matrixmultimedia.co.uk.
The delay icons will accept fixed numbers up to 999. For type INT variables which are less then 1000, it is probably worth dividing by 3 or 4 and then calling 3 or 4 delay icons with the result.
Sorry but you cannot attach files to the forum as of yet.
My email is ben@matrixmultimedia.co.uk.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
At the moment, there is no way of attaching code. This will hopefully change soon when the forum software is next updated.
As for your problem, you need to be aware that the DELAY icon only accepts values between 0 and 255. You should also use an INT variable type if you expect the values to be above 255.
You will then need to add a temporary INTvariable (TempVal) and additional code before the DELAY icon that does something similar to the following:
As for your problem, you need to be aware that the DELAY icon only accepts values between 0 and 255. You should also use an INT variable type if you expect the values to be above 255.
You will then need to add a temporary INTvariable (TempVal) and additional code before the DELAY icon that does something similar to the following:
Code: Select all
//Calculation
TempVal = delay2
//Loop
While TempVal > 250
//Delay
Delay (250)
//Calculation
TempVal = TempVal - 250
//End Loop
//Delay
Delay (TempVal)
Hi Steve and Benj
Thanks for your help. I see how the problem can be fixed. I'll stick to values under 255ms for now. Presumably a change to the delay routine which could correctly pass larger values could be made in flowcode, rather than having to call several separate delays.
On a different topic I notice that the PIC clock in Flowcode is fixed at 4.8MHz rather than 4MHz, and since the demo version doesn't appear to allow me to do change it or anything in the C code, I cant set it correctly.
Thanks for your help. I see how the problem can be fixed. I'll stick to values under 255ms for now. Presumably a change to the delay routine which could correctly pass larger values could be made in flowcode, rather than having to call several separate delays.
On a different topic I notice that the PIC clock in Flowcode is fixed at 4.8MHz rather than 4MHz, and since the demo version doesn't appear to allow me to do change it or anything in the C code, I cant set it correctly.
Tony
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Yes - this should be fixed within Flowcode.
The 48MHz value is because you have selected the ECIO module as a target, and this is the speed it runs at. You cannot change the configuration data for this device because it would stop the USB (and therefore the bootloader).
The ECIO module has a 4MHz crystal, but this clock frequency is divided within the chip itself using a PLL.
The 48MHz value is because you have selected the ECIO module as a target, and this is the speed it runs at. You cannot change the configuration data for this device because it would stop the USB (and therefore the bootloader).
The ECIO module has a 4MHz crystal, but this clock frequency is divided within the chip itself using a PLL.