Look Up Tables using Flowcode and Microsoft Excel

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

User avatar
Benj
Matrix Staff
Posts: 14073
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4297 times
Been thanked: 4050 times
Contact:

Look Up Tables using Flowcode and Microsoft Excel

Postby Benj » Mon Jul 30, 2007 11:04 am

Here are 3 example Flowcode files and an excel spreadsheet that show how to create look up tables using Flowcode.

The Excel file is used to create the data for the Look up table.

Once the data has been created it can be included into Flowcode by using the Edit -> Supplementary code dialogue window.

Example 1 - SIN Look Up Table

Uses a look up table to convert a degree value between 0 and 180 into a value of SIN with amplitude of 100.

Example 2 - SIN look up table using the EB048 Gfx LCD.

As above but now the program steps through the Lookup table to output a Sine wave onto the Graphics LCD. Note that there are visible steps between the LUT values rather then a smooth continous line.

Example 3 - SIN look up table using using the EB048 Gfx LCD with Interpolation.

As above but now the steps have dissapeared as the output is a combination of the Look up table and interpolation between the LUT values.

The archive of LUT files can be found here

http://www.matrixmultimedia.com/softwar ... _Table.zip
These users thanked the author Benj for the post (total 2):
zen (Tue Jan 04, 2011 9:26 am) • joe nova (Sat May 28, 2016 3:52 pm)
Rating: 11.11%
 

RichardB
Posts: 1
Joined: Wed Aug 25, 2010 9:38 am
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby RichardB » Thu Aug 26, 2010 9:15 am

Having created the LUT with excel, and made the single line beginning ROM CHAR* ... where does this line go in the code? I tried one of your examples (the simple sine wave one) and when I ran the simulation the display stayed on "0" as the program stepped through 0,90,180 etc. Surely it should have diplayed the appropriate value each time? I looked through every bit of supp. code and could not find the line creating the LUT. I tried putting it in the LCD-Start code but nothing happened. Please help!!!!!!

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Thu Aug 26, 2010 10:00 am

Hello RichardB
RichardB wrote:made the single line beginning ROM CHAR* ... where does this line go in the code?

Look-up tables go into the supplementary Code window.
With Flowcode 3 it's 'Edit', 'supplementary Code'
With Flowcode 4 it's 'View', 'Project options' then Click on supplementary Code button.
RichardB wrote:when I ran the simulation the display stayed on "0" as the program stepped through 0,90,180 etc. Surely it should have displayed the appropriate value each time?

Look-up tables are using C. Flowcode will not be able to simulate C, that is why only 0 is displayed.
Only way round this is to either use ICD function (V4 only) with real hardware or a simulator that has LCD functions.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Dirk Bubley
Posts: 87
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 9 times
Been thanked: 8 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby Dirk Bubley » Thu Oct 14, 2010 8:18 am

Hello comunity,

question is it possible to define values greater then 255 in a LUT wich goes into the suplementry code??
Load and return must be of course in to a INT variable.

BR

Dirk Bubley

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Thu Oct 14, 2010 12:14 pm

Hiya Dirk Bubley
As far as I’m aware you can only have bytes. So 0 - 255 only

However If it was me I would use two look up tables. One would be your High bytes, and other could be low bytes.

When both values are retrieved, you can then convert high and low byes into a single integer.

Give it a go and post Flowchart when you get stuck. We can then assist you further.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Thu Oct 14, 2010 9:46 pm

To help you are are two different ways you can convert from byte to integer and vice-versa

IntValue = ByteLow+(ByteHigh << 8)

ByteLow = IntValue & 0xFF
ByteHigh = (IntValue >> 8) & 0xFF


IntValue = ByteLow+(ByteHigh * 256)

ByteHigh = (IntValue/ 256)
ByteLow = IntValue - ByteHigh* 256

Not tried the lower three formulas within Flowcode but have included them so you will know how conversions can be done mathematically
These users thanked the author medelec35 for the post (total 3):
JohnCrow (Wed Apr 27, 2011 7:17 pm) • Werner (Wed Nov 23, 2011 12:08 pm) • brandonb (Tue Mar 06, 2012 7:54 am)
Rating: 16.67%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Dirk Bubley
Posts: 87
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 9 times
Been thanked: 8 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby Dirk Bubley » Sun Oct 17, 2010 4:44 pm

