XOUT and HPWM


Closed Thread
Results 1 to 22 of 22

Thread: XOUT and HPWM

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    4mhz! You don't believe in making things easy do you.

    but I'm still curious to see if this can be done without the HPWM module
    I believe it can be done on any pin, without any hardware modules, CCP or Timer, and no Interrupts.

    Last time, we used the CCP module to create the 120khz, then used XOUT to turn that output on and off. But during that 1ms period that it's sending a "1", the XOUT command is just spinning it's wheels in a PAUSEUS 1000.

    Instead of just sitting there letting the hardware do all the work, why not just create the frequency in software for 1ms and be done with it.

    Once again, I've never done this, but maybe I can get lucky twice in a row.

    For a 120khz signal of 1ms in duration, we need to create 120 cycles.
    Each cycle is 8.3333 us (1/120,000).
    @ 4mhz it doesn't divide perfectly, so the closest we can get is an 8us cycle which ends up at 125khz. I hope that's close enough.

    First off, in your main program, make a variable like this to use for counting the cycles
    Code:
    LoopCounter  VAR BYTE  $20  SYSTEM

    Now let's go back to the PBPPIC14.lib file. Un-Comment the LOWT line that we had commented previously. This gives back control of the TRIS register to the XOUT command.
    Code:
        ifdef XOUT_USED
      LIST
    XOUT2   movlw   2               ; Default to 2 cycles
    XOUT    movwf   R2              ; Save number of cycles
            movf    RR1, W          ; Get data port
            movwf   FSR             ; Put it into FSR
            movf    RM1, W          ; Get data bit mask
            call    LOWT            ; Set data to low, output
    And, change the xout1loop that we modified before, to this ...
    Code:
    xout1loop 
        movlw   120   ; 120khz for 1ms = 120 cycles
        movwf   LoopCounter
        
    xout120loop
            ; ---- 1 cycle of the 120khz ---------------------
            movf    RM1, W              ; 1    Get data bit mask
            iorwf   INDF, F             ; 2    Set the bit
            nop                         ; 3    waist some time
            comf    RM1, W              ; 4    Get inverted data bit mask
            andwf   INDF, F             ; 5    Clear the bit
    
        decfsz   LoopCounter, F         ; 6    Are we done yet?
        goto     xout120loop            ; 8    NO.  Do it again.
    Then, using it should be like normal again ...
    Code:
    XOUT PORTB.3,PORTA.0,[house\lightsOff]
    Once again, Fingers crossed
    <br>
    DT

  2. #2
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default How do you do it?!

    Quote Originally Posted by Darrel Taylor
    4mhz! You don't believe in making things easy do you.


    Once again, Fingers crossed
    <br>
    Time to raise my hat again! That was superlative, Darrel. Worked the first time (that is, as soon as I remembered to switch off the CCP module enabled for the earlier version!). And of course, I confirmed it works as well on any other pin.

    Thanks a ton.

    Anand

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Fantastic!

    My luck seems to be getting better.

    I'm thinking it's time for a trip to Vegas.

    You're very welcome, and thanks for the fun project.

    DT

    P.S. Dave's idea sounds pretty good too. More control.
    &nbsp; &nbsp; And Jeff might be happier without us messing with his macro's.

  4. #4
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor
    P.S. Dave's idea sounds pretty good too. More control.
    I would love to see an example for the 12F683.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I would love to see an example for the 12F683.
    So would I.

    I'm glad it was your idea.

    DT

    oops, so much for the good karma from before.
    Maybe I better skip Vegas.

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