Mathematics

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Mathematics

Post by Jan Lichtenbelt »

I will use the graphic LCD and I intend to draw a circle. Is it possible to use the mathematical functions like cosinus and sinus in Flowcode 4?

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:

Re: Mathematics

Post by Benj »

Hello Jan,

Yes this is possible.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Mathematics

Post by Jan Lichtenbelt »

Hello Ben,

I did not expect that it would be possible. I tried it directly. Declaring the variable A (float) and in the C-Code box I put: A= cos(1). But this results only in the message: unknown indentifier. What's wrong?

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:

Re: Mathematics

Post by Benj »

Hello,

In Flowcode PIC the trig functions are unavailable unless you use the HiTech compiler. A discussion on how this is done is available from here.

http://www.matrixmultimedia.com/mmforum ... =26&t=6812

My other suggestion would be to avoid the use of trig and instead use a look up table to calculate your COS and SIN values.

http://www.matrixmultimedia.com/mmforum ... =26&t=3543

This will probably be easier as you will be able to pre multiply up the cooordinates in your lookup table to define the size and location of the circle on the display.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Examples of Sin and Cos functions

Post by Jan Lichtenbelt »

I made an example of lookup table for both sinus and cosinus functions, based on Ben's suggestions in http://www.matrixmultimedia.com/mmforum ... =26&t=3543

The example uses 10 values stored in the EEPROM, instead of the C-program, for angles between 0, 10... 90 degrees. Angles between these values will be rounded to a mulple of 10. All angles are allowed even > 360 degree or negative angles.
The results can be shown in eg. the actual graphic display's (like E-blocks EB057 and EB058). X- and Y-scaling is possible.

Good luck.
Attachments
Sin_and_Cos_functions.fcf
(19.43 KiB) Downloaded 558 times

Post Reply