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

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby medelec35 » Sat Jan 22, 2011 12:48 pm

Chirikas wrote: I have few other questions, maybe you have zens circuit drawn with some software? ?

Sorry have not got the circuit diagram
Chirikas wrote: Maybe it would help me to understand all connections. Maybe some other chip could be used instead of 16f884 and 16f887?

The great feature of flowcode is you don't have to sick with a circuit diagram posted.
You can load up the posted flowchart then select your own choice of microcontroller, o/p and i/p pins and osc type e.g crystal, ceramic, internal (so long as target device supports internal osc)
Just remember to set the configuration settings for your target device, or you will find hardware will not work.
See:
viewtopic.php?f=26&t=6936
For help and general advice.
There are plenty of people on this forum that are willing to help you when you get stuck.
As for drawing a schematic, if you want to give that a bash yourself, there seems to be a new popular packge called Designspark PCB. Only just downloaded and registered it all for free!
Plus unlike other free design software this one has no limitations, can import eagle libraries, good support and recommended by RS components.
If you're hardware is not working as expected, try looking here first:
viewtopic.php?f=26&t=6936

If you find any posts that are useful, please click on the 'thumbs up' icon next to Quote button on that post.
User avatar
medelec35
Valued Contributor
Valued Contributor
 
Posts: 5312
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire
Has thanked: 1407 times
Have thanks: 1654 times

Advertisement

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby zen » Sat Jan 22, 2011 6:08 pm

I guess I should have explained the circuit drawing. You should scroll down to the bottom of the circuit schematic drawing to the detail on how I made the "reset" and "button" inputs. I did not have enough room to draw them in full on the top picture so I drew them on the bottom. I based the pushbutton design from some demo board made by microchip. If i'm ever in doubt about a design element I look up a microchip demo board that has what I want and use the schematic from their board. The pushbutton circuit is working fine on the board I built. I am not a professional or any kind of authority on embedded circuits. If in doubt listen to medelec. He is far more knowledgeable than I on this subject.

I liberally use capacitors(.1uf ..'104'/small yellow..most of the time) to create a low pass filters. ( limits circuit noise and/or minimizes contact bounce from the pushbutton for ex.).

I have powered 5 rgb led's without any problems right from my 16f887, 16f877 and 18f4685. I suppose one of the benefits of using PWM and utilizing POV is that it minimizes power consumption. My entire circuit is powered from a modified moto. razr usb cell phone charger rated at aprx. 500mA/5v. You do not need a switching transistor to make this work for 5 rgb led's (=15 regular led's) as far as I can tell.
-------------------------------------------------------------
edit....here are a few pictures showing some the various colors and the board I built....
Attachments
begin.JPG
begin.JPG (49.84 KiB) Viewed 3352 times
combinedcolors.JPG
combinedcolors.JPG (68.9 KiB) Viewed 3352 times
zen
 
Posts: 8
Joined: Tue Dec 21, 2010 9:50 pm
Has thanked: 4 times
Have thanks: 4 times

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby zen » Fri Feb 11, 2011 5:12 pm

I decided to activate the free trial of the Hi-Tech C compiler and tried to compile the RGB LED LUT program using it. The BoostC compiler has no problems with the code but the HTC compiler didn't like the program and is returning the following errors:

Warning [374] C:\...\RGB_lut_MAIN.C; 105.5 missing basic type; int assumed
Error [314] C:\...\RGB_lut_MAIN.C; 105.5 ";" expected
Warning [374] C:\...\RGB_lut_MAIN.C; 112.5 missing basic type; int assumed
Error [314] C:\...\RGB_lut_MAIN.C; 112.5 ";" expected
Warning [374] C:\...\RGB_lut_MAIN.C; 119.5 missing basic type; int assumed
Error [314] C:\...\RGB_lut_MAIN.C; 119.5 ";" expected
Error [192] C:\...\RGB_lut_MAIN.C; 479.15 undefined identifier "RED"
Error [981] C:\...\RGB_lut_MAIN.C; 479.33 pointer required
Error [981] C:\...\RGB_lut_MAIN.C; 479.33 pointer required
Error [192] C:\...\RGB_lut_MAIN.C; 480.17 undefined identifier "GREEN"
Error [981] C:\...\RGB_lut_MAIN.C; 480.37 pointer required
Error [981] C:\...\RGB_lut_MAIN.C; 480.37 pointer required
Error [192] C:\...\RGB_lut_MAIN.C; 481.16 undefined identifier "BLUE"
Error [981] C:\...\RGB_lut_MAIN.C; 481.35 pointer required
Error [981] C:\...\RGB_lut_MAIN.C; 481.35 pointer required

Ive tried several different ways to declare the " rom char* RED |BLUE|GREEN {1,2,3,......}; " array and get a different error every time. I'm not sure what must be done differently to make the LUT work for both compilers.

edit--------------------link to htc website on this topic

http://www.htsoft.com/support/faqs.php#faq22


edit #2---------------------------------------------

note: the original code that won't work with HTC used the format: "rom char * red = {1,2,3....}; "

I was able to make this program work by using any one of the following 3 formats:

1. char* red[]= {1,2,3....}; // All of these examples worked the same from what I could tell
2. unsigned char* red[] = {1,2,3....};
3. volatile unsigned char* red[] = {1,2,3....};

char* red[] = {red, array, here,....};

unsigned char* green[] = {green, array, here,....};

volatile unsigned char* blue[] ={blue, array, here,....};

I'm still getting a massive list of warnings saying "illegal conversion of integer to pointer", especially if I compile the code in MPlab instead of FC. I sort of understand the problem but don't either. All I know is that the program is working as usual and compileable with HTC.
zen
 
Posts: 8
Joined: Tue Dec 21, 2010 9:50 pm
Has thanked: 4 times
Have thanks: 4 times

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby Steve » Mon Feb 14, 2011 8:08 am

This might be a better way:

In BoostC, define constant arrays like this:
Code: Select all
rom char* my_const_array = {1,2,3};


And in HITECH, use this:
Code: Select all
const char my_const_array[] = {1,2,3};


In fact, to make the code work with either compiler without modification, do something like this:
Code: Select all
#ifdef _BOOSTC
  rom char* my_const_array = {1,2,3};
#endif
#ifdef HI_TECH_C
  const char my_const_array[] = {1,2,3};
#endif

For this message the author Steve has received thanks:
zen(Mon Mar 07, 2011 10:46 pm)
Rating:6.25%
 
Steve
Flowcode v5 User
 
Posts: 2656
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 22 times
Have thanks: 188 times

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby JohnCrow » Wed Apr 27, 2011 7:24 pm

medelec35 wrote: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


Written a simple flowchart to combine HighByte LowByte values entered on the keypad, using above formula
Attachments
Program 5 - Combine with keypad input.fcf
(15.5 KiB) Downloaded 229 times
1 in 10 people understand binary, the other one doesn't !
User avatar
JohnCrow
Valued Contributor
Valued Contributor
 
Posts: 1244
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 389 times
Have thanks: 547 times

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby JohnCrow » Wed Apr 27, 2011 7:27 pm

medelec35 wrote: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


Written a simple flowchart to combine HighByte LowByte values entered on the keypad, using above formula
Attachments
Program 5 - Combine with keypad input v2.fcf
(11.5 KiB) Downloaded 234 times
1 in 10 people understand binary, the other one doesn't !

For this message the author JohnCrow has received thanks: 2
medelec35(Wed Apr 27, 2011 8:18 pm), Werner(Wed Nov 23, 2011 1:29 am)
Rating:12.5%
 
User avatar
JohnCrow
Valued Contributor
Valued Contributor
 
Posts: 1244
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 389 times
Have thanks: 547 times

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby Eissa88 » Sat Feb 18, 2012 2:09 pm

hello there,

I want to use LUT to navigate between some words, can you show me how to do that in flowcode v4 please?
Eissa88
 
Posts: 1
Joined: Thu Feb 16, 2012 9:56 pm
Has thanked: 0 time
Have thanks: 0 time

Re: Look Up Tables using Flowcode and Microsoft Excel

Postby Benj » Mon Feb 20, 2012 11:36 am

Hello,

Do you mean you need to store string data into a lookup table?

One way to do this is to have two arrays of data one for your string data and the other for the string lengths. Both variables should probably be byte based.

StringData[] = "HelloWorldMyNameIsBen"
IndexData[] = 0,5,10,12,16,18,21

Then when you need to pull out a word you first need to know its index so say you want to pull out word 2 - "World".

First you would look up the second index remembering that the numbering starts from 0.

idx = 1
Index = IndexData[idx] which equals 5

You then pull out the index for the next string so you know where the end of the current string is.

idx = idx + 1
NextIndex = IndexData[idx] which equals 10

You can then create a loop to cycle through each of the bytes in the string.

counter = Index
while (counter < NextIndex )
{
... = StringData[counter]
}

Hope this helps.
User avatar
Benj
Matrix Staff
 
Posts: 8708
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1465 times
Have thanks: 1813 times

Previous

Return to Programming Tips & Tricks

Who is online

Users browsing this forum: Google [Bot] and 0 guests