Hi medelec,

very good reply!! It worked!! I´m now using two LUT table!!

BR

Dirk

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Sun Oct 17, 2010 5:26 pm

That's great! Glad you got a solution that works.
Thanks for letting us know.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

zen
Posts: 8
Joined: Tue Dec 21, 2010 9:50 pm
Has thanked: 4 times
Been thanked: 5 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby zen » Tue Jan 04, 2011 9:23 am

I have a few questions for those experienced with using look up tables in reference to the program posted above.

1.I am having trouble understanding the way operation occurs between flowcode and the look up table. Does flowcode actually examine the file 'SIN LUT.xls', retrieve the string of values, and then insert the string into the project during compilation? For example, If I changed an X or Y value in the SIN_LUT.xls spreadsheet and then compiled one of the included programs will flowcode examine the excel spreadsheet and put the current state of the "Complete Array Declaration String" into the program. (sort of like how a library or linker file works in mplab)?

---If flowcode doesn't operate in the above manner above (and I don't think it does) is it correct to think of the spreadsheet as simply a tool used to calculate the string of values and concacenate/chain them into a form that flowcode can use?....Therefore, the only thing that flowcode examines is the data that the user paste in the supplementary code box and there is no data exchange between the excel sheet and flowcode?

2. I am trying to build a program that will control the duty cycle of an RGB LED using a look up table system like ben has but i am unsure how to apply to a pretty cool rgb led LUT i found online(attached below).

--My idea was to use a potentiometer and ADC to return a value for 'Hue' ranging from 0-19 and use 5 momentary action pushbuttons to select color from darker to lighter as reflected in the table. So if I turned the potentiometer to a position that returned a value of 9 and also hit the first button returning a brightness value of 1, I need my program to return the data values for red, green, blue found in the chart where row 9 column 1 intersect which is
"r= 0 g=255 b=192"...... these values will then be used to set the PWM duty cycle for the led until changed.

For the life of me I cannot see how to make an array or string that could return the appropriate values for each color. I thought about storing the data into the eeprom but experimented and could not find a way to find each location. Even if there was only one column for the brightness setting I have trouble understanding how to make an array or string that returns r, g, b. I understand how a basic array works but is it possible to build arrays within arrays within strings or some other odd combination of such that interrelates data table.

