PICkit 3 build problem

Discussion in 'Embedded Systems and Microcontrollers' started by Old Frank, Aug 16, 2016.

  1. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    When my PICkit 3 is told to "build" it insists that a file must be included, in spite of displaying the hex code of my Assembler. I've some experience with a K150 using Oshonsoft simulation and the Microbrn programmer. I've tried local colleges for help and even posted a Facebook appeal, but to no avail. Any suggestions?
    ... and "sorry" if this is in the wrong place, but I'm getting desperate.
     
  2. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    Micochip forums are probably better than Facebook for PK3 issues: http://www.microchip.com/forums/Forums

    If you have the hex file, why are you trying to re-build it?

    Please post your file.

    John
     
  3. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    Ye gods, John. That was quick.
    I need to use the PICkit 3 because the K150 doesn't support the newer PIcs I'm trying to use - with DAC. I'll need to simulate and make changes then, eventually, program a 12HV752 (to start with).
    The file is very incomplete, but here (I hope) it is:
    [
    list p=12HV572 ; list directive to define processor
    #include <p12HV572.inc> ; processor specific variable definitions
    __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT

    ;***** VARIABLE/CONSTANT DEFINITIONS***********************************
    w_temp EQU 0x40 ; variable used for context saving
    status_temp EQU 0x41 ; variable used for context saving

    LEVCNTR EQU 43h ;Counter for voltage level pointer
    HIINTERCNTR EQU 44h ;Counter for FFs in interval
    CNTRFF EQU 45h ;Counter for interval - starts at FF
    LOINTERCNTR EQU 46h ;Counter for units in interval
    RESULTHI EQU 51h ;Store for AD result's upper 8 bits
    RESULTLO EQU 52h ;Store for AD result's lower 8 bits
    LEVEL EQU 53h ;Store for LEVTABLE value
    HIINTERVAL EQU 54h ;Store for HIINTERTABLE value
    LOINTERVAL EQU 56h ;Store for LOINTERTABLE value
    ;**********************************************************************
    ORG 0x000 ; processor reset vector
    goto MAIN ; go to beginning of program
    ORG 0x004 ; interrupt vector location
    movwf w_temp ; save current W register contents
    movf STATUS,w ; move status register into W register
    movwf status_temp ; save contents of STATUS register
    ;ISR here
    movf status_temp,w ; retrieve copy of STATUS register
    movwf STATUS ; restore pre-isr STATUS register contents
    swapf w_temp,f
    swapf w_temp,w ; restore pre-isr W register contents
    retfie ; return from interrupt

    MAIN
    banksel ANSELA
    movlw b'00010010' ;Set <RA4&RA1> to an.
    movwf ANSELA ; & others to dig.
    banksel TRISA
    movlw b'00011000' ;Set <RA4:3> to input
    movwf TRISA ; & <RA2:0> to output
    banksel PIE1
    bsf PIE1,ADIE ;Enable ADC interrupt
    bsf INTCON,GIE ;Enable all interrupts
    banksel ADCON0
    movlw b'00001101' ;Left justified
    movwf ADCON0 ;Vdd is Vref & AN3 & ADC on
    bsf ADCON1,4 ;
    banksel DACCON0
    movlw b'10100000' ;DAC enabled
    movwf DACCON0 ;with O-P on pin 1.

    LEVEL_SET ;
    banksel LEVCNTR ;Voltage level pointer
    movlw 05h ;Put 05d in because 1 is added at look-up start.
    NEXT_LEVEL
    banksel LEVCNTR ;Voltage level pointer
    movwf LEVCNTR ;Puts latest value in voltage level pointer

    COL_LEVEL ;Collects value for voltage level
    movlw LOW LEVTABLE
    addwf LEVCNTR,F
    movlw HIGH LEVTABLE
    btfsc STATUS,C
    addlw 1
    movwf PCLATH
    movf LEVCNTR,W
    call LEVTABLE ;Put value
    movwf LEVEL ;into LEVEL store
    movwf DACCON1 ;and output to RA1

    ADCIN ;Reads pot'r for interval time
    bcf PIR1,ADIF ;Clear AD interrupt flag
    bsf ADCON0,1 ;Start conversion
    nop ;Delay to allow
    nop ;settling time.
    btfsc ADCON0,1 ;Is conversion done?
    goto $-1 ;If not, test again.
    banksel ADRESH ;
    movf ADRESH,W ;Read uppermost 8 bits
    movwf RESULTHI ;into GPR space
    movf RESULTHI,1 ;This is to check for
    btfss STATUS,Z ;AD value of zero, otherwise
    decf RESULTHI,1 ;dec. result to avoid FFh - crash.

    COL_HIINTERVAL ;Collects value for interval time
    movlw LOW HIINTERTABLE
    addwf RESULTHI,F
    movlw HIGH HIINTERTABLE
    btfsc STATUS,C
    addlw 1
    movwf PCLATH
    movf RESULTHI,W
    call HIINTERTABLE ;Put nr of FFs
    movwf HIINTERVAL ;into HIINTERVAL store.

    COL_LOINTERVAL ;Collects value for interval time
    movlw LOW LOINTERTABLE
    addwf RESULTHI,F
    movlw HIGH LOINTERTABLE
    btfsc STATUS,C
    addlw 1
    movwf PCLATH
    movf RESULTHI,W
    call LOINTERTABLE ;Put nr of units
    movwf LOINTERVAL ;into LOINTERVAL store.

    ;Go through off-time counts - MID, UNIT

    MIDTIME ;Deals with number of FFs in off-time
    LOOP0A
    movf HIINTERVAL,0 ;Put nr of FFs
    movwf HIINTERCNTR ;in HIINTERCNTR.
    LOOP1A
    movlw FFh ;Put FFh in
    movwf CNTRFF ;CNTRFF
    LOOP2A
    decfsz CNTRFF,1 ;Dec. CNTRFF to zero
    goto LOOP2A ;with inner loop
    decfsz HIINTERCNTR,1 ;Dec. HIINTERCNTR until nr of
    goto LOOP1A ;FFs is zero.

    UNITIME ;Deals with lower byte in off-time
    movf LOINTERVAL,0 ;Put LOINTERVAL (nr of UNITS)
    movwf LOINTERCNTR ;in LOINTERCNTR.
    LOOP1B
    decfsz LOINTERCNTR,1 ;Decrement LOINTERCNTR
    goto LOOP1B ;until it is zero.
    decfsz LEVCNTR,1 ;Dec. LEVCNTR
    goto NEXT_LEVEL ;Loop for next voltage level
    goto LEVEL_SET ;Loop for next half-cycle

    ORG 0x100
    LEVTABLE
    addwf PCL,1
    retlw 0Fh ;
    retlw 1Ah ;
    retlw 1Eh
    retlw 1Ah
    retlw 0Fh
    retlw 00h

    ORG 0x200
    HIINTERTABLE
    addwf PCL,1
    retlw D9h ;These values
    retlw 6Ch ;have been
    retlw 36h ;set for
    retlw 24h ;half
    retlw 1Bh ;cycle
    retlw 15h ;times.

    ORG 0x300
    LOINTERTABLE
    addwf PCL,1
    retlw 03h ;These values
    retlw 81h ;have been
    retlw 40h ;set for
    retlw 2Bh ;half
    retlw 20h ;cycle
    retlw B3h ;times.]
    Is this the right way to present it?
    Frank
     
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
    Your code must be including a .INC file that is missing.
    p12HV572.inc for example, and this must be listed in the build files.
    Max.
     
  5. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    I've tried to use the Microchip forums, but keep having insurmountable problems trying to login. In spite of using correct user name & password, it persists in not activating my account. Hence my desperation.
     
  6. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    I've put that at the beginning. Is it in the wrong format?
     
  7. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
    What are you using to compile, I still use MPLAB IDE.
    Max.
     
  8. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
    This is my build file samples, it is not enough to just list it in the main file, in MPLAB it must be inluded in the *.MCW as shown.

    upload_2016-8-16_14-52-42.png
    Max.
     
  9. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
    The MPLAB users guide walks through a complete example.
    Max.
     
  10. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    Are you sure the device is not a 12F(HV)752 instead of 12F(HV)572? I can't find 12F(HV)572 in my version of MPLab.

    I tried compiling as a 12x752 and there are a lot of husekeeping items and a few symbols not defined errors.

    Please confirm the chip. I may need to update. I suspect it is not a 12F5xx as they don't have interrupts.

    Can you post the code using code tags, e.g., [code=ASM] ... [/code]

    John
     
  11. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    Thanks, Max. I'll look again in the morning with the PICkit 3 stuff on screen. My spring runs down about 9p.m. (now in N. Wales) and thinking is even harder at my age.
    I used a PICkit 2 a few years ago and had little trouble, but I've forgotten how I got it to work.
    The K150 etc. was a doddle - almost self-explanatory. The PICkit 3 is all bells & whistles, by comparison.
    Thanks again.
    Frank
     
  12. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    You're right, John. It's a 12HV752, not 572, and I didn't notice that. But that shouldn't cause my problem, should it?
     
  13. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    It's MPLABX IDE, but I think I should go back to an earlier version.
     
  14. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    On my machine it does. There are things like bank setting, interrupts, include files, and actually the names of the ports that could differ.

    That was an easy fix, but the defines need work. Also, to compile, the programs needs an END command. Again easy.

    Now that we both know the chip, :) I'll take another look at it. Don't feel bad about that. When "movfw" was commonly used as an instruction, I always mixed that up with "movwf."

    John
     
  15. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    This compiles. I did some fixes you need to address.
    1) Define your radix as hex. The compiler doesn't seem to like xxh when the first digit is an alpha character, so I changed them to 0xnn. EDIT: The real problem probably was that I forgot to disable case sensitivity. Leave it as you had it, but be sure to do that in the compiler settings. I usually use radix dec
    2) I just went with the default configuration. You do not want that. So, read the configuration section of toe datasheet and use the correct bit names.
    John
    Code (Microchip Assembler):
    1.  
    2.      list p=12HV752 ; list directive to define processor
    3.      #include <p12HV752.inc> ; processor specific variable definitions
    4.      __CONFIG 0x3FFF ;_CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
    5.  
    6. ;***** VARIABLE/CONSTANT DEFINITIONS***********************************
    7. w_temp EQU 0x40 ; variable used for context saving
    8. status_temp EQU 0x41 ; variable used for context saving
    9.  
    10. LEVCNTR EQU 43h ;Counter for voltage level pointer
    11. HIINTERCNTR EQU 44h ;Counter for FFs in interval
    12. CNTRFF EQU 45h ;Counter for interval - starts at FF
    13. LOINTERCNTR EQU 46h ;Counter for units in interval
    14. RESULTHI EQU 51h ;Store for AD result's upper 8 bits
    15. RESULTLO EQU 52h ;Store for AD result's lower 8 bits
    16. LEVEL EQU 53h ;Store for LEVTABLE value
    17. HIINTERVAL EQU 54h ;Store for HIINTERTABLE value
    18. LOINTERVAL EQU 56h ;Store for LOINTERTABLE value
    19. ;**********************************************************************
    20.      ORG 0x000 ; processor reset vector
    21.      goto MAIN ; go to beginning of program
    22.      ORG 0x004 ; interrupt vector location
    23.      movwf w_temp ; save current W register contents
    24.      movf STATUS,w ; move status register into W register
    25.      movwf status_temp ; save contents of STATUS register
    26.      ;ISR here
    27.      movf status_temp,w ; retrieve copy of STATUS register
    28.      movwf STATUS ; restore pre-isr STATUS register contents
    29.      swapf w_temp,f
    30.      swapf w_temp,w ; restore pre-isr W register contents
    31.      retfie ; return from interrupt
    32.  
    33. MAIN
    34.      banksel ANSELA
    35.      movlw b'00010010' ;Set <RA4&RA1> to an.
    36.      movwf ANSELA ; & others to dig.
    37.      banksel TRISA
    38.      movlw b'00011000' ;Set <RA4:3> to input
    39.      movwf TRISA ; & <RA2:0> to output
    40.      banksel PIE1
    41.      bsf PIE1,ADIE ;Enable ADC interrupt
    42.      bsf INTCON,GIE ;Enable all interrupts
    43.      banksel ADCON0
    44.      movlw b'00001101' ;Left justified
    45.      movwf ADCON0 ;Vdd is Vref & AN3 & ADC on
    46.      bsf ADCON1,4 ;
    47.      banksel DACCON0
    48.      movlw b'10100000' ;DAC enabled
    49.      movwf DACCON0 ;with O-P on pin 1.
    50.  
    51. LEVEL_SET ;
    52.      banksel LEVCNTR ;Voltage level pointer
    53.      movlw 05h ;Put 05d in because 1 is added at look-up start.
    54. NEXT_LEVEL
    55.      banksel LEVCNTR ;Voltage level pointer
    56.      movwf LEVCNTR ;Puts latest value in voltage level pointer
    57.  
    58. COL_LEVEL ;Collects value for voltage level
    59.      movlw LOW LEVTABLE
    60.      addwf LEVCNTR,F
    61.      movlw HIGH LEVTABLE
    62.      btfsc STATUS,C
    63.      addlw 1
    64.      movwf PCLATH
    65.      movf LEVCNTR,W
    66.      call LEVTABLE ;Put value
    67.      movwf LEVEL ;into LEVEL store
    68.      movwf DACCON1 ;and output to RA1
    69.  
    70. ADCIN ;Reads pot'r for interval time
    71.      bcf PIR1,ADIF ;Clear AD interrupt flag
    72.      bsf ADCON0,1 ;Start conversion
    73.      nop ;Delay to allow
    74.      nop ;settling time.
    75.      btfsc ADCON0,1 ;Is conversion done?
    76.      goto $-1 ;If not, test again.
    77.      banksel ADRESH ;
    78.      movf ADRESH,W ;Read uppermost 8 bits
    79.      movwf RESULTHI ;into GPR space
    80.      movf RESULTHI,1 ;This is to check for
    81.      btfss STATUS,Z ;AD value of zero, otherwise
    82.      decf RESULTHI,1 ;dec. result to avoid FFh - crash.
    83.  
    84. COL_HIINTERVAL ;Collects value for interval time
    85.      movlw LOW HIINTERTABLE
    86.      addwf RESULTHI,F
    87.      movlw HIGH HIINTERTABLE
    88.      btfsc STATUS,C
    89.      addlw 1
    90.      movwf PCLATH
    91.      movf RESULTHI,W
    92.      call HIINTERTABLE ;Put nr of FFs
    93.      movwf HIINTERVAL ;into HIINTERVAL store.
    94.  
    95. COL_LOINTERVAL ;Collects value for interval time
    96.      movlw LOW LOINTERTABLE
    97.      addwf RESULTHI,F
    98.      movlw HIGH LOINTERTABLE
    99.      btfsc STATUS,C
    100.      addlw 1
    101.      movwf PCLATH
    102.      movf RESULTHI,W
    103.      call LOINTERTABLE ;Put nr of units
    104.      movwf LOINTERVAL ;into LOINTERVAL store.
    105.  
    106. ;Go through off-time counts - MID, UNIT
    107.  
    108. MIDTIME ;Deals with number of FFs in off-time
    109. LOOP0A
    110.      movf HIINTERVAL,0 ;Put nr of FFs
    111.      movwf HIINTERCNTR ;in HIINTERCNTR.
    112. LOOP1A
    113.      movlw 0xFF ;Put FFh in
    114.      movwf CNTRFF ;CNTRFF
    115.      LOOP2A
    116.      decfsz CNTRFF,1 ;Dec. CNTRFF to zero
    117.      goto LOOP2A ;with inner loop
    118.      decfsz HIINTERCNTR,1 ;Dec. HIINTERCNTR until nr of
    119.      goto LOOP1A ;FFs is zero.
    120.  
    121. UNITIME ;Deals with lower byte in off-time
    122.      movf LOINTERVAL,0 ;Put LOINTERVAL (nr of UNITS)
    123.      movwf LOINTERCNTR ;in LOINTERCNTR.
    124. LOOP1B
    125.      decfsz LOINTERCNTR,1 ;Decrement LOINTERCNTR
    126.      goto LOOP1B ;until it is zero.
    127.      decfsz LEVCNTR,1 ;Dec. LEVCNTR
    128.      goto NEXT_LEVEL ;Loop for next voltage level
    129.      goto LEVEL_SET ;Loop for next half-cycle
    130.  
    131.      ORG 0x100
    132. LEVTABLE
    133.      addwf PCL,1
    134.      retlw 0Fh ;
    135.      retlw 1Ah ;
    136.      retlw 1Eh
    137.      retlw 1Ah
    138.      retlw 0Fh
    139.      retlw 00h
    140.  
    141.      ORG 0x200
    142. HIINTERTABLE
    143.      addwf PCL,1
    144.      retlw 0xD9 ;These values
    145.      retlw 0x6C ;have been
    146.      retlw 36h ;set for
    147.      retlw 24h ;half
    148.      retlw 1Bh ;cycle
    149.      retlw 15h ;times.
    150.  
    151.      ORG 0x300
    152. LOINTERTABLE
    153.      addwf PCL,1
    154.      retlw 03h ;These values
    155.      retlw 81h ;have been
    156.      retlw 40h ;set for
    157.      retlw 2Bh ;half
    158.      retlw 20h ;cycle
    159.      retlw 0xB3 ;times.
    160.  
    161.      end
    162.  
     
    Last edited: Aug 16, 2016
  16. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    Mercy buckets, John (as the French don't say).
    I'd removed most of the look-up tables to save space on the website and the "end" with it. The way I've been using Assembler has worked (almost) perfectly with the K150 & Oshonsoft, so I just kept doing it. I'd started with a Velleman 4084 (or something like that) but the K150 was easier to use.
    I'll go over it this evening, when SWMBO permits.
    Many thanks again.
    Frank
     
  17. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    The tables weren't a problem at all. The problems were getting the correct chip number, formatting the code, and the configuration. For whatever reason, MPLab 8.92 didn't like the bit names. That could also have been a case sensitivity issue. When I test code like this, I usually just do it as a "Quickbuild" and don't set up a project.

    John
     
  18. xainnasir

    New Member

    Nov 8, 2012
    26
    2
  19. Old Frank

    Thread Starter New Member

    Jul 23, 2016
    17
    1
    Sorry, but it doesn't help because it leaves out too much. I need either someone sitting next to me to show each step from the start, or instructions that have been B.S.I. tested (where B.S.I. stands for "British Standard Idiot"). E.g. the instructions refer to selecting "Project Wizard", but there's no "Project Wizard" option. Perhaps the reference was left over from an earlier version.
     
    ErnieM likes this.
  20. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    What version of MPLab are you using? If not MPLab, what?

    John
     
Loading...