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.

Interfacing PIC18F8722 and TWS 434/ RWS 434

Status
Not open for further replies.

Mr.Khiros

Junior Member level 3
Junior Member level 3
Joined
Aug 25, 2013
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
176
Hi ,
i'm tring to send data from a PIC18F8722 using TWS 434/ RWS 434 & recieve it with PIC16F877A , but my LCD don't show anything
 

Attachments

  • ADC_RF.rar
    107.2 KB · Views: 92

There are a lot of errors in your code.

Your Function() function is returning a char type. It has to return a string type.


Code C - [expand]
1
2
3
4
char* return_my_name()
{
    return "zeeshan";
}



https://stackoverflow.com/questions/10615492/function-with-string-as-return-type-in-c
https://stackoverflow.com/questions/3263972/cant-a-function-return-a-string-without-pointers

StatP, DynP etc... are strings and you are doing math operations on string like


Code C - [expand]
1
(StatP/29.9213)



Do the math operations first. use float variables like fStatP, fDynP, etc.. to hold the float data of ADC. then do like


Code C - [expand]
1
(fStatP/29.9213)



Then convert the necessary float values to string and then send to UART.
 
I tried this code but nothing occurs , i think that there is a prb with interfacing in the simulation
PHP:
unsigned char Pressure[23], Temperature[23];
int strLength  =0;
float ADRead0, StatP , DynP , QNH,TAT , AOA , Mack , TAS , SAT , TA ,PA = 0;
extern  float Function(int n);

void main(){

        TRISA = 0b111111;
        PORTA = 0x00;
        TRISC = 0x80;
        PORTC = 0x00;
        ADCON1 = 0b10001010;
        CMCON = 0x07;
        CVRCON = 0x00;

        UART1_init(9600);
        Delay_ms(1000);

        while (1){
                        StatP = Function(0);  // function call
                        DynP = Function(1);
                        QNH = Function(2);
                        TAT = Function(4);
                        AOA = Function(5);

               // AOA Correction
                    if  (AOA = 15 ) DynP = DynP-(DynP*(5/100)) ;
                    if  (AOA = 20 ) DynP = DynP-(DynP*(12/100)) ;
                    if  (AOA = 25 ) DynP = DynP-(DynP*(22/100)) ;

               // Pressure Altitude calculation
                   PA = (288.16/0.0019812)*(1-pow((StatP/29.9213),0.190255)) ;
               // Mack Number claculation
                   Mack = sqrt(5*((pow((1+(DynP/StatP)),(2/7)))-1)) ;
               // Static Air Temperature calculation
                   SAT = TAT/(1+0.2*pow(mack,2)) ;
               // True Air Speed calculation
                   TAS = 38.968*Mack*sqrt(SAT) ;
               // True Altitude calculation
                   TA = (sat/0.0019812)*((pow((QNH/StatP),0.190255))-1) ;

               // Sending data with a delay of 1 sec
                        FloatToStr(PA, Pressure);
                        strLength = strlen(Pressure);
                        Pressure[strLength - 1] = 'T';
                        Pressure[strLength] = 'x';
                        Pressure[strLength + 1] = '\0';
                        UART1_Write_Text(Pressure);
                        uart1_write(0x0d);
                        delay_ms(1000);  

        }

}

        float Function(int n) {
                       ADRead0 = ADC_Read(n) * 0.1559251559251559;
                       return ADRead0;
        }
 

See attached file.

97247d1381753964-adc_rf.png


ADC_RF Tx Code


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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#define METHOD1
//#define METHOD2
 
int strLength = 0;
unsigned char Pressure[23], Temperature[23];
float ADRead = 0.0, fStatP = 0.0, fDynP = 0.0, fQNH = 0.0, fTAT = 0.0, fAOA = 0.0, fMack = 0.0, fSAT = 0.0, fTAS = 0.0, fTA = 0.0, fPA = 0.0;
#ifdef METHOD1
      unsigned char StatP[23] , DynP[23] , QNH[23], TAT[23], AOA[23], Mack[23], TAS[23], SAT[23], TA[23], PA[23];
#elif METHOD2
      unsigned char sTemp[23];
#endif
 
void Delay1Sec(){
    Delay_ms(1000);
}
 
void UART1_CRLF(){
    UART1_write(0x0D);
    UART1_write(0x0A);
}
 
float Function(int n) {
    ADRead = ADC_Read(n) * 0.1559251559251559;
    FloatToStr(ADRead, Pressure);
    strLength = strlen(Pressure);
    Pressure[strLength - 1] = 'T';
    Pressure[strLength] = 'x';
    Pressure[strLength + 1] = '\0';
    
    UART1_Write_Text(Pressure);
    UART1_CRLF();
    Delay1Sec();
    
    return ADRead;
}
 
