Flowcode maths problem help please

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

markkkk
Posts: 21
Joined: Fri Jul 28, 2006 3:30 am
Location: Brisbane Australia
Contact:

Flowcode maths problem help please

Postby markkkk » Sun Aug 13, 2006 10:31 am

I am a new user of Flowcode and I am enjoying learning it and its works just great. But I have a problem doing some maths with it. I have no idea how to solve this. First of all I am sending address data to a DDS chip which will determine the output frequency of the DDS chip. It is parallel loaded with a 40 bit tuning word. It is done by basically sending the chip a reset then sending the LSB of 8 bits then pulsing the chip to say here is the first load then send the next 8 bits etc till you get to the MSB which is the 32 bit word so far then the last 8 bits of the 40 bit word are basically a static load then you tell the chip with another pulse on a port to read the total 40bit load that you put into it in a 8bit parallel load five times. I basically have all of the timing and stepping done no problems but I need to calculate the tuning word of 32 bytes within the program as loading in by hand the pre programmed 32 bit word for 50 plus frequencies will be a massive job and not enough memory in the chip I suspect. Now this is only a 8bit micro?..how can I do this?... the formula to get the 32 bit word is basically (freq x 2 to the 32nd power) divded by the ref xtal freq..... I dont know how to express on this keyboard 2 to the 32 but of course the number is 4294967296 and once the maths problem is resolved you convert the number to binary and you get the 30 or 32 bit word....if its only 30 then you add two 0's to it to make it 32. Can anyone hel;p with this?....I may have to get some C code inserted or mabye create some macro I am not sure...any suggestions would be appreciated but please remember I am a complete novice with programming but I am not dumb and should be able to work it out once shown

User avatar
Steve
Matrix Staff
Posts: 3080
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 391 times
Contact:

Postby Steve » Mon Aug 14, 2006 9:19 am

32-bit maths is going to be tricky on an 8-bit micro and take up a fair bit of space within the program memory, so I would suggest a different route - use of a lookup table.

50 32-bit words can be stored in 50*4 = 200 8-bit bytes, which can be pre-calculated on a PC using a spreadsheet. Your values can be stored into a lookup table within the program ROM itself (if you need help on this, we can show you how).

Incidentally, I'm certain that the maths routines to do this calculation on the fly within your program would be *far* in excess of the 200 program instructions necessary to implement a look-up table.

I hope this helps.

markkkk
Posts: 21
Joined: Fri Jul 28, 2006 3:30 am
Location: Brisbane Australia
Contact:

Postby markkkk » Mon Aug 14, 2006 9:54 am

Hi Steve...thanks for the quick reply. I know what a lookup table is but I will need some help to get it started then I am sure I can do the rest. I can calculate all of the necessary binary words but wasnt sure whether It would be too big. There is a 16F84 program that programs the same DDS I want to use. but it basically is a free tuning one and calulates on the fly..it is all written is assembler and I think I can decipher where they do this with a ARG command and they do ti 5 times but past that I cant get any further. Thats why I think flowcode is such a great tool. I mean I am programming steps and ports and bits and pieces to actually do things....nothing too complex of course but most of the stuff I do isnt that complex...this DDS project is probably very ambitious for me at this stage but if you dont challenge yourself you dont learn.

markkkk
Posts: 21
Joined: Fri Jul 28, 2006 3:30 am
Location: Brisbane Australia
Contact:

Postby markkkk » Mon Aug 14, 2006 10:02 am

Steve...just to let you know what I am using...I am using the 16F88 supplied with my V3 development board. I then will have outputs through the strip connector on the V3 to control the AD9851 DDS chip to start all this programming. The next step after getting the frequency data programming and scanning of these frequencies done is to read via the ADC the RSSI level from the receiver that I am using the DDS to scan. This will then be sent to a graphic display so I realise there will be other interfacing and programming to do this but I think the graphic side of this will be easier than this first part. I have trolled the web trying to find easy to understand beginner stuff with programming and "how to do" things but there really isnt a lot around they all assume you have a fairly substancial knowledge of programming...what comes first "the chicken or the egg"

User avatar
Steve
Matrix Staff
Posts: 3080
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 391 times
Contact:

Postby Steve » Mon Aug 14, 2006 12:48 pm

In v2 of FlowCode, you can use a "#defines" component with code similar to the following to define a lookup table:

Code: Select all

const char table[] = {10, 20, 30, 40, 50, 60, 70, 80};


Assuming you have 2 variables IDX and VAL in FlowCode, you would access this table using a 'C' icon with the following code:

Code: Select all

FCV_VAL = table[FCV_IDX];


To do this in v3 of FlowCode, define the look-up table in the "definitions" area of the "supplementary code" window (but use "rom char" instead of "const char"). Access the table in v3 in a similar way to the above.

Alternatively, you could create your own lookup table in Assembly (and insert this into a 'C' icon). There is a good application note about lookup tables in assembly on the Microchip website.

Hopefully this will get you going.

markkkk
Posts: 21
Joined: Fri Jul 28, 2006 3:30 am
Location: Brisbane Australia
Contact:

Postby markkkk » Wed Aug 16, 2006 12:07 pm

OK maybe I am not as smart as I think I am. :(..I have looked all over the microchip website looking for the appnote on the lookup table in assembler. Cant seem to find what I think I am looking for. There are bits on lookup tables but it doesnt seem to fit what I want to do. Also I couldnt find anything in the flowcode help files or tutorials about lookup tables either. The reply that you sent me doesnt really gell with my head yet either. I think I may need some clearer direction that I might be pointed to so I can understand a bit more. I understand about eprom location addresses etc no problem and the data to be loaded into those addresses and how it should be able to be done. That I can understand and I can make up all the 40 bit words to go into those allocations. I know I have to call those 8bit sections of those locations and can load them to the port as required. I think I just need the commands that I need to call each specific loaction. I have done a lot of seaching on the net about lookup tables in C and assembler and it just doesnt make any sense to me yet. Although I must say I didnt really find a lot of info about it either. Is there any more info about flowcode than the 28 tutorials and the flowcourse?...

Ian
Posts: 110
Joined: Thu Sep 29, 2005 10:53 am
Location: Matrix Multimedia
Been thanked: 1 time
Contact:

Postby Ian » Fri Aug 18, 2006 10:42 am

Hope this helps.

http://www.microchip.com/stellent/idcpl ... e=en011102

"This application note shows how to implement a table look-up for the following devices: ? PIC12CXXX ? PIC12CEXXX ? PIC16CXXX ? PIC16CEXXX ? PIC16FXXX The examples shown are for the PIC16CXXX family. An explanation of differences for the PIC16C5X family is at the end of this application note. To access data in program memory, a table read operation must be performed. The table consists of a series of retlw K instructions where, the 8-bit table constants are assigned to the literal K. The first instruction in the table computes the offset to the table by using addwf PCL,F and consequently, the program branches to the appropriate retlw K instruction "