[Menu]>[Circuits Gallery]>[Decorative light]


Processing explanation of Decorative light Controller

Interruption operation
Three kinds of interruptions are used on this software. The following explanation is in case of 50 Hz.
RB0 int:The polarity reversals (0V) of alternating voltage are detected by this interruption.
TMR0 int: ON timing of the TRIAC is controlled.
The interruption is 1 millisecond
TMR1 int: Pattern switch reading and ON timing change of the TRIAC are done.
The interruption is 50 milliseconds.

In case of TMR0 and TMR1, TRIAC1 to 5 are conrtolled sequentially.

RB0 interruption
;*************** RB0 interruption process ***************
    The polarity reversals of alternating voltage are detected by the photo coupler for alternating voltage (TLP626), and a synchronization pulse is inputted into RB0. If voltage change of RB0 is detected by PIC, the INTF bit of an INTCON register will be set to 1, and an interrupt will occur. The following TRIAC control initializations are performed by this interruption.
    - Initialization of TMR0
    - Initialization (0) of the index (tmr0_index) which manages a control position for every interruption of TMR0
    - Initialization (OFF) of the data (porta_work) for holding the ON/OFF state of TRIAC
    - Initialization (OFF) of PORTA which controls ON/OFF of TRIAC
TMR0 interruption
;************** TMR0 interruption process ***************
    The count-out of TMR0 is carried out for every 500 microseconds and the interruption occurs.
    By this interruption, the timing which makes a TRIAC ON is controlled. The timing which makes a TRIAC ON is indicated by TRIAC control memory (TRIACx). The index (tmr0_index) of TMR0 is increased in 1 every time the interruption of TMR0 occurs and is made ON condition in the TRIAC when becoming the same as the value of the TRIAC control memory. Therefore, if the value of TRIAC control memory is small, the timing turned ON will become early and a lamp will come on brightly. If a value is large, timing will become late and a lamp will become dark.
TMR1 interruption
;***** Timer1 interruption process (50ms interval) ******
    The count-out of TMR1 is carried out for every 50 milliseconds and the interruption occurs. In the interruption processing of TMR1, the reading of pattern switches and the processing to change the control timing for TRIAC are done.
    In the pattern switch reading processing, it specifies a switch by 3 bits of higher ranks (RB7-5) of PORTB. After that the reading of PORTB is done. The timing for 750 microseconds is prepared after carrying out switch specification until it reads PORTB. The condition of the switch is stored in RB4-1. So, it is 1 bit shifted to the right and it sets to 4 bits of lower ranks once more. In the read data, 0 and 1 are reversed. So, it is reversed using xorwf instruction. 4 bits of lower ranks are picked up and are stored in portb_work. The condition of the switch is stored in swx_mode. However, it isn't changing if the contents of portb_work and swx_mode are the same. In the case, storage processing isn't done. When the contents of portb_work and swx_mode were different, the setting of a switch was changed. In this case, read data is stored in swx_mode. Moreover, the process number (tx_proc) to use in the control timing for TRIAC is cleared. Pattern data is initialized by this. All switch readings were performed by one processing in the early design. However, since control time was short, a decoder did not operate normally. Then, I changed into the processing which reads the state of one switch by one processing. Therefore, reading is done a maximum of 250 milliseconds later after change of the position of the switch. There is no problem.
    Control timing process for TRIAC is started up every twice of interruption of TMR1. So, the interval is 100 milliseconds. In this processing, the data which controls the light of the lamp is set to TRIAC control memory (TRIACx). TRIAC is controlled by TMR0 interruption processing based on the set-up data. For the details of this processing, look at the following pattern processing.


pattern processing
;*********** Pattern process (100ms interval) ***********

Pattern processing is started every 100 milliseconds by the interruption processing of TMR1. In this processing, the control timing of the TRIAC is managed in five processes.

Process 0 ( Initialization )This process copies the pattern data to the execution management memory.
Process 1 ( Initial delay )The equipment this time can shift a blink's beginning time for the amusement of the lighting-up.
Process 2 ( Rising up )This process makes bright state from dim state.
Process 3 ( Bright )This process continues bright state.
Process 4 ( Falling down )This process makes dim state from bright state.
Process 5 ( Dim )This process continues dim state.

Structure of execution management memory
    10 bytes of memory is used for control timing processing of TRIAC. This memory exists for every TRIAC.
    The data used in each process are stored in 5 bytes (yellowish green) of high order of memory.
    5 bytes (yellow) of low rank is the management area under processing execution. An on-going process number is stored in a process number. The number of the following process is set up at the time of the end of each process. Moreover, the data required of next processing are set after the process counter. These area is used as a work area in each process.

