Shop OBEX P1 Docs P2 Docs Learn Events
RTCC clock — Parallax Forums

RTCC clock

LightfootLightfoot Posts: 228
edited 2008-01-03 02:04 in General Discussion
How to you configure the interrupt code to fire each time the RTCC pin is pulsed?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • BeanBean Posts: 8,129
    edited 2007-08-05 13:15
    The interrupt is triggered when RTCC "rolls over" from 255 to 0. So you will need to set RTCC to 255 in the setup code and in the interrupt code.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • LightfootLightfoot Posts: 228
    edited 2007-08-05 18:39
    Will this do it?

    INTERRUPT 255

    <code>

    RETURNINT

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 9,217
    edited 2007-08-05 18:50
    No, you need to do this:

    INTERRUPT
    
      ' ISR code here
    
    RETURNINT 255
    



    You'll also have to set the option register -- this is covered in the help file.

    Q: Why bother using the RTCC input in this manner when you could easily use an edge-triggered interrupt on port B? There's an example of "Who was first?" button input program that uses port b interrupts in the help file.
  • BeanBean Posts: 8,129
    edited 2007-08-05 22:30
    Actually I think you will need to use "RETURNINT 1".

    When I get a chance I will try it. But like JonnyMac said, using Port B interrupts would be simplier.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • LightfootLightfoot Posts: 228
    edited 2007-08-06 23:44
    I manageed to free up RB.0 for interrupt use. Here is the code I am using. A zero cross detector is on the RB.0 pin. The interupt code triggers a triac (that parts works, I tried it). I am unsure if what I am doing here is wrong because the code does not work.

    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000

    INTERRUPT 'Pulse triac

    pauseus 6000
    ra.0 = 1
    pause 1
    ra.0 = 0

    RETURNINT

    PROGRAM Start

    Start:

    tris_a = %1110
    plp_a = 0
    WKPND_B = %00000000
    WKED_B = %11111111
    WKEN_B = %11111110 'Zero cross detector at RB.0

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 9,217
    edited 2007-08-06 23:57
    Does you triac circuit work? It's impossible for you to know if your program works or not unless you're sure that you can control the triac on-and-off. Trust me, I've been down that road (when designing the EFX-TEK FC-4 -- which polls the ZC input).

    Another issue could be the use of the internal clock; it's not very accurate and your timing may not be as close as you thing -- especially with the granularity of a 4 MHz clock.
  • LightfootLightfoot Posts: 228
    edited 2007-08-07 07:24
    Triac circuit works fine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 9,217
    edited 2007-08-07 14:39
    I have your strategy working on my board (see attached) -- you have to clear the pending register at the end of the interrupt to enable new interrupts. Also, I really think your timing is going to be sloppy using the internal 4 MHz clock; I have a 20 MHz resonator on my board. That said, once I got the program working I switched to the internal clock and it still seems to work.

    The *problem* with this strategy is the delays in the ISR mean that the dimmer the lamp, the more time is consumed by the ISR; most dimmers use a polling strategy with a counter in the ISR to control triac firing -- this minimizes time spent in the ISR leaving cycles for the foreground.

    Post Edited (JonnyMac) : 8/7/2007 2:55:56 PM GMT
  • LightfootLightfoot Posts: 228
    edited 2007-08-07 15:54
    How does the ISR counter strategy work?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 9,217
    edited 2007-08-07 16:43
    You need two variables for your triac control: a level (used by the foreground) and an accumulator (used by the ISR). When the ZC is detected you copy the level to the accumulator, then each pass through you increment the accumulator and when it rolls over from 255 to zero, you turn on the triac. If you set your ISR rate to 32.5 uS then you get 256 divisions in each half cycle. This is what my four-channel dimmer (EFX-TEK FC-4) does.

    Edit: I modified the demo (above) to use ZC polling in the ISR. Note that two flag bits are used to detect the 0 -> 1 transition on the ZC input which resets the accumulator. The ISR can be a little tighter if coded in assembly; like this:

    INTERRUPT NOCODE 30720
    
      ASM
        BANK  0
        MOVB  thisZC, ZCross                        ' capture ZC
        JNB   thisZC, No_ZC                         ' look for 0 -> 1 change
        JB    lastZC, No_ZC
        MOV   acc, level                            ' reset accumulator
    
    No_ZC:
        MOVB  lastZC, thisZC                        ' save ZC scan
        CLRB  Lamp1                                 ' triac off 
    
    Update_Acc:
        INC   acc                                   ' bump accumulator  
        SNZ                                         ' if not zero, exit
        SETB  Lamp1                                 ' else triac on
      ENDASM 
      RETURNINT
    

    Post Edited (JonnyMac) : 8/7/2007 5:06:54 PM GMT
  • bennettdanbennettdan Posts: 614
    edited 2008-01-02 02:44
    JonnyMac I have been looking into some ciruits for a christmas lights to music sequencer and I have looked into the vixen but I had already started writing some VB.net code to sync music like the vixen works but a little different and I like the code you have here for the SX. If you want more channels you have to change the ISR to allow for the extra channels and the interrupt time has to be changed?
  • JonnyMacJonnyMac Posts: 9,217
    edited 2008-01-02 03:11
    You need to update the interrupt for more channels, but you don't change the ISR timing. I have an article in the November article of Nuts & Volts that shows how to build an eight-channel dimmer that can be daisy-chained (via RS-485) to up to 128 channels. BTW, I designed that board to be controlled by Vixen and KC Oaks wrote a driver for the board. You can get all my updated files here:

    http://www.christmasinshirley.com/forum/viewtopic.php?t=1567

    Post Edited (JonnyMac) : 1/2/2008 3:18:29 AM GMT
  • bennettdanbennettdan Posts: 614
    edited 2008-01-02 04:04
    Thanks Jon
    I plan to share the light control program when I get it done. I think it will be very user freindly..
    One more question does your ZC detector see the line voltage at 120hz or 8.333 ms pulse? I am using a bridge diode into a optoisolator then feeding that into my micro...

    Post Edited (bennettdan) : 1/2/2008 4:09:56 AM GMT
  • JonnyMacJonnyMac Posts: 9,217
    edited 2008-01-02 19:26
    That's not *my* detector, I found it in use in many similar circuits. It outputs a high-going pulse that straddles the ZC point (so the pulse shows up ever 8.33 ms). In my program the dimmer stuff is running every 32.5 uS and it checks to see if the ZC is presently high and that the last scan was low; when this condition is met the dimmer registers are reloaded for a new cycle.
  • bennettdanbennettdan Posts: 614
    edited 2008-01-03 00:42
    Will my ZC detector still work with your code or do I need to try a different detector?
  • JonnyMacJonnyMac Posts: 9,217
    edited 2008-01-03 02:04
    So long as you're not filtering after your bridge I think it should still work. Look at the output of the detector -- do you get a high-going pulse every 8.33 milliseconds? If you do, you're cool.
Sign In or Register to comment.