12F683 HPWM question

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
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.

Rich (BB code):
@ DEVICE PIC12F683, FCMEN_OFF, IESO_OFF, INTRC_OSC_NOCLKOUT , WDT_OFF, PWRT_ON, MCLR_OFF, PROTECT_ON, BOD_OFF
OSCCON  = %01110001     ' Internal 8MHz osc.
DEFINE OSC 8
' ======= Common Settings =================================
ADCON0 = 0
ANSEL  = 0
CMCON0 = 7           ' Comparators off.
TRISIO = 0
GPIO   = 0
' ============= PWM Settings =========
CCP1CON =   %00001100       ' CCP1, PWM mode
PR2     =   250             '
T2CON   =   %00000101       ' TMR2 on, prescaler 1:4
CCPR1L  = 0
Speed var CCPR1L
Btn  Var GPIO.3  ' Assuming ; the pin is pulled down to GND by 10K resistor, and button pulls it high to Vdd.
' LED is connected to GPIO.2 (on board PWM module)
pause 10
Start:
    if btn then 
        if speed + 85 < 256 then    ' 0, 85, 170, 255, 0 
            speed = speed + 85
        else
            speed = 0
        endif
 
        while btn : pause 20 : wend
    endif
 
    pause 2
goto Start
end
Thanks for any help.
 
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?
Rich (BB code):
while btn : pause 20 : wend
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,159
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


Thanks for any help.
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.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
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.
Here are lines 119, 120, 121, and 122 from the asm file.

Rich (BB code):
    ASM?
 DEVICE PIC12F683, FCMEN_OFF, IESO_OFF, INTRC_OSC_NOCLKOUT , WDT_OFF, PWRT_ON, MCLR_OFF, PROTECT_ON, BOD_OFF

    ENDASM?
Thanks for your help.
 

Papabravo

Joined Feb 24, 2006
21,159
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.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
@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.

Rich (BB code):
' Device Configuration:
#IF __PROCESSOR__ = "12F683"
#config
cfg1 = _INTRC_OSC_NOCLKOUT  ; Internal oscillator
cfg1&= _WDT_OFF             ; Watch Dog Timer disabled
cfg1&= _PWRTE_ON            ; Power-up Timer enabled
cfg1&= _MCLRE_OFF           ; Master Clear Reset disabled
cfg1&= _CP_OFF              ; Program Code Protection disabled
cfg1&= _CPD_OFF             ; Data Code Protection is disabled
cfg1&= _BOD_OFF             ; Brown-out Detect disabled
cfg1&= _IESO_OFF            ; Internal External Switchover mode disabled
cfg1&= _FCMEN_OFF           ; Fail-safe Clock Monitor disabled
 __CONFIG  cfg1             ; Set the configuration bits   
#ENDCONFIG
#else
#MSG "Wrong microcontroller selected!"
#endif

' Register Initializations:
ADCON0  = 0
ANSEL   = 0
CMCON0  = 7           ' Comparators off.
TRISIO  = 0
GPIO    = 0
OSCCON  = %01110001   ' Internal 8MHz osc.
CCP1CON = %00001100   ' CCP1, PWM mode
CCPR1L  = 0
T2CON   = %00000101   ' TMR2 on, prescaler 1:4
PR2     = 250         ' Set the PWM period.

' Includes:

' Defines:
DEFINE OSC 8

' Constants:

' Variables:

' Aliases and modifiers:
Speed var CCPR1L
Btn Var GPIO.4  ' Assuming ; the pin is pulled down to GND by 10K resistor, and button pulls it high to Vdd.
' LED is connected to GPIO.2 (on board PWM module)

' Program Code:
pause 10

Start:
    if btn then 
        if speed + 51 < 256 then    ' 0, 51, 102, 153, 204, 255 0 
            speed = speed + 51
        else
            speed = 0
        endif
 
        while btn : pause 20 : wend
    endif
 
    pause 2
goto Start
end
 

Papabravo

Joined Feb 24, 2006
21,159
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
 

THE_RB

Joined Feb 11, 2008
5,438
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".
:)
 
Top