Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/22/09 13:09
Modified:
  11/22/09 13:11

Read: times


 
#171028 - Intensity control
Hello Dear Programmers,

I am trying to make a program that will control the intensity of a standard 40 watt bulb by duty cycle control.

Basically the sinusoidal that i have is 50Hz ie of 0.02 sec time period. Now the wave touches the origin line twice in this time. I have used a circuit to determine the origin of the AC waveform(sinusoidal) that i have. From this circuit i will get a trigger wave at the origin(ie where the sinusoidal wave touches the origin line). According to my calculation i will have a trigger every 0.01 sec. Now i have fed this pulse to external interrupt 0 of the micontroller.

I have used the timer interupt 0 in 16 bit mode. Now according to my calculation, in 0.01 sec the counter counts from 0000h to 2400h. Now the furthur the output is switched on from the input trigger the lower the intensity. i.e. in i switch on the bulb at 0000h then the intensity is maximum and if i switch it on after 1200h the intensity is half and if at 2400h the intensity is least.

On the pin P1.2, i have connected a triac circuit that will trigger the output.

I have switched ON-OFF the bulb without the use of interrupts and it is working but when i use the interrupt then it is not working.

#include <reg51.h>
#include <generic.h>

sbit GREEN = P3^6;
sbit YELLOW = P3^7;
sbit output_ = P1^2;
bit START = 0;
bit STOP = 1; 
/*=============================================================================
SET FREQUENCY : 50Hz

Each half of the AC cycle lasts 0.01 sec. and the timer counts 0000h to FFFFh in this time.
We will control this time and switch on and off pin 1.0 that is the output.
We will take the ext int 0 negetive edgs as the start point.
/*=============================================================================*/
unsigned char set_point_L = 0x00,set_point_H = 0x00;
/*=============================================================================*/
/*=============================================================================*/
void ex0_isr (void) interrupt 0
{
output_ = STOP;			//stop trigger
TR0 = 0;			//Stop timmer
TL0 = 0x00;			//Loading the initial value, lower Byte - thus reseting timmer
TH0 = 0x00;			//Loading the initial value, Higher Byte - thus reseting timmer
TR0 = 1;			//start timmer
}
/*=============================================================================*/
void timer0_ISR (void) interrupt 2
{
if(set_point_L == TL0 && set_point_H == TH0)
	output_ = START;				//start trigger
}
/*=============================================================================*/
void initialize_global_interupt(void)
{
IE = 0x9B;							//10011011 global enable, ext int 0 ,timer int 0 and timmer int 1 (for baud rate) enabled
}
/*=============================================================================*/
void initialize_timer_0(void)
{
TR0 = 0;
TMOD = 0x21;  			//00100001Set Mode(16-bit timer with reload)
TL0 = 0x00;			//Loading the initial value, lower Byte
TH0 = 0x00;			//Loading the initial value, Higher Byte
TR0 = 1;			//Starting the timmer internally so that it can be accessed externally
}
/*=============================================================================*/
void initialize_external_int_0(void)
{
IT0 = 1;						//making the external interupt edge trigerred
}
/*=============================================================================*/
void main (void)
{
initialize_timer_0();
initialize_external_int_0();
initialize_global_interupt();
while(1)
  {
	set_point_L = 0x00;
	set_point_H = 0x24;
	sec_wait(1);
	
	set_point_L = 0x28;
	set_point_H = 0x23;
	sec_wait(1);

	set_point_L = 0x58;
	set_point_H = 0x1B;
	sec_wait(1);

	set_point_L = 0x88;
	set_point_H = 0x13;
	sec_wait(1);

	set_point_L = 0xB8;
	set_point_H = 0x0B;
	sec_wait(1);

	set_point_L = 0xE8;
	set_point_H = 0x03;
	sec_wait(1);

	set_point_L = 0xF4;
	set_point_H = 0x01;
	sec_wait(1);


	set_point_L = 0x64;
	set_point_H = 0x00;
	sec_wait(1);

	set_point_L = 0xF4;
	set_point_H = 0x01;
	sec_wait(1);

	set_point_L = 0xE8;
	set_point_H = 0x03;
	sec_wait(1);

	set_point_L = 0xB8;
	set_point_H = 0x0B;
	sec_wait(1);

	set_point_L = 0x88;
	set_point_H = 0x13;
	sec_wait(1);

	set_point_L = 0x58;
	set_point_H = 0x1B;
	sec_wait(1);

	set_point_L = 0x28;
	set_point_H = 0x23;
	sec_wait(1);

	set_point_L = 0x00;
	set_point_H = 0x24;
	sec_wait(1);
  }
}
/*====================================*/

 


List of 15 messages in thread
TopicAuthorDate
Intensity control            01/01/70 00:00      
   show some CODE            01/01/70 00:00      
      Dear Erik            01/01/70 00:00      
         where are the comments?            01/01/70 00:00      
         We can't read your mind            01/01/70 00:00      
            Erik & Richard            01/01/70 00:00      
               What prevents you from putting in the required comments?            01/01/70 00:00      
               While putting in comments i saw one error            01/01/70 00:00      
   Hmmmm...            01/01/70 00:00      
      Jitter            01/01/70 00:00      
         still no luck            01/01/70 00:00      
            We have not seen the schematics            01/01/70 00:00      
               Its working            01/01/70 00:00      
   Another Program to test my interrupt !!            01/01/70 00:00      
   Code legibility            01/01/70 00:00      

Back to Subject List