Ideas on ir-code for dimmer


Closed Thread
Results 1 to 1 of 1
  1. #1
    Join Date
    Sep 2008
    Posts
    2

    Default Ideas on ir-code for dimmer

    I'm trying to write code for a dimmer controlled by ir, I'm trying to adapt the ir code from the http://www.rentron.com/PicBasic/IR_Chips.htm example. I have used this ir-code before as ir-proximity sensors on two robots. The basic dimmer code that works fine by it self is:
    Code:
    ' Dimmer for 50hz AC for pic12f683 or pic12f675
    @ DEVICE INTRC_OSC, MCLR_OFF, PROTECT_OFF, WDT_ON
    ANSEL = 0 ' A/D OFF -- Port pins all digital
    TRISIO = %001100	' Set I/O
    GPIO = %000000		' All 0 on boot 
    
    AC_wave var gpio.2
    TRIAC var gpio.5
    fired var bit
    fired = 0
    dim_value var byte
    dim_value = 200
    
    OPTION_REG = %10000101 ';presc 1:64
    intcon.2 = 0		' TMR0 Overflow Interrupt Flag
    intcon.5 = 1		' TMR0 Overflow Interrupt Enable
    tmr0 = 100			' Set timer to ~10ms
    pause 100          ' Stabilize on power-up
    intcon.7 = 1		' Turn on intterupts
    
    ON INTERRUPT GOTO interrupt_rutine
    goto mainloop
    
    disable
    interrupt_rutine:
      if intcon.2 = 1 then 				' If Timer0 Overflow
        intcon.2 = 0					' Clear TMR0 Overflow Interrupt Flag
        fired = 0						' Set TRIAC fired to 0
        while AC_wave = 1				' If AC_wave is 1 wait until negative to sync
        wend
        tmr0 = 100						' Set tmr0 for ~10ms
      endif
      resume
    enable
    
    mainloop:
      if fired = 0 then					' If TRIAC is not yet fired
        if tmr0 > dim_value then		' If it's time to fire TRIAC
          high TRIAC					' Fire TRIAC
          pauseus 100
          low TRIAC
          fired = 1					' Set TRIAC fired to 1
        endif
      endif
      goto mainloop
    But the problem is that when I try to integrate the ir-code into this code the ir-reception takes way to much time, one ir-transmission is ~10-18ms + the time to verify the signal. If the pic would get the transmission right every time a interruption of 20ms would be acceptable but when I try to set GPIE to detect an incoming signal it seems like picbasics interrupt check takes to much time for the pic to get to the function that records the signal and the verification fails.

    I have seen several projects somehow managing to both send TRIAC signals with pic12f675 or similar without the light flickering when the pic receives the ir-signal, how do they do? I can't get the pic to be at two places in the program at once. Do I need to use hardware interrupts instead?

    I know that there are a lot of dimmer threads i this forum but I did not find anything on a dimmer with ir-reception. Any other ir-code would be fine as long as I'm able to receive a 4-5 bit header and a 8 bit value.

    Any good ideas?
    Last edited by tirithen; - 13th February 2009 at 23:51.

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Plz help in completing RC-5 IR remote lamp dimmer project
    By vu2iia in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2008, 08:44
  5. how to get pic to pic communication
    By kinsiro in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th August 2005, 17:12

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

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