Wrong values with COSINE!


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Exclamation Here it is:

    Thanks for your interest , i will try to provide more details and hope they will be helpful for you.

    But first, in that link, i am not using "ATN and HYP", nor "X and Y", nor arctan or arcos or logarith or interpolation...

    all my work is that i am getting Power. It is given as you know by:

    P = V x I x Cos alpha.

    and i am using PIC 16F876A with PicBasic Pro.

    I solved the matter of V and I by applying sensors. and for the phase between them, i used a PLL. now i am inserting all 3 variables as inputs for the PIC and i need it to give me the correct power but i discovered that it is giving very wrong values!

    i found out that it's from the "cos" because as it is stated, the cosine give value in 2's complement from -127 to +127 and not in the traditional way from 0 to 359 degrees...

    But for us, we use the traditional numbering system.... so i need to use it! But it is not working... i can do it with a table but i need to find out if there is a mathematical way to use the same function "cosine" , already provided..

    thanks again and i hope you will be able to help me.

  2. #2
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eng4444
    all my work is that i am getting Power. It is given as you know by:

    P = V x I x Cos alpha.
    And out of this silly task you are able to make such a lot of dust ?

    P=V*I 16 Bit
    X=COS(Alpha*255/360) 8 Bit 2-komplement
    Minus=X.7
    P=P*(X and %01111111) 32 Bit !!!
    P=Div32 127
    It's quick-n-dirty, maybe there is an error inside....

    And all the way without using this boring 0,xxx, only integers !
    Ha, the good old times are back, where programmers must understand what they are doing and counting the bits...

    Just USE YOUR BRAIN, not your mouth !



    Hello Mel,
    Yes, I ruin you prices and your time....
    but I inserted 1 mistake, so this code will not work right. But some postings ago, there was the right hint. Maybe we could train his brain....
    Last edited by BigWumpus; - 7th May 2006 at 22:21.
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  3. #3
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Unhappy You know what i like about forums?

    Quote Originally Posted by BigWumpus
    And out of this silly task you are able to make such a lot of dust ?

    P=V*I 16 Bit
    X=COS(Alpha*255/360) 8 Bit 2-komplement
    Minus=X.7
    P=P*(X and %01111111) 32 Bit !!!
    P=Div32 127
    It's quick-n-dirty, maybe there is an error inside....

    Just USE YOUR BRAIN, not your mouth !



    Hello Mel,
    Yes, I ruin you prices and your time....
    but I inserted 1 mistake, so will not work right. But some postings ago, there was the right hint. Maybe we could train his brain....
    --------------------------------------------------------------------


    It's just that you like to show up... i wonder if you succeeded because for me you were just acting like a clown... trying to be nice to mel just by making fun of me.

    i wonder what you get from all this - stupid... and moreover, you wanna train my brain? lol and you submit and error on purpose???!

    i came here because i didn't know how to do it so do you really find it worthy to take all your advantages and try to make fun of me?? or just to appear the intelligent?? you are idiot! keep your knowledge for yourself.

    In case someone else has an idea about my question i'll be grateful.



    By the way Mel,

    Did you made this forum just to make fun of people with your friends?
    thanks a lot for your kindness.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    It's not my forum. I just make sure folks don't abuse it (or each other) too much...

    From your first post, I gather this is a serious project with a serious problem... unfortunately I only answer the frivolous ones - serious I leave to other people - unless there's money involved.

    But really, to join a forum just in order to ask folks to drop what they're doing and IMMEDIATELY write code for you because you need it URGENTLY is really the height of bad manners - and you should expect a little fun to be made from it.

    My original post pointed you to the fact that you CANNOT have fractions with PICBasic... ONLY INTEGERS. If you are capable of doing the circuit you describe, then you are also capable of a little high-school mathematics in converting degrees to radians. Then feeding that figure into the provided COS function and converting the resultant into the required COSINE but scaled-up because we must always work in INTEGERS.

    You have been shown how to convert degrees to radians and how to get your Cosine function... a little bit of experimentation on your part will complete the code and you will have a working program. So make an effort, try to understand what's been written (thank you BigW), and don't expect everyone else to do it all for you...

    See... this is why we're not getting rich on this forum... somebody always does it for free... *sob*

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Nicely done Melanie.

    I'm affraid I would have been much more severe.

    However, my severeity would have been directed to everyone besides ENG4444.

    Maybe it wasn't the best entrance to our forum, but. The words, idiot, stupid, and the dreaded F word came from well established users. Not the poor guy that made his first post here today. (originally)

    As the "Bad Cop" I'd like to "Run you ALL in" for inciting a riot.

    Fortunately, there's a "Good Cop" around that handles children better than I do.
    <br>
    DT

    P.S. Luciano excluded!

  6. #6
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Arrow thanks...

    I have joined several forums and it was the first time where i see people asking for money and the sentence "don't expect to do it for free".

    it's a real big shame because orginally, that was the aim of forums in case some of you do not know.


    in all cases, i don't wanna get far from my subject. I'm still asking that question and still waiting more answers

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You know, if I want a Pizza and I don't know how to make one...

    1. I look in a Cookbook and follow the recipie (for Cookbook read PICBasic manual)...
    2. I go to Cookery School and learn...
    3. I at least make an attempt at something and if it doesn't turn out right then perhaps somebody will feel sorry for me and help me out...
    4. I pay someone to bring it to my door...

    I sure as hell don't run down the street shouting "I'm hungry and I want someone to make me a Pizza NOW!" and when neighbours offer their recipies and suggestions I dismiss them without at least trying to understand what they're offering me...

    Quick (one minute of coding) and dirty 0-90 degree FREE Cosine demonstrator...

    If you don't like it... go write your own...
    If you want 91-359 Degrees... go write your own - it's not immediately obvious...
    If you don't like the precision... go write your own...
    ...I think you get the idea...

    Code:
    	Angle Var WORD
    	Cosine var WORD
    	Radian var BYTE
    	TempA var WORD
    	TempB var WORD
    
    	LCDOut $FE,1
    Loop:
    	For Angle=0 to 90
    		Gosub GetCosine
    		LCDOut $FE,$80,"Angle=",#Angle,"  ",$FE,$C0,"Cosine="
    		LCDOut #Cosine DIG 3,".",#Cosine DIG 2,#Cosine DIG 1,#Cosine DIG 0
    		Pause 1000
    		Next Angle
    	Goto Loop
    
    GetCosine:
    	Radian=(Angle+1)*255/360
    	TempA=COS(Radian)
    	TempA=TempA & %01111111
    	TempB=TempA*1000
    	Cosine=DIV32 127
    	Return
    Oh... and before you say anything to the contrary... yes it DOES work...

  8. #8
    Eng4444's Avatar
    Eng4444 Guest


    Did you find this post helpful? Yes | No

    Thumbs up Sorry i forgot one thing..

    Thanks Melanie a lot.

    Your code is great and it worked perfectly.


    Luciano,

    Also a big thanks because that article is extremely important.

Similar Threads

  1. WRITECODE stores wrong 14-bit word values in FlashMEM
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 26th June 2009, 04:35
  2. Looking at pic basic pro symbol values in mplab 8.15a simulator
    By ukemigrant in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th May 2009, 13:18
  3. Need help calculating OSC cap values
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 26th June 2008, 21:27
  4. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 08:02
  5. 16F877A problem: "coupled" digital values
    By Lupo83 in forum General
    Replies: 16
    Last Post: - 4th December 2007, 12:46

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts