PDA

View Full Version : LTC-1298 to 18K1320 not working?!



Ramius
- 19th January 2014, 19:39
Hi All!
Okay so for some probably very simple and basic reason I cannot seem to read from the 1298! I took an older program and decided to modify it. After hours of trial and error and a bottle of excedrin I thought maybe someone could maybe look and see what I did wrong? Thanks, Ed

'************************************************* ******************
'* Name : XXXXSPEED.bas *
'* Author : Ed Cannady *
'* Notice : Copyright (c) 2014 *
'* : All Rights Reserved *
'* Date : 1/18/2014 *
'* Version : 1.0 *
'* Notes : For a 18F1320 and LTC1298 and MS4515 *
'************************************************* ******************

Define OSC 20
Define LOADER_USED 1
Include "Modedefs.bas"
include "hpwm10L.pbp"
ENABLE DEBUG


#CONFIG
__CONFIG _CONFIG1H, _HS_OSC_1H & _FSCM_OFF_1H
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_8K_2H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_27_2L
__CONFIG _CONFIG3H, _MCLRE_OFF_3H
__CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_ON_4L & _STVR_ON_4L
__CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
__CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
__CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
__CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
__CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
__CONFIG _CONFIG7H, _EBTRB_OFF_7H
#ENDCONFIG


ADCON1 = 255

CLOCK VAR PortB.5 ' CLOCK from Pin 11 to Pin 7 of the 1298
DOUT VAR PortB.7 ' Data Out from Pin 13 to Pin 6 of the 1298
DIN VAR PortB.6 ' Data In from Pin 12 to Pin 5 of the 1298
CS VAR PortB.0 ' Chip Select From Pin 8 to Pin 1 of the 1298

TRISB.5 = 0 ' Make B.5 an output (CLOCK)
TRISB.7 = 0 ' Make B.7 an output (Data out to the 1298)
TRISB.6 = 1 ' Make B.6 an input (Data In from the 1298)
TRISB.3 = 0 ' Make B.0 an output (Chip Select)

addr VAR BYTE ' Channel address / mode
result VAR WORD ' Reading from the A/D
Vbits VAR WORD ' Variable to store A/D volts reading
Abits VAR WORD ' Variable to store A/D Amps reading
REF VAR WORD ' 0.0 Amps reference point
AMPS VAR WORD ' Amps reading
VOLTS VAR WORD ' Volts reading


REF = 489 ' Start with a reference number
AMPS = 0 ' Set the Amps value to zero
VOLTS = 0 ' Set the Volts value to zero

HIGH CS ' Set the A/D Chip select to inactive

Goto mainloop ' Skip subroutines

getad:
CS = 0 ' A/D Chip select active

' ** Send address / mode - Start bit, 3 bit addr, null bit].**

SHIFTOUT DIN, CLOCK, MSBFIRST, [1\1, ADDR\3, 0\1]

SHIFTIN DOUT, CLOCK, MSBPRE, [RESULT\12] 'Get 12-bit results

CS = 1 ' A/D Chip select inactive

Return

' ** Subroutine to get Volts value (channel 0)
GETVOLTS:
addr = $05 ' Single ended, channel 0, MSBF high
Gosub getad
Vbits = result
Return

' ** Subroutine to get Amps value (channel 1)
GETAMPS:
addr = $07 ' Single ended, channel 1, MSBF high
Gosub getad
Abits = result
IF Abits < 494 THEN REF = Abits ' No Load cal./sup.voltage/temp. comp.
Return

mainloop:
Gosub GETVOLTS ' Get the Volts Reading
gosub GETAMPS ' Get the AMPS Reading

' ** VOLTS SECTION
VOLTS = ((Vbits*/ 500)>>4)*3

' ** AMPS SECTION
AMPS = (Abits - REF)* 20

GOTO mainloop