Strange compile error, plus unexpected input behavior

23 views
Skip to first unread message

Mike

unread,
Mar 12, 2026, 9:13:55 PM (8 days ago) Mar 12
to jallist
I'm converting Roman Black's 1kHz sine wave generator (https://romanblack.com/onesec/Sine1kHz.htm) to the 12F1840.  For now, I'm running it on the internal oscillator at 8MHz.

It mostly works.  The switch does put the device into CAL mode, but releasing the switch does not return it to SINE mode.  It's a short program and I just can't see the problem.

The other issue is that the compiler returns a weird warning referencing the last line of the program.  It does compile, though.

Below is the program, if anyone has time to look at it.

Regards,
Mike

--
-- Description: Roman Black's 1kHz sine wave generator.
--              Ported to JAL and the PIC12F1840.
--
--              Connections:
--                  Green LED on RA1 (to ground, with resistor).
--                  Red LED on RA0 (to ground, with resistor).
--                  Switch on RA3 (MCLR) switching the pin to ground, using internal pullup.
--                  Signal output on RA2.
--                  Using the internal oscillator at 8MHz, no crystal.
--
include 12f1840
--
pragma target clock     8_000_000
pragma target OSC       INTOSC_NOCLKOUT
pragma target PWRTE     enabled     -- power up timer
pragma target BROWNOUT  disabled    -- no brown-out reset
pragma target PLLEN     disabled    -- PLL off
pragma target WDT       disabled    -- no watchdog
pragma target DEBUG     disabled    -- no debugging
pragma target LVP       disabled    -- no Low Voltage Programming
pragma target MCLR      internal    -- no external MCLR reset, pin is used as GPIO
pragma target FCMEN     disabled    -- no fail-safe clock monitor
pragma target IESO      disabled    -- no internal/external switchover

var byte pwmstep
var byte pwmval
var byte debounce

const byte sine[50] = {52,57,62,66,70,74,77,80,82,84,85,86,86,
                          86,85,83,81,78,75,72,69,65,61,56,52,
                       48,44,39,35,31,28,25,22,19,17,15,14,14,
                          14,15,16,18,20,23,26,30,34,38,43,48}

enable_digital_io()
LATA  = 0b0000_0000
TRISA  = 0b0000_1000
WPUA = 0b0000_1000
OPTION_REG = 0b0000_0111
OSCCON = 0b0111_0000
while ! OSCSTAT_HFIOFS loop end loop
T2CON = 0b0000_0100  -- postscale 1:1, prescale 1:1, TMR2 on
PR2 = 40-1  -- 20us tick
_usec_delay(300_000)  -- small settling delay


procedure set_sine_mode() is
    pwmstep = 0
    debounce = 0
    LATA = 0b000_0010  -- turn on SINE mode LED
    CCP1CON = 0b0000_1100  -- turn on PWM
end procedure


procedure set_cal_mode() is
    CCP1CON = 0b0000_0000  -- turn off PWM
    LATA = 0b000_0001  -- turn on CAL mode LED
   
    assembler
    local loop, done
    loop:
        bsf     LATA,2
        bcf     LATA,2
        btfsc   PORTA,3  ; check if switch was set to SINE mode
        goto    done
       
        bsf     LATA,2
        bcf     LATA,2
        goto    loop
    done:
    end assembler
end procedure


set_sine_mode()
forever loop
    -- just sit in loop and load new PWM value every TMR2 cycle
    while (!PIR1_TMR2IF) loop
    end loop
    CCPR1L = pwmval  -- store PWM value for this cycle
    PIR1_TMR2IF = false  -- clear TMR2 interrupt flag
   
    pwmstep = pwmstep + 1
    if (pwmstep >= 50) then
        pwmstep = 0
    end if
    pwmval = sine[pwmstep]
   
    if (pin_A3 == low) then
        debounce = debounce + 1
        if (debounce > 250) then
            set_cal_mode()
            -- return from cal mode
            set_sine_mode()
        end if
    else
        debounce = 0
    end if
end loop

Mike

unread,
Mar 12, 2026, 9:51:23 PM (8 days ago) Mar 12
to jallist
Okay, I think I've figured it out.  Because of the assembly code, the wrong bank is selected.  The problem, however, is that I can't issue a "movlb 0" because it looks like the compiler doesn't recognize "movlb"?

Regards,
Mike

Mike

unread,
Mar 12, 2026, 10:05:54 PM (8 days ago) Mar 12
to jallist
Okay, I solved it with "clrf BSR".

Rob CJ

unread,
Mar 13, 2026, 12:33:55 PM (7 days ago) Mar 13
to jallist
Hi Mike,

I see in the asm command list that movlb is indeed not mentioned but in other parts of the compile program PIC_OPCODE_MOVLB is used to the instruction is used. It may be that this assembler command is forgotten?

Kind regards,

Rob


Van: 'Mike' via jallist <jal...@googlegroups.com>
Verzonden: vrijdag 13 maart 2026 02:51
Aan: jallist <jal...@googlegroups.com>
Onderwerp: [jallist] Re: Strange compile error, plus unexpected input behavior
 
--
You received this message because you are subscribed to the Google Groups "jallist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallist+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jallist/7a765f16-f495-435b-85b7-91a9fbf24c29n%40googlegroups.com.

Mike

unread,
Mar 13, 2026, 2:46:49 PM (7 days ago) Mar 13
to jallist
Hi Rob,

Yeah, that's what it looks like.  I was able to select Bank 0 by clearing the BSR register (via "clrf BSR"), but if I had to select another bank I probably couldn't do it.  I know this intrudes on the territory of what JAL should or shouldn't be able to do.  I just wanted to convert that project to JAL to lend itself to further modification/experimentation.

Regards,
Mike

Rob CJ

unread,
Mar 14, 2026, 5:06:29 AM (7 days ago) Mar 14
to jallist
Hi Mike,

I did a quick test to see what happend if I added the instruction to the asm table and added a movlb 0 instruction to your program. Unfortunately that has side effects so it is not that simple to add. I assume more needs to be done. Not sure if it is related with the fact that normally the compiler adds its own movlb instructions and that this conflicts with that.

Info below.

Current compiler warning
-----------------------
/mnt/a1156b13-f869-473b-a48f-9e6cf5cd6673/PIC/Compiler/Test/2026/Issue missing movlb instruction/missing_movlb.jal:60: syntax error
/mnt/a1156b13-f869-473b-a48f-9e6cf5cd6673/PIC/Compiler/Test/2026/Issue missing movlb instruction/missing_movlb.jal:60: syntax error
2 errors, 0 warnings

With modification
-----------------
/mnt/a1156b13-f869-473b-a48f-9e6cf5cd6673/PIC/Compiler/Test/2026/Issue missing movlb instruction/missing_movlb.jal:100: warning: data error at 0x00000073 (got 7f8c expected 10c)
/mnt/a1156b13-f869-473b-a48f-9e6cf5cd6673/PIC/Compiler/Test/2026/Issue missing movlb instruction/missing_movlb.jal:100: warning: data error at 0x00000074 (got 7f8c expected 10c)
/mnt/a1156b13-f869-473b-a48f-9e6cf5cd6673/PIC/Compiler/Test/2026/Issue missing movlb instruction/missing_movlb.jal:100: warning: data error at 0x00000075 (got 7f8c expected c)
/mnt/a1156b13-f869-473b-a48f-9e6cf5cd6673/PIC/Compiler/Test/2026/Issue missing movlb instruction/missing_movlb.jal:100: warning: data error at 0x00000077 (got 7f8c expected 10c)
/mnt/a1156b13-f869-473b-a48f-9e6cf5cd6673/PIC/Compiler/Test/2026/Issue missing movlb instruction/missing_movlb.jal:100: warning: data error at 0x00000078 (got 7f8c expected 10c)

Kind regards,

Rob


Van: 'Mike' via jallist <jal...@googlegroups.com>
Verzonden: vrijdag 13 maart 2026 19:46
Aan: jallist <jal...@googlegroups.com>
Onderwerp: Re: [jallist] Re: Strange compile error, plus unexpected input behavior
 

Mike

unread,
Mar 14, 2026, 8:08:45 AM (6 days ago) Mar 14
to jallist
Yeah, that's understandable.

Patrick FROUCHT

unread,
Mar 18, 2026, 3:10:19 PM (2 days ago) Mar 18
to jal...@googlegroups.com
Hi Rob

Using the PIC12F1840, I encountered the sames issuesas Mike. for "large" programs 

I got the warning :
[Warning] (Noel_guirlande_252_ledsX.jal) [Line 501]  data error at 0x00000116 (got 22e expected 2e)
and another
 [Warning] (12F1840_SW2812b_Dada-tour-Eiffel-1.jal) [Line 359]  data error at 0x0000010f (got 231 expected 31)
The line number is the last line of programs..
Both programs are working I don't know the meaning of the warnings.

Patrick

Patrick

Rob CJ

unread,
Mar 19, 2026, 1:52:01 PM (yesterday) Mar 19
to jal...@googlegroups.com
Hi Patrick,

Strange since the ROM size of that PIC is not that large.

Can you send an example Program?

Thanks.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Patrick FROUCHT <patfr...@gmail.com>
Verzonden: woensdag 18 maart 2026 20:10
Aan: jal...@googlegroups.com <jal...@googlegroups.com>

Mike

unread,
Mar 19, 2026, 2:30:19 PM (yesterday) Mar 19
to jallist
Patrick,

I'm skeptical that it has to do with the size of the program.  If you're using assembly in your JAL program, that's probably why.  Because JAL doesn't handle assembly perfectly.  As noted earlier in this thread, you can't issue a MOVLB instruction in a JAL program.  You should definitely make sure that your program works as expected.  My original program compiled, but didn't work correctly until I realized the problem and corrected it by making sure Bank 0 was selected at the necessary spot.

Mike

Rob CJ

unread,
Mar 19, 2026, 2:48:43 PM (yesterday) Mar 19
to jallist
Hi Mike, Patric,

About using assembler. Have you checked chapter 11 of the compiler documentation? There you find this about banks.
To guarantee the correct data bank is selected when accessing a file register, use one of the following:
BANK opcode ...
Or:
BANK f


I remembered something from the pointer library that Matt wrote.

@Mike. If you apply this to your assembly code, you see the following generated assembly code without 'bank':

;   59     assembler
;   61     loop:
l_loop
;   62         bsf     LATA,2
                               bsf      v_lata, 2
;   63         bcf     LATA,2
                               bcf      v_lata, 2
;   64         btfsc   PORTA,3  ; check if switch was set to SINE mode
                               btfsc    v_porta, 3
;   65         goto    done
                               goto     l_done
;   67         bsf     LATA,2
                               bsf      v_lata, 2
;   68         bcf     LATA,2
                               bcf      v_lata, 2
;   69         goto    loop
                               goto     l_loop
;   70     done:

And this with 'bank':

;   59     assembler
;   61     loop:
l_loop
;   62         bank bsf     LATA,2
                               bsf      v_lata, 2
;   63         bank bcf     LATA,2
                               bcf      v_lata, 2
;   64         bank btfsc   PORTA,3  ; check if switch was set to SINE mode
                               movlb    0
                               btfsc    v_porta, 3
;   65         bank goto    done
                               goto     l_done
;   67         bank bsf     LATA,2
                               movlb    2
                               bsf      v_lata, 2
;   68         bank bcf     LATA,2
                               bcf      v_lata, 2
;   69         bank goto    loop
                               goto     l_loop
;   70     done:


So bankswitching is done when needed.

Maybe it solves your problems.

Kind regards,

Rob



Van: 'Mike' via jallist <jal...@googlegroups.com>
Verzonden: donderdag 19 maart 2026 19:30

Mike

unread,
Mar 19, 2026, 6:03:59 PM (24 hours ago) Mar 19
to jallist
Thanks, Rob.

Lots of things are resolved when one reads the manual. lol  Oops.

Regards,
Mike
Reply all
Reply to author
Forward
0 new messages