News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

SHOut disables TMR1 interrupt

Started by shantanu@india, Dec 03, 2025, 09:52 AM

Previous topic - Next topic

shantanu@india

Hi,
This is mainly to draw Les's attention to this small issue in the compiler.
I am using 18F24K22 with TMR1 interrupt @200msec & in the main program SHOut is being called after 5 TMR1 interrupts i.e @ 1 sec. After the first SHOut the interrupt is somehow getting disabled so that 1-sec execution stops altogether.
I had to write a small bit-banged substitute of SHOut to solve the issue.
This was reported in another of my threads a few months back.
Regards
Shantanu

Stephen Moss

If memory serves SHout is a software serial data transfer solution, in which case there is some logic to it disabling interrupts until the serial data transfer has completed so that the data transfer itself is not interrupted.
The simplest way to do that would be to set the global Interrupt Enable bit to false (GIE=0), so if you have not already done so try setting the GIE bit to 1 immediately after your SHout command and see if that resolves the problem.

top204

#2
Only one of the compiler's commands touch a timer, and that is HPWM, for Timer2. None of the other commands touch any of the timers, or effect any interrupts.

The Shout and Shin commands, just like other commands that need a pin reference, use the address of the port and a mask for the pin, and all delays within commands are done with loops or Nop, or Bra mnemonics, while toggling pins, or waiting for pins.


shantanu@india

To make things clearer I'll outline what the problem was & how I worked around it.

Symbol StrobePin  LATA.7
Symbol DataPin    LATC.0
Symbol ClockPin  LATA.6

interrupt_program:

   Context Save

  'TMR1 interrupt  @ 200 msec

    If PIR1.0 =1 Then
        Clear PIR1.0
        timer1=15535
        Inc timer1_count
        If timer1_count>=5 Then
            Set refresh_flag
        endif
   Context Restore

main:
    ....................
    ....................
    Initialize TMR1 for 200 msec interrupt
    ......................................
    While 1=1
      if refresh_flag=1 then
        SHOut DataPin,ClockPin, LsbFirst,[relay_state\8]
        High StrobePin
        Nop
        Low StrobePin
      EndIf
    Wend
In the above code SHOut works only once  due to interrupt getting disabled somehow. I did not go into assembly code to check.

So I had to replace SHOut with the following SPIOut subroutine:

SPIOut:
    ByteOut=relay_state
    for pos = 0 to 7
      if ByteOut & $01=1 then
        DataPin=1
        elseif ByteOut & $01=0 then
        DataPin=0
        endif
        nop
        ClockPin=1
        nop
        ClockPin=0
    ByteOut=ByteOut>>1
    Next
    StrobePin=1
    nop
    StrobePin=0
    return
Regards
Shantanu

top204

The pins must be Port.Pin, otherwise, they will fail. Same if they were TRIS or VAR.BIT etc... A LAT is not Port.Pin.

The commands expect a Port.Pin as the parameter, and do not check if they are valid, because I did not tink it would be necessary, when the manual, and the hints both state a Port.Pin for teh Clock and Data lines. :-)

I'll see if I can add a check for them, and add an error message.

tumbleweed

I mentioned all this in post#8 of the linked thread...

shantanu@india

Thanks Les & Tumbleweed.
Yes it was a mistake on my part to use LAT to declare Port pins.
Regards
Shantanu

top204

I'll try to add a warning, and also correct any LAT or TRIS uses as the pins, and make them the appropriate PORT, As I have done in several compiler commands. i.e. PinHigh, PinLow, PinInput, PinOutput etc...