12F683 HPWM question

Discussion in 'Embedded Systems and Microcontrollers' started by tracecom, Oct 31, 2013.

  1. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    What does this line of assy code do in terms of HPWM in a 12F683?

    @ DEVICE PIC12F683, FCMEN_OFF, IESO_OFF, INTRC_OSC_NOCLKOUT , WDT_OFF, PWRT_ON, MCLR_OFF, PROTECT_ON, BOD_OFF

    It seems to be the cause of this error.

    [ASM ERROR] 12F683 HPWM BUTTON.ASM (120) : Illegal opcode (PIC12F683)
    [ASM WARNING] 12F683 HPWM BUTTON.ASM (120) : Found label after column 1. (DEVICE)

    It's from some PBP code I snagged from the web. Here's the entire code.

    Code ( (Unknown Language)):
    1. @ DEVICE PIC12F683, FCMEN_OFF, IESO_OFF, INTRC_OSC_NOCLKOUT , WDT_OFF, PWRT_ON, MCLR_OFF, PROTECT_ON, BOD_OFF
    2. OSCCON  = %01110001     ' Internal 8MHz osc.
    3. DEFINE OSC 8
    4. ' ======= Common Settings =================================
    5. ADCON0 = 0
    6. ANSEL  = 0
    7. CMCON0 = 7           ' Comparators off.
    8. TRISIO = 0
    9. GPIO   = 0
    10. ' ============= PWM Settings =========
    11. CCP1CON =   %00001100       ' CCP1, PWM mode
    12. PR2     =   250             '
    13. T2CON   =   %00000101       ' TMR2 on, prescaler 1:4
    14. CCPR1L  = 0
    15. Speed var CCPR1L
    16. Btn  Var GPIO.3  ' Assuming ; the pin is pulled down to GND by 10K resistor, and button pulls it high to Vdd.
    17. ' LED is connected to GPIO.2 (on board PWM module)
    18. pause 10
    19. Start:
    20.     if btn then
    21.         if speed + 85 < 256 then    ' 0, 85, 170, 255, 0
    22.             speed = speed + 85
    23.         else
    24.             speed = 0
    25.         endif
    26.  
    27.         while btn : pause 20 : wend
    28.     endif
    29.  
    30.     pause 2
    31. goto Start
    32. end
    Thanks for any help.
     
  2. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    I think you should "DEFINE Btn GPIO.3" if that is the proper syntax for pbp.

    Edit: is case sensitive turned off in assembler? try inlining the code?
    Code ( (Unknown Language)):
    1. while btn : pause 20 : wend
     
    Last edited: Oct 31, 2013
  3. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    It sets the values of the bits in the configuration word. As such it CANNOT be the source of your problem. The 120 in the error message is the line number on which the error occurred. It is probably line 120 in the assembly language file, not the original source file.
     
  4. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Here are lines 119, 120, 121, and 122 from the asm file.

    Code ( (Unknown Language)):
    1.  
    2.     ASM?
    3.  DEVICE PIC12F683, FCMEN_OFF, IESO_OFF, INTRC_OSC_NOCLKOUT , WDT_OFF, PWRT_ON, MCLR_OFF, PROTECT_ON, BOD_OFF
    4.  
    5.     ENDASM?
    6.  
    Thanks for your help.
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    So the ASM? and ENDASM? tags are supposed to enclose actual code, with opcodes and operands. The settings in the CONFIG words are just data, and you need to dig into the documentation for the compiler/assembler to see how the values of configuration words are done. It looks like you might be trying to apply MPLAB rules to a non-MPLAB compliant product.

    The @ DEVICE construct looks suspicious, and it is not MPLAB compatible.
     
  6. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I am not using MPLAB, but rather Microcode Studio. I reworked the @ DEVICE structure and moved the input off the MCLRE pin, got it to run, but truthfully, i don't understand why the changes fixed the problem. However, now that it runs, I can study it and learn something.

    Thanks for the input.
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    It looks like the line:

    @ DEVICE PIC12F683, FCMEN_OFF, IESO_OFF, INTRC_OSC_NOCLKOUT , WDT_OFF, PWRT_ON, MCLR_OFF, PROTECT_ON, BOD_OFF

    is trying to set the config bits. PBP really doesn't have a good way to set the config bits, it assumes what they should be compiles with the assumption, then hopes your loader is capable of adjusting the bits.

    The PBP help file states the .inc file for each device holds default config bits. You could edit this file to set them the way you wish (and hope you don't have another project that needs different settings).

    Back when I used this I may have just deleted config info from the .inc file so I could add what I needed in the main file. It has been several years since I used this compiler, I have very little good to say about it. Oshonsoft sells a much less expensive Basic compiler that has fewer quirks.
     
  8. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    @ErnieM

    You are correct about the @DEVICE statement, and I agree that it is a haphazard method of setting the config bits. To that end, I am trying to define a more systematic way of arranging PBP code. Here is my attempt to better organize the code from post 1 of this thread. There are still some areas that I don't understand (how to calculate PR2, e.g.), and lots of notations that I need to add, but I am making some progress.

    Thanks for your input.

    Code ( (Unknown Language)):
    1. ' Device Configuration:
    2. #IF __PROCESSOR__ = "12F683"
    3. #config
    4. cfg1 = _INTRC_OSC_NOCLKOUT  ; Internal oscillator
    5. cfg1&= _WDT_OFF             ; Watch Dog Timer disabled
    6. cfg1&= _PWRTE_ON            ; Power-up Timer enabled
    7. cfg1&= _MCLRE_OFF           ; Master Clear Reset disabled
    8. cfg1&= _CP_OFF              ; Program Code Protection disabled
    9. cfg1&= _CPD_OFF             ; Data Code Protection is disabled
    10. cfg1&= _BOD_OFF             ; Brown-out Detect disabled
    11. cfg1&= _IESO_OFF            ; Internal External Switchover mode disabled
    12. cfg1&= _FCMEN_OFF           ; Fail-safe Clock Monitor disabled
    13.  __CONFIG  cfg1             ; Set the configuration bits  
    14. #ENDCONFIG
    15. #else
    16. #MSG "Wrong microcontroller selected!"
    17. #endif
    18.  
    19. ' Register Initializations:
    20. ADCON0  = 0
    21. ANSEL   = 0
    22. CMCON0  = 7           ' Comparators off.
    23. TRISIO  = 0
    24. GPIO    = 0
    25. OSCCON  = %01110001   ' Internal 8MHz osc.
    26. CCP1CON = %00001100   ' CCP1, PWM mode
    27. CCPR1L  = 0
    28. T2CON   = %00000101   ' TMR2 on, prescaler 1:4
    29. PR2     = 250         ' Set the PWM period.
    30.  
    31. ' Includes:
    32.  
    33. ' Defines:
    34. DEFINE OSC 8
    35.  
    36. ' Constants:
    37.  
    38. ' Variables:
    39.  
    40. ' Aliases and modifiers:
    41. Speed var CCPR1L
    42. Btn Var GPIO.4  ' Assuming ; the pin is pulled down to GND by 10K resistor, and button pulls it high to Vdd.
    43. ' LED is connected to GPIO.2 (on board PWM module)
    44.  
    45. ' Program Code:
    46. pause 10
    47.  
    48. Start:
    49.     if btn then
    50.         if speed + 51 < 256 then    ' 0, 51, 102, 153, 204, 255 0
    51.             speed = speed + 51
    52.         else
    53.             speed = 0
    54.         endif
    55.  
    56.         while btn : pause 20 : wend
    57.     endif
    58.  
    59.     pause 2
    60. goto Start
    61. end
     
  9. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    Good job. There are always multiple pathways to the desired result.

    1. First make it work
    2. Then make it fast/small
    3. Then make it elegant
     
    ErnieM likes this.
  10. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    No. 2 means:

    Fast and small?

    or

    Fast or small?
     
  11. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    fast or small = must only be one, can be either one.

    fast and small = must be both.

    and/or = can be either one, OR both (covers all possibilities).

    fast/small = abbreviation for "fast and/or small".
    :)
     
  12. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    Unrolled code goes for fast but makes it NOT small.
     
Loading...