• 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.

lookup table Code works in proteus sim, but not IRL

Status
Not open for further replies.

Roger_NO

Member
Hi,
Just learnd how to use loockup tables and SPI interface with a digital pot. When adding a switch to my project the code halts. It does not get the table data it seems. The gode works fine without the "BTFSS PORTA,1"

Code:
     LIST      p=16F88              ; list directive to define processor
     #INCLUDE <p16f88.inc>          ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the 
; .asm file. The lables following the directive are located in the respective 
; .inc file.  See the data sheet for additional information on configuration 
; word settings.
;
;------------------------------------------------------------------------------

     __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
     __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    errorlevel -302


 cblock    0x20
        d1
        d2
        d3
        count1
        count2
 endc


;******************** EQUATES ************************************************************


CS         EQU H'00'     ;CHIP SELECT
COMMAND EQU H'13'     ;VARIABLE FOR THE COMMAND BYTE
R_VALUE EQU d'20'     ;VARIABLE FOR THE RESISTANCE VALUE
DIM        EQU    H'00'


;******************** PROGRAM ORIGIN *****************************************************

 ORG     0X00

;-------------------- PORTB AND SPI SETTING ----------------------------------------------

 BSF     STATUS, RP0 ;SPECIFY BANK 1
 MOVLW    B'01101100'
 MOVWF    OSCCON
 MOVLW     H'00'
 MOVWF     TRISB         ;SET PORTB AS AN OUTPUT
 CLRF     PORTA 
 MOVLW     0x00
 MOVWF     ANSEL 
 MOVLW     0xFF 
 MOVWF     TRISA
 BCF     STATUS, RP0 ;SPECIFY BANK 0
 CLRF     PCLATH         ;ENSURE PCLATH BIT 3 IS CLEARED
 CLRF     INTCON         ;ENSURE ALL INTERRUPTS ARE DISABLED
 MOVLW     0x30         ;
 MOVWF     SSPCON         ;SET SYNC SERIAL PORT CONTROL REGISTER

;-------------------- PROGRAM ROUTINE ----------------------------------------------------

LOOP1
 btfss    PORTA,1        ;start?
 goto    LOOP1

START   
 BCF     PORTA, CS     ;SELECT THE POT
 CLRF    DIM
LOOP
 MOVLW     COMMAND     ;LOAD THE COMMAND BYTE IN THE ACCUMULATOR
 CALL     TRANSMIT    ;TRANSMIT THE COMMAND BYTE
 MOVF    DIM,W
 CALL    TABLE
 CALL    TRANSMIT
 INCF    DIM,1
 BTFSS    DIM,4
 GOTO    LOOP
 BSF     PORTA, CS     ;UNSELECT THE POT
 GOTO     START        ;FINISH

;-------------------- TRANSMISSION SUBROUTINE --------------------------------------------

TRANSMIT 
 BCF     STATUS, RP0 ;SPECIFY BANK 0
 MOVWF     SSPBUF         ;PLACE DATA IN BUFFER TO SEND
 BSF     STATUS, RP0 ;SPECIFY BANK 1
LOOP3 
 BTFSS     SSPSTAT, BF ;CHECK IF TRANSMISSION IS COMPLETE
 GOTO     LOOP3 ;
 BCF     STATUS, RP0 ;SPECIFY BANK 0
 RETURN             ;RETURN FROM SUBROUTINE

;*******************************************************************************************
TABLE
    ADDWF    PCL,1
    retlw    d'220'
    retlw    d'221'
    retlw    d'222'
    retlw    d'223'
    retlw    d'224'
    retlw    d'225'
    retlw    d'226'
    retlw    d'227'
    retlw    d'228'
    retlw    d'229'
    retlw    d'230'
    retlw    d'231'
    retlw    d'232'
    retlw    d'233'
    retlw    d'234'
    retlw    d'235'


DELAY                    ;100ms
            ;99993 cycles
    movlw    0x1E
    movwf    d1
    movlw    0x4F
    movwf    d2
DELAY_0
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    DELAY_0

            ;3 cycles
    goto    $+1
    nop

            ;4 cycles (including call)
    return

 END
;******************** END OF PROGRAM *****************************************************
 

Wp100

Well-Known Member
How have you got your switch wired to PortA,1 and what resistor value are you using, pulled Up or Down ?