If BUTTON = 1 ;
PWM_DUTY_RED = COLUMN1[RED[ROW[POTENTIOMETER_RETURN[=9]]] ;
PWM_DUTY_BLUE= COLUMN1[GREEN[ROW[POTENTIOMETER_RETURN[=9]]] ;
PWM_DUTY_GREEN= COLUMN1[BLUE[ROW[POTENTIOMETER_RETURN[=9]]] ;
From here I would need to build arrays/strings that would hold the data for all the columns, rows and so on.

Any advice, ideas or suggestions or solutions are welcome. I'm at a dead end for now when it comes to using the RGB lookup table and have no idea how to form an effecient program with it. btw.....there is some kind of macro in the attached table that the author made that can look up a color. I have no idea how it works but I bet it could be used. I found the LUT on the microchip forums
Attachments
LUT_RGB.xls
(50 KiB) Downloaded 1015 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Tue Jan 04, 2011 1:34 pm

The look up table will not be a problem, I can help you with that.
I'm not sure if only one LED on at a time will give you the same lighting effect as all three on at the same time. There will be a persistence of vision, but if you set value of 0, 255 and 192, do you get correct blue. Then alter values to 255,192 and 64. do you get correct shade of orange. At this stage do one step at a time, you do not need the pot or switch connected. Just manually set values and send to target.
Take a look here:
viewtopic.php?f=26&t=7021&p=16827
and here:
viewtopic.php?f=26&t=7652

Between the there methods you have, choose one which would be best to use.
With the last link, you do not need a miac it will still give you an idea.
When you have established a method and created a Flowchart that just works by manually setting three numbers for RGB. Add the pot and switches.
then upload to forum, and I will sort the look-up table side out for you.
Or if you want I will post how I would created LUT along with a formula to access correct numbers, so you can add it yourself.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Tue Jan 04, 2011 4:11 pm

I have created a way to enter the LUT method.
The attachment LED LUT1.jpg is no longer available

You will need to copy Red, Green and Blue boxes, and paste each in the supplementary code window ('View', 'Project Options' then select 'Use supplementary code')

Formula 1 is entered in a calculation component

Formulas 2 - 4 are entered in a C component

Brightness variable in Formula 1 is determined by which switch is pressed.
Switch 1 for lowest brightness so Brightness=1
Switch 2 for a higher brightness so Brightness=2
Note the look up tables are using first 4 switches only. So formulas 2 - 4 are only accessed if switches 1 - 4 are pressed.
If switch 5 is pressed, then just use a decision Branch to set PWM_RED, PWM_GREEN & PWM_BLUE TO 255.

E.g IF SWITCH 5 = 1
THEN PWM_RED=255
PWM_GREEN =255
PWM_BLUE = 255.
ELSE
ADC0=((19*ADC0/255)+Brightness*20)-20
FCV_PWM_RED= red_brightness[FCV_ADC0];
FCV_PWM_GREEN= green_brightness[FCV_ADC0];
FCV_PWM_BLUE= blue_brightness[FCV_ADC0];

Hope this has helped enough for you to complete your project.
Attachments
LUT_RGB Modified2.xls
(46 KiB) Downloaded 826 times
LED LUT1.jpg
(123.46 KiB) Downloaded 23776 times
Last edited by medelec35 on Tue Jan 11, 2011 12:32 pm, edited 2 times in total.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

zen
Posts: 8
Joined: Tue Dec 21, 2010 9:50 pm
Has thanked: 4 times
Been thanked: 5 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby zen » Wed Jan 05, 2011 7:25 pm

Medelec,
I probably should have been more precise in what the data in the RGB LUT.xls is representing or how I am reading it. The values R,G,B are the duty cycle returns (Time High of R,G,B /Total Cycle Time ex.. Red/255) for each state determined with respect to state of a potentiometer and a pushbutton. .... An interrupt or macro would be used to furnish the current state of the pot and button that would be updated in the program.

While Potentiometer value =__ ,AND, Button input= __ , then go fetch relevant data from a column and row and return values for R?/255, G?/255, B?/255....

From using the example from my first post the three outpus captured from an oscilloscope should roughly appear as draw below for each period until the pot. or button state changed
. [ """So if I turned the potentiometer to a position that returned a value of 9 and also hit the first button returning a brightness value of 1, I need my program to return the data values for red, green, blue found in the chart where row 9 column 1 intersect which is "r= 0 g=255 b=192""" ]

The amount 255 is CONSTANT > |===================< X/255 >==================|<period...The ratio of R or G or B /255 is varied

R= 0 |______________________________________________ | ; off time appears as = ____
G= 255 |-----------------------------------------------------------------| ; ---- = appears as on time
B= 192 |-----------------------------------------------_____________| ;
So red is on 0/255 slots, green is on 255/255 possible slots, blue is on 192/255 slots , this repeats until the pot. and/or button value is changed.

I think your pretty well understanding what I'm trying to do but wanted to post this for clarification just in case. I'm trying to wrap my head around the manner in which you calculating brightness and R,G,B_PWM with respect to the buttons in formulas 1 and 2-4

I'm trying to apply this data to a program similar to one I ironically was able to build with help from a program you posted. I have the program posted here... viewtopic.php?f=7&t=7992

For clarification, In formula 1 are you using a short (byte) return the value where ADC0 is initially the ADC0 sampled value/255? I see how you build an array consisting of the 80 different states for each color of R,G & B but I'm having trouble understanding how that formula could work in response to a change in either the button or potentiometer.

Did you have any clue what the macro built by the author on the RGB_LUT spreadsheet does?

I'll see if I can't build a program using the advice you given thusfar. I'll post what I happen to create though it may be ugly

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Wed Jan 05, 2011 9:11 pm

Formula 1 does this:
You have a pot which reads bytes (0 to 255)
it converts this to 0 to 19 (since there are 20 values)
then if switch 2 is pressed Brightness = 2
so the next column of table are read. (2nd column)
if switch 3 is pressed Brightness = 3
so 3rd column of table are read. etc
Once you get a value, it will retrieve the correct data from the look-up table.
E.g assuming switch 3 is pressed so the Variable Brightness = 3
and pot is on 0
using ADC0=((19*ADC0/255)+Brightness*20)-20

ADC0 =((19*0/255)+3*20)-20
= 0 + 40
=40
So LUT at position 40 will be retrieved = 255 128 255
R G B

So I i did was to show one method of retrieving the values from the spread sheet you posted
Which is what you was asking for.

If you post a flowchart with one pot and 5 switches along with the LUT in supplementary code section. I will check to see if when you turn pot and have a switch pressed, the correct data form LUT will be retrieved
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Thu Jan 06, 2011 6:27 am

zen wrote:Did you have any clue what the macro built by the author on the RGB_LUT spreadsheet does?
No, could not get it to work. I even enabled all at the trust center, but still no joy. Could be something to do with windows 7 and the version of spread sheet I am running.

Another example to retrieve data that corresponds to red outlined data within your spread sheet. (192, 255 & 255)

If put is turned so its value approx 121 and switch 4 is pressed = which sets Brightness variable to 4
Applying to formula used to retrieve LUT data:
=((19*121/255)+4*20)-20
= 9+60
= 69
so its retrieving the 9th number from the bottom row (0 -19), and 4th row across.
If you count starting from 0 at Cell D24 so 1=D23, 2=D22........20=G24, 21=G23........60=M24, 61=M23.......69=M15=192
So the value in Cell M15 = 192 will be retrieved = value for RED
Apply formula to Green, Count 69 starting from 0=E24...................69=N15=255
Value in N15 is 255
Now Variable PWM_RED=192
PWM_GREEN= 255
PWM_BLUE= 255
So you use these numbers from all three LUT's to set duties. Although I would of said Value of LUT retrieved/255 is not correct. You do not want a result less than 1 to work with.
In micro maths using INT or bytes, all results are rounded down
E.g 192/255 = 0 not 0.75
Unless you meant / = out of and not divide.

Note: there is a typo in formula FCV_PWM_RED= blue_brightness[FCV_ADC0];
Should be: FCV_PWM_BLUE= blue_brightness[FCV_ADC0];

In your flowchart you will need to use the Variable manager and add Variable as bytes called PWM_RED, PWM_GREEN & PWM_BLUE.
You will not need to add Variables red_brightness, green_brightness or blue_brightness
zen wrote:I'm trying to apply this data to a program similar to one I ironically was able to build with help from a program you posted. I have the program posted here... viewtopic.php?f=7&t=7992

That PWM method was created for a single PWM channel, and posted it, since I have not seen it done that way before.
I don't believe it will work in your case as you want at times all three PWM channels on at the same time to mix the LED coulours to give the desired effect.
If I was you I would use method adopted here:
viewtopic.php?f=26&t=7021&p=16827
so your interrupt in a similar format to this:
Interrupt PWM.jpg
Interrupt PWM.jpg (119.69 KiB) Viewed 33632 times



Hope this helps to clear things up.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

zen
Posts: 8
Joined: Tue Dec 21, 2010 9:50 pm
Has thanked: 4 times
Been thanked: 5 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby zen » Tue Jan 11, 2011 3:25 am

I'm not sure what it is I'm getting wrong but I am unable to get this program to run correctly. I have tried around ten hours worth of changing settings and have written 2 versions of this program without luck. I'm pretty sure I'm doing something wrong when reading the array. Attached is a slimmed down copy of the program where variables and macro's are kept to a minimum. The most common error I have recieved is one that says I'm missing a semi-colon, paren and something else (viewtopic.php?f=24&t=4851 .............another post concerning the same errors I am recieving). The program will compile to C but not to hex. I'm not sure is whether the array is being saved in the rom. The program is using up alot of ram making me think that its not being put there.
Thanks again for your help medelec
Attachments
rgbLUT.fcf
(19.18 KiB) Downloaded 941 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Tue Jan 11, 2011 7:21 am

Corrected Errors for you.
Main problem is you had:
FCD_PWM_RED = RED[FCV_ADCO_MATH];
FCD_PWM_GREEN = GREEN[FCV_ADCO_MATH];
FCD_PWM_BLUE = BLUE[FCV_ADCO_MATH];
Changed to:
FCV_PWM_RED = red[FCV_ADCO_MATH];
FCV_PWM_GREEN = green[FCV_ADCO_MATH];
FCV_PWM_BLUE = blue[FCV_ADCO_MATH];
Also you do not need: Brightness = Brightness
Since variable will never change you will get the warning:
'warning: expression was optimized out'
Semicolon missing in supplementary window was my mistake, Sorry.
I did not put them on the excel sheet. I have corrected that and uploaded.
New excel sheet is called:
LUT_RGB Modified2.xls

Compiles OK.
Only had a few minutes spare, as had to get ready for work.
I won't be able to test until get home tonight.
Edit: Just tested on hardware and using ICD.
After making some more corrections. I can confirm LUT values retrieved are now correct for setting of pot and switch presses.
So Project is definitely getting there .. Not much to do now. 8)
problem was Brightness value was done as a local variable, so when returning to main, brightness was wrong value hence wrong LUT value displayed.
I have also removed count = 0 and count up to 10 loop.
Reason being value of LUT is 0 - 255. If you keep resetting after 10, you will not cover full range of values.
I reckon the last thing you will need to do is find out the time required when lut = 1, then use that value.
I believe the best way then would be a timer interrupt. Not a call with a macro then a 1ms delay within macro.
Practically, 1 ms is too long, since 255= 255ms,which is a very visible flashing rate.
Attachments
rgbLUT2.fcf
(17.95 KiB) Downloaded 908 times
These users thanked the author medelec35 for the post:
zen (Wed Jan 12, 2011 6:36 pm)
Rating: 5.56%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

zen
Posts: 8
Joined: Tue Dec 21, 2010 9:50 pm
Has thanked: 4 times
Been thanked: 5 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby zen » Wed Jan 12, 2011 5:50 pm

My plan was do things almost exactly as you just advised above. The loop count was at 255, It was 10 because 255 loops on a simulation speed of 5 takes forever. A delay loop or timer interrupt will be used to dial in the timing of the finished product.

It's odd that you got the supplementary code to work correctly. I had done it the exact way you had and problems. I think that the error you found on brightness was causing most of the problems. I just downloaded and tested on an led and it is working. There are about 20 distinct colors on the button one setting which validates the data in the excel spreadsheet. Now it's time to get to work and smooth out the program. Your awesome medelec, without your expertise I would be stuck and frustrated.

I'll post up a smoothed out version of this program after I tweak it a bit. Hopefully it will help somebody else out in the future. I haven't seen any reference on the internet showing how to use a system like this to control an RGB led.

edit: It looks like I get to learn a lesson about interrupts. It won't let me call the pwm macro in the interrupt because it requires the parameter adco_math. A delay loop may be the way to go
Last edited by zen on Wed Jan 12, 2011 6:55 pm, edited 2 times in total.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Wed Jan 12, 2011 6:23 pm

Hiya zen,
Your welcome, and just glad I could help you to progress nearer towards the end of your project.
The finished version sounds great, and would be a great addition to the articles section.
One piece of advice regarding timer interrupts. It is best to avoid any delays (or fixed components which calls delays e.g LCD display routines etc.) within the interrupt routine.
Thanks for keeping us updated on the progress.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Sat Jan 15, 2011 9:53 am

zen wrote:edit: It looks like I get to learn a lesson about interrupts. It won't let me call the pwm macro in the interrupt because it requires the parameter adco_math. A delay loop may be the way to go

Just noticed your edit.
To use a timer interrupt, the macro it is calling should not have any local variables defined within.
I have removed variables so interrupt can be used.
Since delay within macro was set for 1ms, I have set interrupt access time for just a tad over 1ms
You may need to adjust timer0 frequency for LED colours to mach excel sheet colours, but again it's another starting point.
Attachments
rgbLUT3.fcf
(15.25 KiB) Downloaded 887 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Chirikas
Posts: 3
Joined: Thu Jan 20, 2011 2:00 pm
Has thanked: 2 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby Chirikas » Fri Jan 21, 2011 5:46 pm

Hi,
I am quite interested in this project. Maybe somebody have scheme and PCB layout ?

zen
Posts: 8
Joined: Tue Dec 21, 2010 9:50 pm
Has thanked: 4 times
Been thanked: 5 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby zen » Sat Jan 22, 2011 5:34 am

Here is an extremely simplified version of the final program. It utilizes one pushbutton that cycles through the different brightness settings. I have setup this program in a variety of formats where 1-5 pushbuttons are used, several rgb led's are powered,etc....and they have all performed well using this template.

The best part about this program is its' high resolution. You can adjust the on duty cycle from 0-255 out of a 255 length period.

This program runs flawlessly on an 18f4685 and has a few hiccups on the 16f887 every so often. The hiccups that you encounter ARE NOT a problem with the program, but a problem with values in the look up table and uC you are using. If you play around with the LUT values you will hopefully be able to smooth out any color/flicker issues that arise with your uC, I was able to. Some chips will have issues some will not...The reason for this is beyond me.

I was surprised to find this program runs best without using interrupts as in the mood_light bit bang pwm demo program referenced by medelec. I tried numerous methods for implementing this and found the version below run it the best.

Thanks again medelec for helping me figure all of this out.
Hopfully this program and circuit will help somebody else learn how implement LUT's or perhaps drive an rgb led.
Attachments
RGB_LUT_Circuit.JPG
RGB_LUT_Circuit.JPG (86.52 KiB) Viewed 33427 times
LUT_RGB Modified1.xls
(46 KiB) Downloaded 824 times
rgbLUT_1Perfect.fcf
(14.36 KiB) Downloaded 938 times
These users thanked the author zen for the post:
Chirikas (Sat Jan 22, 2011 11:11 am)
Rating: 5.56%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Sat Jan 22, 2011 9:00 am

zen wrote:I was surprised to find this program runs best without using interrupts as in the mood_light bit bang pwm demo program referenced by medelec. I tried numerous methods for implementing this and found the version below run it the best.

Probably reason is timing of interrupt. Your program works fine now, but if you add any more functions, then timing of LED lighting will be affected. I will see if I can match them up so timing LEDS or on/off are the same with and without using interrupt just to see. It's great that you have a working version.

zen wrote:Thanks again medelec for helping me figure all of this out.
Hopfully this program and circuit will help somebody else learn how implement LUT's or perhaps drive an rgb led.

Your welcome. It's great that you and other members post what you have got working, so people can lean by example. Thanks for that.

Re connection of switches to i/p ports.
It is not recommended to leave and i/p floating See Fig1. This is because interference/noise etc. can make the i/p rise to A voltage which is either above logic 1 voltage, or in between logic 0 and logic 1. If you did not want to connect a pull-up or pull down resistor, then you can use a port that can be configured for internal weak pull-ups.

Value of resistor is a trade off between keeping voltage near to VDD or VSS and current drawn. E.g if value is too high, then becomes less effective in higher electrical noise environment, but current flow is less. If value is too low, then too much current is drawn so can cause loading of supply, or current rating of chip to be exceeded. Its hobsons choice, but 10K I believe is a fair compromise but can use 1K - 100K. Other people may have different preferences.
Connecting Switches.jpg
Connecting Switches.jpg (72.81 KiB) Viewed 33423 times
Last edited by medelec35 on Sat Jan 22, 2011 9:37 am, edited 1 time in total.
These users thanked the author medelec35 for the post (total 2):
Chirikas (Sat Jan 22, 2011 11:10 am) • Werner (Wed Nov 23, 2011 12:18 pm)
Rating: 11.11%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Chirikas
Posts: 3
Joined: Thu Jan 20, 2011 2:00 pm
Has thanked: 2 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby Chirikas » Sat Jan 22, 2011 9:10 am

I was looking at Zen's scheme and I am wondering, if I would make it and programmed the chip with your program, would it work ? as far is a saw on the internet everywhere transistors is being used in led output. so i am quite confused.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8287
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Sat Jan 22, 2011 11:38 am

Transistors are used if you want to drive more current through LED's than microcontroller can supply (max current supplied/source = 25mA or a total of 250mA) . E.g Peak of more than 25mA per pin or 250mA in total, or where several LEDs are in series, so require a higher voltage source than 5V microcontrollers can supply. With zen's circuit.
Since only using 3 LEDs with series resistors to limit current through each LED (max current of standard LEDS usually about 20mA) transistors to drive LED's will not be required.
So yes it would work.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Chirikas
Posts: 3
Joined: Thu Jan 20, 2011 2:00 pm
Has thanked: 2 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby Chirikas » Sat Jan 22, 2011 12:04 pm

thank you for your help. For the first time I would use only three small leds or one with four contacts, just to try how everything works. I have few other questions, maybe you have zens circuit drawn with some software? Maybe it would help me to understand all connections. Maybe some other chip could be used instead of 16f884 and 16f887?