If your data to see on terminal is in the counts variable, you have this line commented out.
Ioannis
If your data to see on terminal is in the counts variable, you have this line commented out.
Ioannis
Thanks Ioannis,
I changed it to counts, Unfortunatly no difference, but at least if it was working I wouldn't have seen it anyway. Thanks for the tip.
I also Added
ANSELH.2 = 0
This then worked, however I must say when I read the datasheet for the 18F14K22 I interpret it that it should be digital so it wouldnt be necessary to add this statement so I am a bit confused. Maybe another 40 or 50 reads and it might sink in!!!
regards
aajgss
I now have everything working and calculating air speed
I used "DEC1" to only print out to one decimal point.
Running the program gave some strange results. On occasion the count would increase, but the Knots value woud reduce.
By printing out all of the remainder, I could see what was going on.
eg for 2577 counts, the value would be 110.7 and for 2579 counts the value would be 110.1. The problem being in the true value
2577 counts is 110.457 and 110.501. The "DEC1" would give the digit either the 1 or 7 and not the 4 or the 5 as I expected (read hoped)
How can I get the first digit?
thanks
aajgss
What does your code look like now?
Dave
Always wear safety glasses while programming.
Hi Dave,
Code is attached. Thanks for looking
ThanksCode:Define LOADER_USED 1 INCLUDE "MODEDEFS.BAS" DEFINE OSC 12 DEFINE SHIFT_PAUSEUS 10 TRISB.4 =1 ' set PortB 4 as an input TRISB.6 =0 ' set PortB 6 as an output ANSELH.2 =0 DEFINE ADC_BITS 8 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 ANSEL =%10000000 ' Enable ADC channel-AN2 ANSELH =%0000 OSCCON=%01100000 TRISA =%00001111 ' Set ports A3-A2-A1-A0 as inputs TRISC =%01001000 knots var long knotsRem var long zero var word zeroSw var portc.6 i var byte avg var word HIGH CS START: for i = 1 to 10 LOW CS PAUSEUS 150 'delay after CS goes low for conversion to start. Probably not needed SHIFTIN SDI,SCK,2,[counts\14] ' using mode 2 for SPI high cs avg = counts + avg next counts = avg/10 avg=0 if zeroSw then zero = counts 'Get value at zero pressure if zeroSw then high portc.2 counts = counts -zero 'set zero point if counts >65000 then counts= 0 'in case of underflow knots = (((SQR(counts*10000))*65500)/301)/10000 knotsRem = ((SQR(counts*10000)*65500)/301)//10000 serout2 portb.7,396,[ #Knots,".",Dec1 knotsRem," Knots ",#counts," ",#zero,10,13] GOTO START: END
aajgss
Try DEC2 then try DEC3 to see what the command does.
Then take a look at DIG
Add a DIG statement to your code to "pull" the DIGit you want.4.17.7. DIG
DIG returns the value of a decimal digit. Simply tell it the digit number (0 - 4 with 0 being the rightmost digit) you would like the value of, and voila.
B0 = 123 ' Set B0 to 123
B1 = B0 DIG 1 ' Sets B1 to 2 (digit 1 of 123)
Dave
Always wear safety glasses while programming.
Thanks Dave,
I looked at both as you suggested. These are the results
Number 40.8914
DEC2 returns the value 1
DEC4 RETURNS
Number 50.143
Bookmarks