XOUT and HPWM


Closed Thread
Results 1 to 22 of 22

Thread: XOUT and HPWM

  1. #1
    Join Date
    Oct 2004
    Posts
    448

    Default XOUT and HPWM

    Hi, this is about the X10 command. I would like to modulate the signal coming out of X10, at 120 KHz. I can currently do this by using the HPWM on one pin, and getting the XOUT on another, and then combining them externally. This is at the cost of 1 extra pin, and the external circuitry.

    Is there any way that this can be done in software, so that one gets a composite modulated X10 signal out of a single pin?

    Thanks in advance for any suggestions!

    Regards,

    Anand

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


    Did you find this post helpful? Yes | No

    Default

    Hi ardhuru,

    I've never done anything like that before, but after looking at the macro's for XOUT, I think it might be possible.

    But the method used depends on the chip. Which one are you using?

    Darrel

  3. #3
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Currently, the 16F628A for its HPWM. Being able to do it on this would be fine, but if I could achieve it on a 12F629/75, better still.

    Thanks, and I'm hoping you'd have some trick to suggest!

    Regards,

    Anand

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


    Did you find this post helpful? Yes | No

    Default

    628A, OK, that should make it easy.

    XOUT TRISB.3,PORTA.0,[house\lightsOff]


    The idea is that the XOUT command takes a register and a bit for the output pin assignment. Normally this is something like PORTB.0 but it really doesn't matter which register and bit you use.

    So by assigning TRISB.3 as the output, it should modulate the PWM by turning the pins output on and off.

    PBP finds the location of the corresponding TRIS register by simply adding 80h to the PORTs address. For PORTB (06H), TRISB would be 06h + 80h = 86h.   So now, if PBP thinks that TRISB.3 is a physical pin, then it will also try to set the pin to Output by clearing (106h).3 which now lines up with PORTB again in bank2. But since that pin is overriden by the Peripheral select switch, the data doesn't get thru, so all's well.



    The reason I say all of that, is because if you try to do the same thing on an 18F, the registers don't line up next to each other like that, and can cause some pretty nasty problems.

    As for the 12F629/75, I suppose you could set up the timer to generate the frequency using interrupts, and do the same thing with TRIS.

    Should work for SEROUT(2) as well. Assuming it works at all.

    HTH,
       Darrel

  5. #5
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Darrel, thanks for the detailed reply.

    I tried this, and was at first delighted to see a strong(er) signal than what I was getting by the 2-pin method.

    But, it did not work. I notice the waveform looked different from the 2 pin waveform as well (as seen after the transistor that combined the 2 signals).

    I think the problem is, when you control the HWPM *before* and *after* the XOUT line, the spaces between the data bits that XOUT gives, which should remain low, are now consistently transitioning at 120 KHz. I suspect for this to work, like you pointed out earlier, the XOUT macro itself might have to be modified.

    Is my analysis correct, or am I being too dense?

    Regards,

    Anand

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


    Did you find this post helpful? Yes | No

    Default

    Hmmm, what I missed was the Polarity of the XOUT signal. The PBP manual didn't really go into too much detail, but i found another document on the web that explained it better. It's description goes like this.
    Transmit to Power Line—Output a high on this line within 200 μ of Zero Crossing
    going high, and hold the line high, to output a one on the power line—that is, to turn on
    the 120 kHz oscillator. Use the same timing with a low output to output a zero. The line
    should be low if the interface is not to transmit data, since that keeps the oscillator off.
    So, 1 turns the 120khz ON, 0 turns it off.

    But with the TRIS bit, it works the other way around. 1 = INPUT (OFF),  0 = OUTPUT (ON). Just a little backwards.

    I think you're right though, the only way around it is to change the XOUT command itself. Fortunately, it's an easy change if you're willing to tamper with the PBPPIC14.LIB file.

    If so, be sure to make a copy of the file before editing, you might want it back the old way later on.

    Your mission, should you choose to accept it, is to ...

    Open the PBPPIC14.LIB file in the PBP folder, and do a search for XOUT. You should see a section that looks like this
    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
    Comment out the "call     LOWT". We'll handle setting the pin to the correct state manually.

    Then scoll down a little bit to xout1loop and change it like this
    Code:
    xout1loop 
       ;     movf  RM1, W           ; Get data bit mask
       ;     iorwf   INDF, F        ; Set the bit
            comf    RM1, W          ; Get inverted data bit mask
            andwf   INDF, F         ; Clear the bit
    
            movlw   high 1000       ; Pause 1 ms
            movwf   R0 + 1
            movlw   low 1000
            call    PAUSEUSL
    
       ;     comf    RM1, W          ; Get inverted data bit mask
       ;     andwf   INDF, F         ; Clear the bit
            movf    RM1, W          ; Get data bit mask
            iorwf   INDF, F         ; Set the bit
    It just reverses whether it sets the pin high or low.

    Now, to use it ..
    Code:
        TRISB.3 = 1          ' start with output OFF
        XOUT TRISB.3,PORTA.0,[house\lightsOff]
    Fingers crossed

    P.S. Don't blame me if you don't backup the file first.
    DT

  7. #7
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Darrel, that was brilliant!

    Worked the first time. If I wore a hat, i'd have raised it now.

    Thanks and regards,

    Anand

  8. #8
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Darrel, whatever you suggested in the earlier messages worked perfect, and that's made me more ambitious/adventureous/greedy.

    What I wonder is, can this also be achieved using your popular timer0/1 based PWM techniques (instead of the PIC's HPWM) to modulate the XOUT signal? The idea being able to use this with any pic, and on any pin.

    Thanks in advance.

    Regards,

    Anand

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


    Did you find this post helpful? Yes | No

    Default

    Hi Anand,

    I think at 120kz, the interrupts required to generate that frequency on ANY pin (250,000 per second) would interfere with the timing of the XOUT command.

    I can't think of an easy way off hand.

    DT

  10. #10
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Oh, okay.

    Nothing like actually trying it out, I guess.

    Referring to some of your earlier posts I think I should be able to see if it flies.

    Shall keep this thread posted for the benefit of others, if it works.

    Thanks for all the inputs, Darrel.

    Anand

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


    Did you find this post helpful? Yes | No

    Default

    Anand,

    The 8-pin 12F683 has HWPM and only costs slightly more than the 12F629 or 12F675. I posted a simple example of turning it on/off using ~120kHz with 1ms bursts at 10ms intervals in another thread recently. Here it is again...
    Code:
    DEFINE OSC 8
    @ DEVICE PIC12F683, INTRC_OSC_NOCLKOUT, MCLR_OFF
    
    TRISIO.2 = 0				'GPIO.2=Output
    PR2 = 17			        'PWM Period   117.7kHz
    CCPR1L = 8				'PWM Duty-Cycle  
    T2CON = %00000100    			'Timer2=ON, 1:1 prescale
    OSCCON = %01110001                      'INT HF OSC 8MHz
    WHILE OSCCON.3>0: WEND                  'OSC startup timeout
    WHILE OSCCON.2=0: WEND                  'INT HF OSC stable
    WHILE OSCCON.2>0 
      CCP1CON = %00001100 'PWM ON
      PauseUS 1000        'generate 1ms burst 
      CCP1CON = 0         'PWM OFF
      Low GPIO.2
      Pause 10            'pause 10ms
    WEND
    The disadvantage of using XOUT is that it cannot send microdim/microbright and cannot send the extended commands X-10 introduced 6-7 years ago.

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


    Did you find this post helpful? Yes | No

    Default

    Hey Anand,

    Still using the 628A ?
    and what OSC ?

    I think I have something for you.

    DT
    Last edited by Darrel Taylor; - 5th May 2006 at 05:49. Reason: Come on... get your butt outta bed, this is Cool!

  13. #13
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Yes, still on the 16F628, with the internal 4 Mhz oscillator, although I'm hoping to migrate it to an 8 pin (or even 6?) device.

    I could of course use an 12F683 as Dave pointed out, but I'm still curious to see if this can be done without the HPWM module.

    Very eager to see your suggestion!

    Anand

  14. #14
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Dave, thanks for the inputs. I could not have designed the actual hardware interface to the mains without your invaluable pointers to powerline carrier articles.

    Are you suggesting that X10 signals would be better generated in PBP without using the XOUT macro? My X10 transmitter is a very basic one, so the micro dim/brights are not an issue.

    I would have loved to have some extended commands though.

    Again, a heartfelt thanks.

    Anand Dhuru

  15. #15
    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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ardhuru
    Are you suggesting that X10 signals would be better generated in PBP without using the XOUT macro? My X10 transmitter is a very basic one, so the micro dim/brights are not an issue. I would have loved to have some extended commands though.
    I think the best approach is to create a procedure (using ASM or using the CCP module) to generate a 1ms burst of ~120kHz and then call it as needed from PBP. That gives you the flexibility to send arbitrary patterns. If you also use Darrel's Instant Interrupt's, you can do the X-10 part in the background, sending a manchester half-bit at each zero-crossing.

    Using the CCP module, you could even use a timer to end the ~120kHz burst and do single or 3-phase in the background with minimal loss of processing time. This would also allow you to listen to the powerline during manchester 0 half-bits to detect collisions. Note that it does no good to listen if using a TW523 or equivalent as it delays its output by 22 powerline half-cycles, acting like a 22-bit shift register with the powerline frequency as its clock.

  17. #17
    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

  18. #18
    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.

  19. #19
    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.

  20. #20
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ardhuru
    Dave, thanks for the inputs. I could not have designed the actual hardware interface to the mains without your invaluable pointers to powerline carrier articles.

    Are you suggesting that X10 signals would be better generated in PBP without using the XOUT macro? My X10 transmitter is a very basic one, so the micro dim/brights are not an issue.

    I would have loved to have some extended commands though.
    Anand,

    There may soon be another possibility. SmartLabs tells me they will release their powerline chips this month. They will cost less than $2 even in single quantities and can do both X-10 and Insteon.

  22. #22
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Sounds very interesting

    Hi Dave,

    that sounds like a very useful product indeed; almost like a TW523-in-a-chip solutoin. I would look forward to its release.

    In the mean time, my home brew circuit with off the shelf part also seems to be holding its own. In fact, the transformer I used (one from the set used in AM radios), gives out a signal 2 to 3 times in amplitude as the one from the RR501/TM751.

    Regards,

    Anand

Members who have read this thread : 1

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