#ifdef METHOD1
void Float2String(){
    FloatToStr(fStatP, StatP);
    FloatToStr(fDynP, DynP);
    FloatToStr(fQNH, QNH);
    FloatToStr(fTAT, TAT);
    FloatToStr(fAOA, AOA);
    FloatToStr(fPA, PA);
    FloatToStr(fMack, Mack);
    FloatToStr(fSAT, SAT);
    FloatToStr(fTAS, TAS);
    FloatToStr(fTA, TA);
}
 
void UART1Send(){
    UART1_Write_Text(PA);
    UART1_CRLF();
    Delay1Sec();
    UART1_Write_Text(Mack);
    UART1_CRLF();
    Delay1Sec();
    UART1_Write_Text(SAT);
    UART1_CRLF();
    Delay1Sec();
    UART1_Write_Text(TAS);
    UART1_CRLF();
    Delay1Sec();
    UART1_Write_Text(TA);
    UART1_CRLF();
    Delay1Sec();
}
#elif METHOD2
void F2S_UART_CRLF(){
    FloatToStr(fStatP, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fDynP, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fQNH, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fTAT, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fAOA, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fPA, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fMack, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fSAT, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fTAS, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fTA, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
}
#endif
 
void main(){
 
      TRISA = 0b111111;
      PORTA = 0x00;
      TRISC = 0x80;
      PORTC = 0x00;
      ADCON1 = 0b00011000;
      ADCON2 = 0b10101001;
      CMCON = 0x07;
      CVRCON = 0x00;
 
      UART1_init(9600);
      Delay_ms(1000);
 
      while (1){
 
              fStatP = Function(0);  // function call
              fDynP  = Function(1);  // function call
              fQNH   = Function(2);  // function call
              fTAT   = Function(5);  // function call
              fAOA   = Function(6);  // function call
 
              // AOA Correction
              if(fAOA = 15.0) fDynP = fDynP-(fDynP*(5.0/100.0));
              if(fAOA = 20.0) fDynP = fDynP-(fDynP*(12.0/100.0));
              if(fAOA = 25.0) fDynP = fDynP-(fDynP*(22.0/100.0));
 
              // Pressure Altitude calculation
              fPA = (288.16 / 0.0019812) * (1 - pow((fStatP / 29.9213), 0.190255));
              // Mack Number claculation
              fMack = sqrt(5 * ((pow((1 + (fDynP / fStatP)), (2 / 7))) - 1));
              // Static Air Temperature calculation
              fSAT = fTAT / (1 + 0.2 * pow(fMack, 2)) ;
              // True Air Speed calculation
              fTAS = 38.968 * fMack * sqrt(fSAT) ;
              // True Altitude calculation
              fTA = (fSAT / 0.0019812)*((pow((fQNH / fStatP), 0.190255)) - 1);
 
              #ifdef METHOD1
                  // Float to String Conversions
                  Float2String();
 
                  // Sending data with a delay of 1 sec
                  UART1Send();
              #elif METHOD2
                  F2S_UART_CRLF();
              #endif
      }
 
      /* function max returns greater one of its 2 arguments: */
}

 

Attachments

  • ADC_RF rev1.rar
    147.3 KB · Views: 87
  • ADC_RF.png
    ADC_RF.png
    94.1 KB · Views: 133
Last edited:
First thx a lot for your work , but if a recompile your code without any changes lcd stop showing values ? & a try to use the second method by changing this code
PHP:
#define METHOD2
an error occurs also
 

Try these. Sim video file in rev3.rar

Edit: Fixed rev5.


Edit2: There is another mistake in your code.

in if() conditions you have to use == operator and not = operator.


Code C - [expand]
1
2
3
4
// AOA Correction
if(fAOA == 15.0) fDynP = fDynP - (fDynP*(5.0/100.0));
if(fAOA == 20.0) fDynP = fDynP - (fDynP*(12.0/100.0));
if(fAOA == 25.0) fDynP = fDynP - (fDynP*(22.0/100.0));



rev6 file attached.

Tx Code


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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#define METHOD1
//#define METHOD2
 
int strLength = 0;
unsigned char Pressure[23], Temperature[23];
float ADRead = 0.0, fStatP = 0.0, fDynP = 0.0, fQNH = 0.0, fTAT = 0.0, fAOA = 0.0, fMack = 0.0, fSAT = 0.0, fTAS = 0.0, fTA = 0.0, fPA = 0.0;
#ifdef METHOD1
      unsigned char StatP[23] , DynP[23] , QNH[23], TAT[23], AOA[23], Mack[23], TAS[23], SAT[23], TA[23], PA[23];
#endif
#ifdef METHOD2
      unsigned char sTemp[23];
#endif
unsigned char msg[23] = "EDABOARD\r\n";
 
unsigned char* Return_String(){
    return msg;
}
 
void Delay1Sec(){
    Delay_ms(2000);
}
 
void UART1_CRLF(){
    UART1_write(0x0D);
    UART1_write(0x0A);
}
 
float Function(int n) {
    ADRead = ADC_Read(n) * 0.1559251559251559;
    FloatToStr(ADRead, Pressure);
    strLength = strlen(Pressure);
    Pressure[strLength - 1] = '\r';
    Pressure[strLength] = '\n';
    Pressure[strLength + 1] = '\0';
    
    UART1_Write_Text(Pressure);
    //UART1_CRLF();
    Delay1Sec();
    
    return ADRead;
}
 
#ifdef METHOD1
void Float2String(){
    FloatToStr(fStatP, StatP);
    FloatToStr(fDynP, DynP);
    FloatToStr(fQNH, QNH);
    FloatToStr(fTAT, TAT);
    FloatToStr(fAOA, AOA);
    FloatToStr(fPA, PA);
    FloatToStr(fMack, Mack);
    FloatToStr(fSAT, SAT);
    FloatToStr(fTAS, TAS);
    FloatToStr(fTA, TA);
}
 
void UART1Send(){
    UART1_Write_Text(PA);
    UART1_CRLF();
    Delay1Sec();
    UART1_Write_Text(Mack);
    UART1_CRLF();
    Delay1Sec();
    UART1_Write_Text(SAT);
    UART1_CRLF();
    Delay1Sec();
    UART1_Write_Text(TAS);
    UART1_CRLF();
    Delay1Sec();
    UART1_Write_Text(TA);
    UART1_CRLF();
    Delay1Sec();
}
#endif
#ifdef METHOD2
void F2S_UART_CRLF(){
    FloatToStr(fStatP, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fDynP, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fQNH, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fTAT, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fAOA, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fPA, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fMack, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fSAT, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fTAS, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
    FloatToStr(fTA, sTemp);
    UART1_Write_Text(sTemp);
    UART1_CRLF();
    Delay1Sec();
}
#endif
 
void main(){
 
      TRISA = 0b111111;
      PORTA = 0x00;
      TRISC = 0x80;
      PORTC = 0x00;
      ADCON1 = 0b00011000;
      ADCON2 = 0b10101001;
      CMCON = 0x07;
      CVRCON = 0x00;
 
      UART1_init(9600);
      Delay_ms(1000);
 
      while (1){
 
              fStatP = Function(0);  // function call
              fDynP  = Function(1);  // function call
              fQNH   = Function(2);  // function call
              fTAT   = Function(5);  // function call
              fAOA   = Function(6);  // function call
 
              // AOA Correction
              if(fAOA == 15.0) fDynP = fDynP - (fDynP*(5.0/100.0));
              if(fAOA == 20.0) fDynP = fDynP - (fDynP*(12.0/100.0));
              if(fAOA == 25.0) fDynP = fDynP - (fDynP*(22.0/100.0));
 
              // Pressure Altitude calculation
              fPA = (288.16 / 0.0019812) * (1 - pow((fStatP / 29.9213), 0.190255));
              // Mack Number claculation
              fMack = sqrt(5 * ((pow((1 + (fDynP / fStatP)), (2 / 7))) - 1));
              // Static Air Temperature calculation
              fSAT = fTAT / (1 + 0.2 * pow(fMack, 2)) ;
              // True Air Speed calculation
              fTAS = 38.968 * fMack * sqrt(fSAT) ;
              // True Altitude calculation
              fTA = (fSAT / 0.0019812)*((pow((fQNH / fStatP), 0.190255)) - 1);
 
              #ifdef METHOD1
                  // Float to String Conversions
                  Float2String();
 
                  // Sending data with a delay of 1 sec
                  UART1Send();
              #endif
              #ifdef METHOD2
                  F2S_UART_CRLF();
              #endif
              
              UART1_Write_Text(Return_String());
      }
 
      /* function max returns greater one of its 2 arguments: */
}



Rx Code


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
37
38
39
40
41
42
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
 
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
 
unsigned char output[23];
 
void main(){
 
    TRISB = 0x00;
    PORTB = 0x00;
    TRISC = 0x80;
    PORTC = 0x00;
 
    LCD_Init();
    LCD_Cmd(_LCD_CURSOR_OFF);
    LCD_Cmd(_LCD_CLEAR);
 
    UART1_Init(9600);
    Delay_ms(100);
 
    while(1){
 
        if (UART1_Data_Ready() == 1){
                 UART1_Read_Text(output, "\r\n", 10);    // reads text until 'Tx' is found
                 Lcd_Out(1,1, output);
                 UART1_Write_Text(output);
                 UART1_Write(0x0D);
                 UART1_Write(0x0A);
                 output[0] = '\0';
        }
    }
}




Edit3: added (rev7)


Code C - [expand]
1
2
3
4
5
6
#ifdef METHOD1
   #undef METHOD2
#endif
#ifdef METHOD2
   #undef METHOD1
#endif

 

Attachments

  • ADC_RF rev3.rar
    320.6 KB · Views: 93
  • ADC_RF rev4.rar
    148.3 KB · Views: 79
  • ADC_RF rev5.rar
    148.7 KB · Views: 88
  • ADC_RF rev6.rar
    148.4 KB · Views: 86
  • ADC_RF rev7.rar
    148.4 KB · Views: 87
Last edited:
Really great job from you , when i simulated it for the first time it worked perfectly , but when i rebuilt the same prob occurs , no error mentioned ? I think also that there is a prob with rs232
 
Last edited:

but when i rebuilt the same prob occurs , no error mentioned ?

What problem are you facing? Maybe your Compiler is generating wrong hex file. Compile my code (rev7 file) without changing anything and compare the hex files created with the hex files in my rev7 file. If they match the problem is something else. If they don't match then Compiler is faulty.


Edit: Try rev8 file.


Edit2: rev9 attached. used strcat() inside Function(). Not tested. Test and reply.
 

Attachments

  • ADC_RF rev8.rar
    498.6 KB · Views: 91
  • ADC_RF rev9.rar
    152.4 KB · Views: 98
Last edited:

It does not work with me because i'm using a not registred version for pic mikroc 5.61
 
Last edited:

i tested the code and i found that method 2 gives more accurate values so i choosed to work with . But it still some problems :
1/ for my project i'm working with speeds and altitudes so i don't need - values , i prefer more accurate in decimals values the thing that terminal don't , it show just 0 ?
2/ in the input values i can't go further then 2v ?
3/ lcd not really important , i'm based on values that must be sended by rs232 wich doesn't shows right values ?
 

UART is sending strings and float is used for values. It can display any real number like 0.0001, 0, 2.43736, -0.06767, etc... 0.0001 is displayed as 1e-4. The problem is in your code and ADC Vref configuration.

What sensors have you interfaced to uC ADC?
What are the o/p voltage range of sensors?
Provide links for datasheets of sensors used.
 

Hi, i will not put real sensors , but i'll test the µc using input signals. I still newbi with o/p voltage range and how to choose the voltage of adc but in my work i need just to provide numbers , the range from 0.1 or may be less to more then 500 , in the current work the range stoped at 100 ( 1v) .
Concerned real numbers UART sometimes he shows 0 and in other times hi shows 1e... and the following ? .
To understand what i want to do : this is an calculator called ADC : Air Data Computer it used on airplanes to provide infos like speeds and altitudes from sensors like pressure and temperature , so i can't use sensors in isis like lm35 because they give just a static value , but in real temperature change with altitude , so i decide to use signals , after that i'll compere calculations provided by µc with those provided by Matlab so i need big accuracy to prove that µc can be used as an ADC for little airplanes
 

If your sensors give 0 to 1V then set Vref+ to 1.1V so that for sensor input of 1V you get adc value near to 1023 with 10 bit ADC. Or use Op amp to amplify sensor o/p to 0 to 5V range. Thsi way you can have Vref = Vdd and even if different sensors give different range of o/ps like 0 to 1V, 0 to 1.5V, ... with Op amp circuits you can convert sensor voltages to 0 to 5V range and get 0 to 1023 adc value for all the sensors. For simulation in Proteus use potentiometer. Also You can provide different Vcc for different potentiometers like 1V, 1.5V, 2.3V,... and use it for adc inputs. There is no problem in code.
 
Hi ,
i'm working with a rang that goes from 29.92 to 0.329 and i need a big accuarcy but i don't know how to configurate the ADC voltage refrence ?
concerned this line how can you know the value of multiplication ?
PHP:
ADRead = ADC_Read(n) * 0.1559251559251559;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top