Using BSF STATUS , RP0 can be a real headache, much easier to use the Directive ' banksel OSCCON ' which selects the respective bank.
You can use banksel 0 to return to Bank 0, all other banks need a register specifying .

You are using CLRF PORTA ( bank0) but you are still in Bank 1, though that should not cause your problem.

Are you using Mplab ide 8.92 or Mplab X and which programmer are you using Pk2 /Pk3 ?

The 16F88 has in inbuilt debugger so you can use that with the Pk2 etc and single step though your code and watch the registers etc change and hopefully see where your 'bug' is.


000382.jpg
 

Pommie

Well-Known Member
Most Helpful Member
Your problem is you set DIM to zero, addwf PCL,w will be an infinite loop with W set to zero.

Mike.
 

Roger_NO

Member
Thanx for your reply!

How have you got your switch wired to PortA,1 and what resistor value are you using, pulled Up or Down ?
I use a Capacitive Touch Switch module, so no pull-up/down necessary? It's based on the TTP223.

Are you using Mplab ide 8.92 or Mplab X and which programmer are you using Pk2 /Pk3 ?
I'm using bouth;) but i tryed installing X and step trough while watching registers, and it seemed fine. I'm using a QL200 DEV board from pic16.

Mike
Your problem is you set DIM to zero, addwf PCL,w will be an infinite loop with W set to zero.
I set DIM to zero so it returns with the first value in my table. Am i doing it wrong?
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
Mike

I set DIM to zero so it returns with the first value in my table. Am i doing it wrong?
Whoops, my mistake. It's a long time since I did lookups in assembly.

Edit, are you sure your table resides in one bank?

Mike.
 

Wp100

Well-Known Member
Have not used a digital pot, so wonder how exactly you are measuring/using its output to see if its receiving the data from the Pic ?

Which digital pot are you using ?

Are you saying if you run your code on a continuous basis without this code it works ok ?

LOOP1
btfss PORTA,1 ;start?
goto LOOP1


Again do not know which touch switch you are , but some have pads to select High or Low outputs and Momentary or Latched outputs .
 

Roger_NO

Member
Have not used a digital pot, so wonder how exactly you are measuring/using its output to see if its receiving the data from the Pic ?

Which digital pot are you using ?

Are you saying if you run your code on a continuous basis without this code it works ok ?

LOOP1
btfss PORTA,1 ;start?
goto LOOP1


Again do not know which touch switch you are , but some have pads to select High or Low outputs and Momentary or Latched outputs .
Im using MCP4151 from micrchip. The pot has 3 pins where i connect one end to VDD and the other to VSS. The wiper pin voltage tells me if the communication is up.

If i remove the btfss PORTA,1 from the code the output wiper (from MCP4151) regulates the voltage by the value in my table. So yes. Without this my code works excellent.
When simulating in proteus 8 the code works well both with and without the btfss instruction. But when testing on my board, it does not.

The touch toggles from low to high when i touch, then back to low when released.
 
Last edited:

Roger_NO

Member
Whoops, my mistake. It's a long time since I did lookups in assembly.
No problem;) My long term memory is horrible as well;)

Edit, are you sure your table resides in one bank?
I am not sure, but when adding a delay between fetching table data, the nr of output changes corresponds with number of variables in the table. (without switch)
 

Wp100

Well-Known Member
Cannot see your error, would suggest you replace your touch switch with a standard pull up or down switch to eliminate that.

If you look at your Disassembly listing it shows the addresses your code occupies, seems ok.

If you remove your lookup table ; CALL TABLE and let DIM just increment from 0 to 256 in an endless loop then you can be sure its not anything to do with the table.

That said, Proteus can often run much slower than on an actual chip, try putting CALL DELAY once or even twice before the TX routine, so you can clearly see the increment on the output.
Running around just 16 values as you have the code with no delays it would be happening very fast eg milliseconds, so doubt a DVM would read it or are use using a scope ?
 

Attachments

Roger_NO

Member
I added 0.5 second delay when i tested i proteus. on my breadboard i used an osilloscope to see and measure the "stepform". i'll try a pull-up resistor to see if it helps when i come home. I'll also try to increment DIM.
I will tell you how it goes! Thanx for all the suggestions.
 

Roger_NO

Member
took some time, but got it working. Had to clear PORTA! (in the rigt bank as you said Wp100) did not think that clearing A would be the main issue! I have skipped this in many other projects, but first time usin f88;)
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top