Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] how to use tangent inverse in Mikro C for Pic

Status
Not open for further replies.

AmmarAkhlaq

Junior Member level 1
Junior Member level 1
Joined
Dec 12, 2013
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
162
can any one teach me how to use tangent inverse function in Mikro C. And displaying it result on leds.
THis is what iam doing but no result.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
double X,Y,Zi,thetaa1;
int thetaa;
void SysInit();
double atan2(double y, double x);
void main(){
      X=2;
      Y=5;
      SysInit();
      while(1)
      {
        thetaa1= atan2(Y,X);
        thetaa = (int)(thetaa1*57.295);
        PORTB=thetaa;
      }
 
}
void SysInit()
{
  ADCON1=0x06;    // disable ADC and make all the pins of Port A as digital input
  TRISA=0xFF;
  PORTA=0x00;
  TRISB=0x00;
  PORTB=0x00;
  TRISD=0x00;
  PORTD=0x00;
  TRISE=0x00;
  PORTE=0x00;
  TRISC.B6=0;
  TRISC.B7=0;
  TRISC.B4=1;    // SDI input
  TRISC.B3=1;    // SCK input from master
  TRISC.B5=0;    // SDO output
  SSPSTAT.SMP=0; // input data sampled at middle
  SSPSTAT.CKE=0; // transition from idle to active
  //SPI1_Init_Advanced(_SPI_SLAVE_SS_ENABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
}

 
Last edited:

If result of atan2() is < 1 then when you cast to int the value after decimal point is truncated and you get 0.
 

Assign the return value of atan2() function to a double type variable. Don't cast it to integer type.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top