Any Simple ASM interupt code examples out there?


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171

    Default Any Simple ASM interupt code examples out there?

    Am looking for a simple interupt code example that will just escape to the interupt on rollover of tmr. I need to have a reliable timebase for a program I've got where it needs to exit with an ASM interupt.

    Thanks in advance

  2. #2
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91


    Did you find this post helpful? Yes | No

    Default Interrupts

    Let me be the first to point you here.......
    http://www.picbasic.co.uk/forum/showthread.php?t=3251
    It has to be simple, even I can use it.

    Hope it helps.
    "It will never happen here!" just happened here.
    My thoughts and prayers for Sandy Hook victims and families.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by George View Post
    Am looking for a simple interupt code example that will just escape to the interupt on rollover of tmr. I need to have a reliable timebase for a program I've got where it needs to exit with an ASM interupt.

    Thanks in advance
    Section 9.3 of the PBP manual, just set up your timer module, change the references from portb.0 over to the timer, and you're set...

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Now we have 3 version of interrupts here

    ASM
    Instant Interrupt
    PBP ON interrupt

    the easiests are PBP, and Darrel Instant interrupts. More efficient pure ASM... but Darrel's instant is really f**** close of the ASM.

    As always, nobody's give the PIC # and the expected results... hard to point out the best and ultimate Solution.... it won't break your keyboard to type few more lines. If so, i'll send you a brand new one... i buy keyboard in slap of 100's. 1-2 buck each.
    Last edited by mister_e; - 22nd March 2007 at 22:20.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    The PIC is a 16F676 so it's pretty tight with code space and variables (have tried DT's code but it runs out of variables), I'm just trying to exit from a serin command where there is always noise coming into the port (AM reciever module) just to increment a timer - and turn device off after a predetermined time.
    Last edited by George; - 23rd March 2007 at 04:23.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Can you post your code here?

    To me a PIC with a USART would be more interesting in this case.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Lightbulb You need not use interrupt

    Hi,

    Even if you are not using interrupts the timer0 rollover (INTCON.2, T0IF) gets set. So you can periodically check if the flag is set. To get proper timeout your main body loop should not execute for more than the timer0 rollover period. Even if it does then you miss a few ticks but still get some dirty timing. So here is how it goes
    Code:
        OPTION_REG = %11000111     ' SET PRESCALE HERE 256 (Datasheet PAGE 14)
        ' @4MHz AND PRESCALE TIMER0 ROLLSOVER IN ABOUT 65.5 mS
        TIME_COUNTER VAR WORD      ' MAY BE A BYTE ALSO
        
        INTCON = 0
        TIME_COUNTER = 0
        MAIN_LOOP:
        
        ' DO WHATEVER
        IF INTCON.2 = 1 THEN       ' CHECK IF TIMER ROLLED OVER
           INTCON.2 = 0            ' CLEAR THE HARDWARE FLAG
           TMR0     = 0            ' CLEAR TIMER0 IF YOU WISH
           TIME_COUNTER = TIME_COUNTER + 1 ' INCREMENT YOUR COUNTER
        ENDIF
           IF TIME_COUNTER > PRESET THEN QUIT_LOOP
           
    
        GOTO MAIN_LOOP
           
        QUIT_LOOP:
        
        ' TIME OVER DO WHATEVER
    PRESET is hard coded. In your main routine when you receive a valid signal don't forget to clear (Reset) the timer_counter variable and any pending ticks i.e., INTCON.2
    Hope this helps
    Regards

    Sougata

  8. #8
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Thanks sougata, that'll be a handy piece of code for some other timing projects of mine - I havn't used the timer in a project before, just a crude timing loop instead.

    I need to interupt to get out of serin command when there is static on the line, tho I'll prolly end up using the RSSI on the module and squelch it, would just be nice to have done this as a sample for learning.

    How do you put code snippets in the little box on this forum? Mine is pasted below sofar

    @ DEVICE PIC16F676, INTRC_OSC_NOCLKOUT, MCLR_OFF, PROTECT_OFF, BOD_ON, CPD_OFF


    Define OSCCAL_1K 1
    DEFINE OSC 4

    TRISA = %001000
    TRISC = %000000


    ANSEL = 0 'disable analog
    T1CON = %00000100
    VRCON = 0 ' A/D Voltage reference disabled
    CMCON = 7 'Disable comparitor

    timesw var PortA.5
    gosw var PortA.3
    stopsw var PortA.4
    LED1 var PortA.0
    timeset var byte
    display var byte
    'time var word
    b0 var byte
    b1 var bit
    b2 var byte

    clear
    timeset = 1
    PortA = 0
    PortC = 0

    Begin: 'start sequence

    display = (1 << b0) - 1
    PORTC = display
    pause 100
    if b0 < 7 then
    b0 = b0 + 1
    goto begin
    Else
    Pause 1000
    b0 = 0
    portC = b0
    Endif

    Start:

    serin PORTA.3,0,1,time,["READY"], timeset, b1 'Read receiver
    gosub disply

    time:
    if timeset = 0 then b1 = 0
    PortA.0 = b1
    goto start

    disply:

    display = (1 << timeset) 'Set display to be bar type
    PORTC = display 'output LEDs
    ' PORTA.0 = b1

    return

    'INTERUPT_SNIP ON TIMING INTERUPT

    ' if b1 = 1 then
    ' time = time + 1
    ' else
    ' time = 0
    ' endif

    ' if time > 200 and b1 = 1 then
    ' time = 0
    ' timeset = timeset - 1
    ' endif

    'RTN FRM INT

  9. #9
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Any idea's on squelch circuit? I was thinking about using an LM358 opamp putting the RSSI and a threshold into one amp then the output of that (maybe thru a divider) to the input of the other amp alongside data to get a squelched output?

    I think MELabs should modify their code for the serin timeout and supply a timeout feature that will timeout if the qualifier isn't met within the timeout period I realise this would be more difficult - but I've spent hours fluffing around on what should be such a simple project - monitoring an RF receiver and counting down the time - i can't exit from the serin cos the static noise on the line resets the timer in the serin command, i can't use Darryl's wonderful interupt file cos it chews up all my variables, i can use an asm interupt cos I'm not really advanced enough to figure it out. Hopefully the squelch will work albeit with what probably is a significant reduction in range.

    I do like Mister_e's concept of looking at a USART - I might have a quick look in2 that before I build my squelch
    Last edited by George; - 26th March 2007 at 02:22.

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by George View Post
    Any idea's on squelch circuit? I was thinking about using an LM358 opamp putting the RSSI and a threshold into one amp then the output of that (maybe thru a divider) to the input of the other amp alongside data to get a squelched output?

    I think MELabs should modify their code for the serin timeout and supply a timeout feature that will timeout if the qualifier isn't met within the timeout period I realise this would be more difficult - but I've spent hours fluffing around on what should be such a simple project - monitoring an RF receiver and counting down the time - i can't exit from the serin cos the static noise on the line resets the timer in the serin command, i can't use Darryl's wonderful interupt file cos it chews up all my variables, i can use an asm interupt cos I'm not really advanced enough to figure it out. Hopefully the squelch will work albeit with what probably is a significant reduction in range.

    I do like Mister_e's concept of looking at a USART - I might have a quick look in2 that before I build my squelch
    Definetely use the hardware USART...many advantages...not to mention you learn a bit about. A bit of a steep learning curve...not too bad though...
    The op-amp...somehow I get the feeling that the op-amp idea will pick up just as much noise as the raw data stream itself and you'll be getting loads of false interrupts.

  11. #11
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Just looking through the site here looks like HSERIN will give just as many if not more headaches - so might pass on that

  12. #12
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Unhappy I am confused

    Hi,

    As far as I understood that you need to monitor the serial input lines for your system to get "READY" as your qualifier. You can always do the qualifier checking manually. Looking for a "R", if found then "E" if not then again "R" and so on. Thus you (your PIC) would not be sitting inside the receive subroutine. Also the b1 variable used in your code is a BIT variable. I have no idea how a bit variable is treated in the serin ?? Also your pseudo code for the interrupt makes no sense. I thought "time" was a label but your code increments it
    Please give me a little more detail on the receiver module, a datasheet pointer perhaps and exactly what you are trying to achieve in plain english. 16F676 does not have a hardware USART. Using it saves you the headache of polling the serial pin quite often so that you don't miss a bit. But you need to use USART interrupt then.
    Regards

    Sougata

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by George View Post
    Just looking through the site here looks like HSERIN will give just as many if not more headaches - so might pass on that
    I wasn't talking about HSERIN, I was talking about straight up USART usage.
    Maybe something like let the USART receive characters, let an interrupt put the received characters into a FIFO buffer.
    In your program loop, you check the buffer for a "READY". If you don't have it, you go on, if you have garbage, you get rid of the garbage...but...if you do have "READY", then if you have X data bytes behind that with some sort of qualifying trailer (say "END"), you have a valid data stream, you extract the data, clear the buffer and wait for another string in the buffer like the above ("READYdatadataEND").
    All done in the background, no waiting for anything, and the only thing that holds up your program loop is the quick jump into the interrupt subroutine that pulls the data from the receive register and puts it into the buffer string.

    Do you know how to do interrupts? If not, this looks like a pretty good project to learn it on... Not mention...loads of help for ya...

  14. #14
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sougata View Post
    Hi,

    As far as I understood that you need to monitor the serial input lines for your system to get "READY" as your qualifier. You can always do the qualifier checking manually. Looking for a "R", if found then "E" if not then again "R" and so on. Thus you (your PIC) would not be sitting inside the receive subroutine. Also the b1 variable used in your code is a BIT variable. I have no idea how a bit variable is treated in the serin ?? Also your pseudo code for the interrupt makes no sense. I thought "time" was a label but your code increments it
    Please give me a little more detail on the receiver module, a datasheet pointer perhaps and exactly what you are trying to achieve in plain english. 16F676 does not have a hardware USART. Using it saves you the headache of polling the serial pin quite often so that you don't miss a bit. But you need to use USART interrupt then.

    How would I do the manual looking for "R", "E"... and so forth? Sorry about my pseudo code, I did it in a hurry, the lower time should read "timer" or something equiv.

    The receiver module is a linx RXM LR-418 and a link to data sheets is here: http://www.linxtechnologies.com/inde...gory=lr_series

    I'll I'm trying to do is not get the program stuck in the SERIN command when it's hearing radio static. even a timeout of 1ms hardly manages to break out of the command - very randomly and intermittantly. Am wanting to increment timer, I'll try using the TMR in the PIC for the 1st time on this project, but really need it to reliably be able to come out of the SERIN so I can switch other things - it will very seldom see a radio transmission - but when it does I need to capture it. Thanks for yr input so far

    A BIT variable seems to work ok in serin - well I haven't had any trouble with it, and it's always responded reliably.
    Last edited by George; - 28th March 2007 at 00:40.

  15. #15
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Is this what you are trying to achieve

    Hi,

    As you mentioned most of the time your radio receiver would be idle (receiving nothing). Your intention is to get out of the serial in routine when you are getting "junk" due to the random switching of the receiver output. The code I posted can just do that for you. The SERIN can jump to a label when nothing is received in the input (the input pin remains idle). So most of the time you will get "characters" due to the receiver throtlling around the noise floor. Just validate your character manually and reset your timer_counter if it is something you expect. Say you are expecting a "R". Get the character from serin first to a byte variable then check if the byte="R" and increment another pointer to check for an "E" next. If not you can let your timer_counter roll. Also you can use a 5 byte FIFO buffer to make things easy. In the FIFO you will always have the last 5 bytes received and validation becomes easier.

    You can also use the RSSI as per the datasheet to guide your PIC when to grab a data. It releives you of the software headache.

    Give the receiver side code or whatever you are transmitting. I shall try to find some time to give you an example
    Regards

    Sougata

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 09:02
  2. ASM code
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 1st March 2010, 23:55
  3. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. ASM Interrupts with BASIC code?
    By Desterline in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 31st October 2003, 19:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts