Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC plus-5110 LCD-GPS-BMP280-HMC5983

Status
Not open for further replies.
Tx = b1×256 +b0 is the same thing as Tx.HB = b1, Tx.LB = b0
Probably .HB / .LB method is faster and uses less memory.
I will look at it.

Anyway with 32 bit calculations you need to take care of the signed 16bit variables, which Oshonsoft can't do directly.
I think the easiest way is by converting the 16 bit T1, T2 etc.
to single variables.
I tested the ×256 and tx.HB=/ tx.LB= methods.
×256 uses 18 instructions and .HB / .LB uses 4

I ran the calculations with the values in BMP280 datasheet in Oshonsoft simulator for the temperature
I got T=25.0824
In the datasheet T = 25.08
Seems good enough.
I will next calculate the pressure and then upload the program.
 
Morning C;
The 256 multiplier is applied by the Basic when you use .HB

I put the 256 in as comment to show you what OSH will do with it.
Is that what you mean,?
E
Hi E,
Here's a section from a program with '.LB and 'HB' Showing no reference to ' * 256 = ' :
I wondered if it should have it?
[I'm happy to see what J comes up with, as he may be using a diffrerent method?]
C.

SPICSOn
SPISend r_t_xlsb 'READ ADDR TEMP xlsb from BMP280
SPIReceive t_xlsb 'Least sig Byte
SPISend r_t_lsb 'READ ADDR TEMP lsb from BMP280 MID
SPIReceive t_lsb 'mid sig Byte
SPISend r_t_msb 'READ ADDR TEMP msb from BMP280 MOST
SPIReceive t_msb 'Most sig BYTE
SPISend r_p_xlsb 'READ ADDR PRESSURE xlsb from BMP280
SPIReceive p_xlsb 'Least sig Byte
SPISend r_p_lsb 'READ ADDR PRESSURE lsb from BMP280 MID
SPIReceive p_lsb 'mid sig Byte
SPISend r_p_msb 'READ ADDR PRESSURE msb from BMP280 MOST
SPIReceive p_msb 'Most sig BYTE
SPICSOff
PORTD.5 = 1 'CHIP SELECT[hpa]OFF
WaitMs 10
PORTD.4 = 0 'CHIP SELECT 5110 ON

'Join all TEMP bytes as long
t_lsbnxlsb.LB = t_xlsb
t_lsbnxlsb.HB = t_lsb
t_msbnlsbnxlsb.LW = t_lsbnxlsb
t_msbnlsbnxlsb.HW = t_msb
'ASCII serial out of Bytes,Word or Single
msg1 = #t_msbnlsbnxlsb
t_msbnlsbnxlsb = ShiftRight(t_msbnlsbnxlsb, 4) ''''''''''''''''''''
'ASCII serial out of Bytes,Word or Single'''''''''''''''''''''''''''''
msg1 = #t_msbnlsbnxlsb '''''''''''''''''''''''''''''''''''''
WaitMs 10 'Does CS need time to switch? [SHORTEN OR REMOVE THIS LINE]
strtmp = #t_msbnlsbnxlsb
'#############################################################################
'Join all PRESS bytes as long
p_lsbnxlsb.LB = p_xlsb
p_lsbnxlsb.HB = p_lsb
p_msbnlsbnxlsb.LW = p_lsbnxlsb
p_msbnlsbnxlsb.HW = p_msb
'ASCII serial out of Bytes,Word or Single
msg1 = #p_msbnlsbnxlsb
p_msbnlsbnxlsb = ShiftRight(p_msbnlsbnxlsb, 4)
 
Last edited:
I checked the generated code from the compiler.
X.HB = byte2, X.LB = byte1 just moves the bytes to right places.
×256 executes the multiply.

I tested with 16F877.
18F compiler may do it better with hardware multiply instruction?
 
Hi,
If BYTE test.LB = 100
and BYTE test.HB = 200

What would 'test' be as a WORD?
C.
 
Last edited:
Hi,
Thanks.
Is the '*256' for our external calculation, or is it necessary to write'*256' to make the program work?
C.
What is external calculation?
256× is alternative to .HB= . LB=
When the variables are correct from SPI data, you calculate with them.
The previous Python code is general code without knowing anything about special language features.
 
What is external calculation?
256× is alternative to .HB= . LB=
When the variables are correct from SPI data, you calculate with them.
The previous Python code is general code without knowing anything about special language features.
Hi J,
I use external calculations with a calculator to verify any answers I get with the programs. {And I don't know how to use it properly:confused:]
I think I understand the .LB .HB part, and once I get verified results, I'll post them.
Thanks.
C.
 
Hi,
Can someone verify that this program is calculating properly please?

I READ the T1 to P9 inbuilt callibration addresses, and enter them into the calculation, to be printed on the 5110.
First one T1.LB = 220 T1.HB 105 should give T1 = 27100, is this correct.
C
 

Attachments

  • 5110.jpg
    5110.jpg
    190.6 KB · Views: 275
  • 18LF4520 BMP280 5110 CALC T1 to P9 from LB_HB 290118 1030.bas
    11.7 KB · Views: 263
Hi C,
The two values are OK to give the final answer. 27100
E
 
I will give up the calculations.
I got the temperature right and almost the pressure, but when I added one line to the pressure calculations, I got hardware stack error.
The program size was about 2170 instructions.
Tested in simulator, processor PIC16F877, PIC-IDE 7.43
Maybe it works in PIC18F simulator, but I have not installed it.
 
I will give up the calculations.
I got the temperature right and almost the pressure, but when I added one line to the pressure calculations, I got hardware stack error.
The program size was about 2170 instructions.
Tested in simulator, processor PIC16F877, PIC-IDE 7.43
Maybe it works in PIC18F simulator, but I have not installed it.
Hi J,
I'm trying to simplify the equation at the moment, by READing the T and P values, calculating the WORD, then attempting to reduce the equation as I work through it. Not easy:arghh:

If you want to re-try, where I test it for you with an 18LF4520, I'd be happy to work through yours.
C.
 
I will give up the calculations.
I got the temperature right and almost the pressure, but when I added one line to the pressure calculations, I got hardware stack error.
The program size was about 2170 instructions.
Tested in simulator, processor PIC16F877, PIC-IDE 7.43
Maybe it works in PIC18F simulator, but I have not installed it.
It must be a bug in the PIC-compiler.
It appeared, when program size went over 2048

I installed PIC18 IDE and it works fine.
Calculated pressure 100653.25 Pa
In the datasheet 100653.27 Pa
I will upload the program soon.
It only calculates temperature and pressure.
No SPI stuff.
 
It must be a bug in the PIC-compiler.
It appeared, when program size went over 2048

I installed PIC18 IDE and it works fine.
Calculated pressure 100653.25 Pa
In the datasheet 100653.27 Pa
I will upload the program soon.
It only calculates temperature and pressure.
No SPI stuff.
Hi J,
Glad to see it now compiles ok.
I'm a bit worried about the 0.02 error though;)
C.
 
Here is the program.
It uses single variables in the calculations.
SPI data should converted to single and take care of the signed integers, which Oshonsoft can't directly do.
 

Attachments

  • pressure.txt
    1.6 KB · Views: 282
Here is the program.
It uses single variables in the calculations.
SPI data should converted to single and take care of the signed integers, which Oshonsoft can't directly do.
Hi J,
Thanks very much for your CALC.
Here is a program using your CALC, which gives the same answer as yours. [Check for my mistakes}
Where did you get the 'adc_t = 519888 and adc_p = 415148' from? and where does a program get them from?
C.
 

Attachments

  • 18LF4520 PCB JJW CALC 300118 0915.bas
    10.8 KB · Views: 267
  • 5110.jpg
    5110.jpg
    184.6 KB · Views: 258
adc_t, adc_p are test values from the datasheet.
You will get the real values reading 3 bytes SPI data for each and combining the bytes to a 20bit value.
See section 4.2 memory map, table 18

Dim T as long, Dim P as long
Then in the real program:
adc_t = T
adc_p = P
 
Last edited:
adc_t, adc_p are test values from the datasheet.
You will get the real values reading 3 bytes SPI data for each and combining the bytes to a 20bit value.
See section 4.2 memory map, table 18

Dim T as long, Dim P as long
Then in the real program:
adc_t = T
adc_p = P
Hi J,
In your program there is a't as SINGLE' and a 'pr as SINGLE' Is there an error?
C.
 
Hi J,
In your program there is a't as SINGLE' and a 'pr as SINGLE' Is there an error?
C.
No, why?
All calculations are made with single variables.
You get bytes from BMP280 and they will be combined to long or words and then converted to singles before the calculation.
This part is still missing from the program.
 
Status
Not open for further replies.
Back
Top