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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Look Up Tables using Flowcode and Microsoft Excel

Post by Benj »

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

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

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by RichardB »

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!!!!!!

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by Dirk Bubley »

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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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
Martin

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by Dirk Bubley »

Hi medelec,

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

BR

Dirk

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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

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

Post by zen »

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
(49.97 KiB) Downloaded 1292 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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:
http://www.matrixmultimedia.com/mmforum ... 21&p=16827
and here:
http://www.matrixmultimedia.com/mmforum ... =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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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 1069 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

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

Post by zen »

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... http://www.matrixmultimedia.com/mmforum ... 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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:
http://www.matrixmultimedia.com/mmforum ... 21&p=16827
so your interrupt in a similar format to this:
Interrupt PWM.jpg
Interrupt PWM.jpg (119.69 KiB) Viewed 46666 times

Hope this helps to clear things up.
Martin

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

Post by zen »

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 (http://www.matrixmultimedia.com/mmforum ... =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 1149 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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 1106 times
Martin

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

Post by zen »

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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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 1079 times
Martin

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

Post by Chirikas »

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

Post by zen »

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 46461 times
LUT_RGB Modified1.xls
(46 KiB) Downloaded 1001 times
rgbLUT_1Perfect.fcf
(14.36 KiB) Downloaded 1188 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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 46457 times
Last edited by medelec35 on Sat Jan 22, 2011 9:37 am, edited 1 time in total.
Martin

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

Post by Chirikas »

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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look Up Tables using Flowcode and Microsoft Excel

Post by medelec35 »

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

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

Post by Chirikas »

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?

Post Reply