Interrupt & device setup for a PIC16F628A in Microcode Studio Plus


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi, PiKachu

    I think reading carefully the '628a datashhet, Chapter CCP, sub chapter CAPTURE could greatly :

    1) improve your knowlege
    2) show you you're re-inventing the wheel
    3) solve your timing headache.

    May be your reflected signal input will have to be directed to PortB.3 ... but I do not think it will be an unavoidable problem ...


    Now, ... you have a PbP command called RCTime with a 2µs @ 20Mhz resolution ... ( see manual for how it works !!! )

    2*1E-6 * 330 = .66 E-3 m ... no comment !
    2*65535*1E-6*330 = 43.25 m ... more than your sensors could ever sense !!!


    ... and remember all period measurements also can be done like that ...

    wish you happy hours

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2


    Did you find this post helpful? Yes | No

    Default

    @ skimask. yeah i know but we make do with what we have.

    @acetronics: I chose BR0/INT because the receiving circuit is a single frequency passband filter, with a peak at 40.3kHz and the -3db points at 39.2kHz and 41.6kHz, which is then connected to a comparator giving me a change of 0VDC-5VDC hence wanting to use the external interrupt on a change of PORTB.0, I'm using the RB3/CCP to generate a 40kHz signal.
    I'm aiming for a range of 0.5m to 20m but with the attenuation on a 40kHz signal in air 10m is more realistic, if only i could get my hands on a 25kHz transducer set (they dont bring them into south africa).

    ok think i've got my timer1 problems sorted. wanting a prescaler value of 1:2, a preset value of 1000. is the following code right?


    preset Var Word
    preset = 1000 ' to give me a preset value of 2ms at a prescaler value of 1:2 for timer1
    TMR1H = preset.highbyte
    TMR1L = preset.lowbyte
    T1CON = %00010000 'prescaler value of 1:2, timer diabled
    INTCON = %11010000 ' GIE & PEIE & INTE enabled
    PIE1.0 = 0 ' TMR1 interrupt disabled
    PIR1.0 = 0 ' TMR1 interrupt flag reset

    start code......
    ........
    .......
    T1CON.0 = 1 ' timer1 enable with a preset value of 1000 and a prescaler value of 1:2
    pause 2000 'wait 2 seconds, this is the only place that the external interrupt must be active, still working on that tho.
    T1CON.0 = 0 ' timer 1 disable
    more code....
    .........
    .........
    end code

    i've read through the datasheet and it doesnt explain GIE and PEIE very well, what is their purpose? does GIE enable every interrupt or just allow the enabled interrupts to happen throughout the entire program? do i have to set PEIE to enable an external interrupt?

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wildpikachu View Post
    . . . if only i could get my hands on a 25kHz transducer set (they dont bring them into south africa) . . .
    I have got to ask . . . why not?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hi JoeS.

    No one brings them into South Africa, not even RS components, and its going to cost about double the entire project to ship one over so its not worth it just for an estimated 5meter distance gain and my lecturer has told me that i will get 100% if i can measure up to 10 meters with 5% accuracy because its more about implementing the theory than actual long distance measuring ability. I can always change it later, 2 lines of code and 4 resistors on the filter.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wildpikachu View Post

    @acetronics: I chose BR0/INT because the receiving circuit is a single frequency passband filter, with a peak at 40.3kHz and the -3db points at 39.2kHz and 41.6kHz, which is then connected to a comparator giving me a change of 0VDC-5VDC hence wanting to use the external interrupt on a change of PORTB.0, I'm using the RB3/CCP to generate a 40kHz signal.
    I'm aiming for a range of 0.5m to 20m but with the attenuation on a 40kHz signal in air 10m is more realistic, if only i could get my hands on a 25kHz transducer set (they dont bring them into south africa).

    ok think i've got my timer1 problems sorted. wanting a prescaler value of 1:2, a preset value of 1000. is the following code right?


    preset Var Word
    preset = 1000 ' to give me a preset value of 2ms at a prescaler value of 1:2 for timer1
    TMR1H = preset.highbyte
    TMR1L = preset.lowbyte
    T1CON = %00010000 'prescaler value of 1:2, timer diabled
    INTCON = %11010000 ' GIE & PEIE & INTE enabled
    PIE1.0 = 0 ' TMR1 interrupt disabled
    PIR1.0 = 0 ' TMR1 interrupt flag reset

    start code......
    ........
    .......
    T1CON.0 = 1 ' timer1 enable with a preset value of 1000 and a prescaler value of 1:2
    pause 2000 'wait 2 seconds, this is the only place that the external interrupt must be active, still working on that tho.
    T1CON.0 = 0 ' timer 1 disable
    more code....
    .........
    .........
    end code

    i've read through the datasheet and it doesnt explain GIE and PEIE very well, what is their purpose? does GIE enable every interrupt or just allow the enabled interrupts to happen throughout the entire program? do i have to set PEIE to enable an external interrupt?
    Hi, Pikachu

    I see you have locked your hardware definition ... so, let's try to do with.

    in your code, you forget to enable TMR1 INT ( PIE1) when using TMR1 ... you can enable it in your header, if TMR1 just works during your 2s Pause.

    PEIE is intended to control PERIPHERALs interrupts such from Timer1, ADC, COMP ( ~ External modules )...

    GIE controls ALL interrupts wherever they come ... AND, of course, allow them IF they are individually allowed ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Hi Alain.
    thanks for the reply, really cleared things up for me. I wasnt going to use timer1 to generate an interrupt but have decided to let it now. I'm using a simple repeated check on RB0 to check for a change instead of using an interrupt.

    I've attached my code, seems right to me but if anyone finds any problems or has any advice please let me know.

    Cheers
    Guy
    Attached Files Attached Files

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Picatchu

    nice code template ... easy to read !

    some tricks :

    Code:
      if (PORTB.0 = rb0old) then goto changetest ' If there is no change then test again
    change for :

    Code:
    While (PORTB.0 = rb0old)
    Wend
    this will loop till a change occurs ... ( much faster ! )

    Note here I did not understand why use the "change" feature : from your explanations ... if "back" signal detected, it simply turns PortB.0 input ON ( ... or OFF depending Hardware)

    Code:
        dummy = (time((6 * temp)+ 3300))    ' calculate part of the full calculation
    to me ( I can fail ...)
    it might be :

    Code:
        dummy = (time*((6 * temp)+ 3300))    ' calculate part of the full calculation
    By the Way : Speed of sound in air = SQR ( 13 * 287* (273.15 + Temp) /10 )

    ... @ sea level ...

    ...

    Alain

    PS: May be you could try a "samples" request here ...

    http://www.midascomponents.co.uk/
    Last edited by Acetronics2; - 3rd May 2008 at 14:47.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Hi alain.

    thanks for the "while" and maths suggestions and for the complement on my code, I will implement them. the checking for a change on RB0 is because the receiving circuit is set to be extremely sensitive and I am not sure what state the comparator, that is connected to RB0, will be in (either 0V or 5V) thats why i'm checking for a change so that regardless of what state the comparator is initially i will stop timer1 as soon as possible. if the code was this: if PORTB.0 = 1 and initially the comparator was at a high i would get an instant stop without even receiving a signal. well in my mind it makes sence :-)

    The calculation is got from one of my physics books and modified it to get rid of any decimal places and to work the distance out in one. it uses temperature in celcius rather than Kelvin.

    thanks for the link, lets see if they are willing to send overseas :-)

    Cheers and thanks again for the help!

    - Guy

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 03:35
  2. Microcode studio - PIC16F877A Interrupts
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th January 2009, 07:10
  3. CDlite to MicroCode Studio
    By grounded in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 30th January 2007, 16:46
  4. MicroCode Studio Plus ICD
    By mwhatley in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 17th August 2006, 21:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07

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