HI, All,
I need a bit of help.
I have a program that I have made to control A piece of equipment By PWM. I have to limit the PWM but need to have 10% steps, the program I have made will simulate fine.
However when I go to compile it gives me a error. (See below)
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1022): error: can't convert 'float' to 'unsigned char'
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1022:17): error: failed to generate expression
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1042): error: can't convert 'float' to 'unsigned char'
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1042:17): error: failed to generate expression
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1062): error: can't convert 'float' to 'unsigned char'
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1062:17): error: failed to generate expression
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1082): error: can't convert 'float' to 'unsigned char'
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1082:17): error: failed to generate expression
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1102): error: can't convert 'float' to 'unsigned char'
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1102:17): error: failed to generate expression
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1122): error: can't convert 'float' to 'unsigned char'
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1122:17): error: failed to generate expression
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1142): error: can't convert 'float' to 'unsigned char'
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1142:17): error: failed to generate expression
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1162): error: can't convert 'float' to 'unsigned char'
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1162:17): error: failed to generate expression
J:\Projects\PinCure\FlowCode Files\UV LED Controller V1-0.c(1450:17): warning: expression was optimized out
I have worked out that this is being generated due to me having a decimal point in my PWM values IE 30.4
IS there a way a can avoid this error but keep the values I have as a lot of the PWM levels I have created need to have the Decimal value.
Thanks
Tristan
PWM. Problem
Moderator: Benj
- 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:
Re: PWM. Problem
Hello Tristan,
Unfortunately you cannot pass floating point variables to the PWM function. What you can do is to use the PWM in 10-bit mode and this will allow for integer values between 0 and 1023. Therefore you can multiply your float variable to allow it to go in the range 0 - 1023 and then convert it to an integer before passing to the PWM duty cycle.
Unfortunately you cannot pass floating point variables to the PWM function. What you can do is to use the PWM in 10-bit mode and this will allow for integer values between 0 and 1023. Therefore you can multiply your float variable to allow it to go in the range 0 - 1023 and then convert it to an integer before passing to the PWM duty cycle.
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
-
- Flowcode V4 User
- Posts: 40
- Joined: Sat Mar 06, 2010 5:25 am
- Location: Chicago USA, & Oxford & Northampton UK
- Has thanked: 6 times
- Contact:
Re: PWM. Problem
Hi, Ben,
Thanks for the reply, I am still trying to get my head round this.
Sorry to be a pain, but do you have a example you can give me.
Thanks
Tristan
Thanks for the reply, I am still trying to get my head round this.
Sorry to be a pain, but do you have a example you can give me.
Thanks
Tristan
- 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:
Re: PWM. Problem
Hello,
If your range of your floating point variable is between 0 and 255 then you would first multiply by 4 to get a value between 0 and 1023. Once you have done this you can use the float to int function in the calculation icon to convert the variable type.
I've included a quick example.
If your range of your floating point variable is between 0 and 255 then you would first multiply by 4 to get a value between 0 and 1023. Once you have done this you can use the float to int function in the calculation icon to convert the variable type.
I've included a quick example.
- Attachments
-
- Flowcode1.fcf
- (4.5 KiB) Downloaded 302 times
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