CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2005
    Location
    Singapore
    Posts
    40

    pic 18f452 input capture coding help

    hi i just start this in school no long ago hope someone can help me with this as my lecture was too confusing to understand.

    well i need to write a assembly code for the pic 18f452 to do a input capture and get the result as this is only part of the whole program there maybe parts missing so please ignore those as i am only doing input capture anyway i have gotten most of the setting done as shown below. the only problem i am having now is how do i contiune???



    list p=18f452, n=48, t=ON, st=OFF
    #include "p18f452.inc"



    ;------------------INTERRUPT SERVICE
    ROUTINE--------------------------------------------
    org 0x000000 ; reset vector
    bra start
    org 0x000008 ; high priority interrupt vector
    bra TMR1_ISR
    ;---------------------------------------------------------------------

    Program1 CODE

    start
    bcf PORTB, RB0 ;off LED
    bcf PIR2,TMR3IF ;tmr3 clear interrupt flag bit
    bcf PIR2,CCP2IF ;clear tmr1 captureccp register capture
    bsf PIE2,TMR3IE ;enable timer3
    bsf PIE2,CCP2IE ;enable ccp2
    bcf IPR2,TMR3IP ;set tmr3 priorty
    bsf IPR2,CCP2IP ;set ccp2 prority
    movlw b'01 10001' ;setting of t3con
    movwf T3CON ;config the setting of t3con
    movlw b'0100' ;
    movwf CCP1CON,CCP2M#:CCP2M0 ;
    movlw 0xAF
    movwf TMR3H
    movlw 0xAC
    movwf TMR3L


    i know i need a interrupt service but how do i write 1 and i know that i need something else but i cannot seems to remember what it is could someone fell me in on this?

    Really hope someone can help with this thanks for the help in advance

  2. #2
    Join Date
    Jul 2004
    Posts
    142

    Re: pic 18f452 input capture coding help

    There are many examples in Microchip's website:

    http://www.microchip.com/stellent
    /idcplg?IdcService=SS_GET_PAGE
    &nodeId=2047

    Make sure the above is all one line when you paste it into your browser.

  3. #3
    Join Date
    Jul 2005
    Location
    Singapore
    Posts
    40

    Re: pic 18f452 input capture coding help

    nope did a search and also look through all the folders got afew but none on input capture for pic 18f452

  4. #4
    Join Date
    Jul 2004
    Posts
    142

    Re: pic 18f452 input capture coding help

    I don't know about your pic specifically, but all pics pretty much
    have the same instruction set.
    So if you find an input capture routine for a 16xxx or a 17xxx
    or an 18xxx, it'll probably work on your chip.

    So you could try again with a wider search.

    But also, what do you mean when you say "input capture"

    Do you mean "detect when an input changes state"

    Or "Count a clock input going to a pin"

    or "measure frequency input going to a pin"

    or something else?

  5. #5
    Join Date
    Jul 2005
    Location
    Singapore
    Posts
    40

    Re: pic 18f452 input capture coding help

    think of a square wave. i will be using binary to represent it

    001110000101010101.
    1 mean high
    0 mean low
    on every rising edge which mean from 0 to 1 a interrupt will occur when the interrupt occur the input capture will capture a data from timer 1 or timer 3 which will then store the data to another initialize value for example "capture". timer 1 or 3 will run by itself from ffff

    the interrupt can be anything from a push button to a clock frequency anything that has a square wave from

  6. #6
    Join Date
    Jul 2004
    Posts
    142

    Re: pic 18f452 input capture coding help

    Well there are many things to do:
    Set up the PIC to trigger an interrupt on a change to a pin.
    This is typically done by setting the interrtupt mask to allow
    interrupts if a pin on Port B changes state.
    see chapter 9 of PIC18F4520 app note

    Also set up the PIC for capture/compare/pwm
    see chapter 15 of PIC18F4520 app note

    Then you write an interrupt routine that will start/stop the count
    when a pin changes state.

    Now, this is a lot of code to write "from one lecture",
    so I think you should go back to the professor for help.

    Also, there is no such thing as a PIC18F542 chip on Microchip's
    web site. There are many chips in the 18F542x family.

    And when I tell you to check the Microchip web site,
    all you do is type in "input capture 18F452" and then say
    "hey there's no example"

    So basically, you've skipped quite a bit of the course,
    you haven't read the data sheets,
    you don't want to search the Microchip web site
    and now you want to download your homework from CodeGuru.

    You will learn a lot more by reading the PIC docs and writing your own
    code.

  7. #7
    Join Date
    Jul 2005
    Location
    Singapore
    Posts
    40

    Re: pic 18f452 input capture coding help

    Also, there is no such thing as a PIC18F542 chip on Microchip's
    web site. There are many chips in the 18F542x family.

    1st in reply to above open you eyes big and you will see i am talking about 452 not 542.

    2nd to prove there is a 452 go to the link below
    http://www.microchip.com/stellent/id...signDocSelect=
    or
    go microchip webpage and type pic18f452 in the search textbox

    3rd i dont think i need to say more about the rest below because you didnt even read properly or search properly for a chip call 452

    good luck on your eye sight next time

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured