CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Triac MOC3021 Driver

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mr.Cricket



Joined: 20 Jan 2013
Posts: 2

View user's profile Send private message

Triac MOC3021 Driver
PostPosted: Sun Jan 20, 2013 11:06 am     Reply with quote

Hi
I found this code on internet.
http://cboard.cprogramming.com/c-programming/136682-help-me-pls-thank-you.html
This is to control the speed of fan and intensity of light but the driver for triac moc3021 are missing. So I need drivers for moc 3021 one for fan and other for bulb.
The code is:
Code:

# include<16f72.h>
# use delay (clock=12000000)
# fuses hs, nowdt, protect
# use i2c(master, sda=PIN_c4, scl=PIN_c3)

# include <lcdb.c>

int temph , templ ;
int1 x=0 , y=0 ;
int m ;

# define zcd PIN_a4
# define pir PIN_B0
# define ldr PIN_a2
# define dim1 PIN_a0
# define dim2 PIN_a1

# include <temperature.c>
# include <dimmer1.c>
# include <dimmer2.c>

#INT_EXT Void main( )
{
Output_low(dim1) ;
Output_low(dim2) ;
X=0; Y=0;
Setup_adc_ports( NO_ANALOGS ) ;// All are digital only
temp_intit( ) ;
lcd_intit( ) ;
LCD_PUTC(“\f POWER SAVER”) ;

delay_ms(2000) ;

While(1)
{
If (! input(pir) )
  {
   output_high(dim1) ;
   While(! input(pir) ){}
   X=~x ;
   LCD_PUTC(“\n PIR ON “) ;
   Delay_ms(5000) ;
  }
if(x == 0)
  {
   If(y == 1)
     {
      delay_ms(20000) ;
      Y=0 ;
     }
   output_low(dim1) ;
   output_low(dim2);
   LCD_PUTC(“\n STAND BY “) ;
   delay_ms (300);
  }

if(x==1)
{
y=1;
temp_read ( );
if (templ==0x80) templ=5;
else templ=0;
printf(lcd_putc, ”\nTEMP: %02d.%d dc”, temph,templ) ;
if(temph>=27 && temph<=28 )
{
back25: if( ! input(zcd))goto back25; //waiting to get zero start
delay_ms(5);
output_high(dim2);
back26: if( ! input(zcd))goto back26; //waiting to get zero start
output_low(dim2);
delay_ms(5);
output_high(dim2);
back27: if( ! input(zcd))goto back27;
output_low(dim2);
}

if (temph>=29 && temph<=31 )
{
back20: if( ! input(zcd))goto back20; //waiting to get zero start
delay_ms(5); / / 161
output_high(dim2);
back30: if( ! input(zcd))goto back30; //waiting to get zero start
output_low(dim2);
delay_ms(5);
output_high(dim2);
back32: if( ! input(zcd))goto back32;
output_low(dim2);
}
if (temph>31 && temph<=33 )
{
back9: if( ! input(zcd))goto back9; //waiting to get zero start
delay_ms(5); // 161
output_high(dim2);
back10: if( ! input(zcd))goto back10; //waiting to get zero start
output_low(dim2);
delay_ms(5);
output_high(dim2);
back11: if( ! input(zcd))goto back11;

output_low(dim2);
}

if (temph>33 && temph<=35 )
{
back12: if( ! input(zcd))goto back12; //waiting to get zero start
delay_ms(3); / / 161
output_high(dim2);
back13: if( ! input(zcd))goto back10; //waiting to get zero start
output_low(dim2);
delay_ms(3);
output_high(dim2);
back14: if( ! input(zcd))goto back14;
output_low(dim2);
}
if (temph>35 && temph<=37 )
{
back15: if( ! input(zcd))goto back15;  //waiting to get zero start
delay_ms(2);
output_high(dim2);
back16: if( ! input(zcd))goto back16;  //waiting to get zero start
output_low(dim2);
delay_ms(2);
output_high(dim2);
back17: if( ! input(zcd))goto back17;
output_low(dim2);
}
if (temph>37) output_high(dim2) ;
if (input(ldr)) output_high(dim1) ;
if (! Input(ldr)) output_low(dim1) ;
}
}
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jan 21, 2013 4:04 am     Reply with quote

Please get real! Rolling Eyes
Did you even read the comments in the thread you linked to?
The code you posted is incomplete, not working and from another beginner in software who used a lot of bad habits (goto statements, to name one).

If you want to learn programming then start with the most basic project first: get a LED to blink.
Read the PIC datasheet
Read the CCS manual
Expand your LED blinking program in small steps that can all be tested:
- write to the LCD
- read temperature and display on LCD
- Add motor control
- Control motor speed based on temperature.

For each of these steps you can find example programs on this website and in the Application Notes on the Microchip website. Do one step at a time and only go to the next step when you have everything working.
Mr.Cricket



Joined: 20 Jan 2013
Posts: 2

View user's profile Send private message

PostPosted: Mon Jan 21, 2013 6:18 am     Reply with quote

I have already starting learning programming.
But i m using triac as a dimmer and i need driver file for this i searched on google but didn't find one
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Jan 21, 2013 6:34 am     Reply with quote

What would you expect a "driver" for a Triac to do? I don't think there is a driver.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Jan 21, 2013 8:51 am     Reply with quote

The PIC needs code to make it work and a PC needs code as well. For PC coding little attention is made to hardware due to the driver layer provided by the PC manufacturer, the OS and the manufacturers of add on devices. The PIC is different it is very close to hardware so learning very much involves hardware. Take the need to control a triac. Learning is best done by building a simple circuit only involving a triac being switched on and off. Now you know what the pic will need to do. Assuming you learned with a PIC how to turn a simple led on or off the path ahead should now seem clear.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Mon Jan 21, 2013 9:08 am     Reply with quote

Worth pointing out, that a TRIAC is just an on/off device. A pulse to the gate turns it on, and it then goes off at the next mains crossing, provided the gate is no longer driven. You can't turn it off (except for more exotic GTO devices). The way you 'dim', is by adjusting when you turn it on. Basically you need hardware to detect the zero crossing point on the mains cycle, and then all you do is adjust how long 'after' this, you send a pulse to the TRIAC to turn it on. Turn it on immediately after the zero crossing, and you have 'full power' leave turning it on till late in the mains cycle and you have a low power output.
Driving it is just down to adjusting the time. However you need the hardware to detect the mains cycle, to make it work.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group