Processing in each process
    Process 0 ( Initialization )
      The data corresponding to the pattern specified with a switch are copied to 5 bytes of high order of execution management memory as the original value.
      Also, at the ending processing, it sets initial delay data for process 1 to the processing counter.

    Process 1 ( Initial delay )
      In this process, decrease processing of the number of times specified by the processing counter is performed. Since processing intervals are 100 milliseconds, if set up with 5, it will become the waiting of 500 milliseconds.
      In end processing of process 1, data-preparation processing for process 2 is performed.
      The processing of rising up which is done in process 2 is complicated a little. The contents of processing change with the value to set up. Since brightness control is ten steps, processing changes by setting data. 20 or more or else less than 20.
      When a setup is 20 or more, the same TRIAC control value must be repeated. For example, when setting data is 40, each 20 stages are repeated twice. The number to repeat is set to the index counter.
      When the setting data is less than 20, some stages should be skiped. For example, when the setting data is 5, the stage is controlled every four. Like 4th stage -> 8th stage -> 12th stage -> 16th stage -> 20th stage. The number of the stages skipped is set to the sub index counter.
      A processing flag area is used for the indication of 20 or more or else less than 20. In case of 20 or more, the flag is set to 1 and in case of less than 20, the flag is set to 0.
      In case that the value of TRIAC control memory (TRIACx) is 20, it is dim. And in case of the value is 0, it is bright. So. In the processing which makes bright from dim, a decrease with the value of TRIAC control memory (TRIACx) is done.

    Process 2 ( Rising up )
      In process 2, the rising up processing is done based on the data of the flag, the index counter, and the sub index counter which are set by the end processing of process 1. When setting data is 20 or more, the enforcement situation of the number of times of a repetition is managed using a sub index counter. In this process, the value of TRIAC control memory (TRIACx) is decreased from 20 to 0.
      At the ending processing, bright time data for process 3 is set to the processing counter.

    Process 3 ( Bright )
      In this process, decrease processing of the number of times specified by the processing counter is performed. The bright data is already stored in TRIAC control memory (TRIACx) by process 2.
      At the ending processing, a flag, an index, a sub index are set like the ending processing of process 1. However, the setting contents are different. It's the processing to increase from 0.

    Process 4 ( Falling down )
      In process 4, the falling down processing is done based on the data of the flag, the index counter, and the sub index counter which are set by the end processing of process 3. In this process, the value of TRIAC control memory (TRIACx) is increased from 0 to 20.
      At the ending processing, dim time data for process 5 is set to the processing counter.

    Process 5 ( Dim )
      In this process, decrease processing of the number of times specified by the processing counter is performed.
      At the end processing, the same processing as end processing of a process 1 is performed. Utilizing end processing of a process 1 is also considered. However, I made the source code different from a process 1, in order to avoid the complicatedness of processing.
      The following process is set as 2. Therefore, it repeats like Process 2 -> process 3 -> process 4 -> process 5 -> process 2 -> ... after this.


User data
    You can change anything, if a source code is changed. Some parameters are made into data format and a change is made easy. They are frequency setting data and control pattern setting data.
Frequency setting data
;*** Frequency of AC power. 50Hz or 60Hz
    This data is the data which set up the frequency of the alternating voltage to be used. 50Hz or 60Hz can be chosen. It is considered that values other than 50 are 60Hz.
    In case of 50 Hz, the period of the half cycle is 10 milliseconds. It makes the time of TMR0 1 millisecond and interruption with 10 times is generated in the half cycle.
    In case of 60 Hz, the period of the half cycle is 8.33 milliseconds. It makes the time of TMR0 0.833 milliseconds and interruption with 10 times is generated in the half cycle.

Control pattern setting data
;*** Control Pattern.  Available 0 to 255 (unit=100ms)
    You can choose out of ten kinds of patterns beforehand set up by a switch with this equipment. Since it's considered as data format, this control pattern can be changed.
    The contents are the same as the yellowish green contents shown with the Structure of execution management memory.
    The unit of the data is 100 milliseconds.
    It is possible to set in a maximum of 255.
    As note point, in case of less than 20, make 0, 1, 2, 4, 5 or 10. Also, in case of equal to or more than 20, make 20 multiples.
    This is because the control number of stages of TRIAC is 20 steps. It's not effective even if you set up values other than the above. At the value except the above, the error doesn't occur. Since it is control of a lamp, it is not effective even if it carries out strict control.
    The example of a pattern 0 is shown below.
    ; Pattern 0
    p0_1    equ    d'10'            ;Start delay      (1sec)
    p0_2    equ    d'5'             ;Rising up      (0.5sec)
    p0_3    equ    d'5'             ;Bright         (0.5sec)
    p0_4    equ    d'5'             ;Falling down   (0.5sec)
    p0_5    equ    d'5'             ;Dim            (0.5sec)