Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sony Infared Code in C18

Status
Not open for further replies.
Im not a timer or PWM guy lol or hardware ... lol thats why most of the things i do is software. :D i know i need to learn to use the hardware stuff.

Hey guys im doing another project but am LOST! lol i need info on how to use a triac without blowing up :D

I have a Q6008RH4 which i have the datasheet but no good info on it. I would love to use this with my IR project so i can use my remote to turn on and off the light. Also the volume to control brightness :D
 
real easy way to fix is open the file "*.mcp" in a text editor and edit it to c:\

Download the fixed files below. Sorry again :)
 

Attachments

  • 1320_CDRIVE.zip
    35.3 KB · Views: 152
Last edited:
I dont really want to start a new thread lol
Would this work? Remember look at the labels i couldnt find the parts in EAGLE for a LIGHT BULB lol or 125V mains... so bare with me lol

triac-png.29805
 

Attachments

  • TRIAC.png
    TRIAC.png
    2.8 KB · Views: 389
Just get a logic level TRIAC and it easy to flash a light bulb I posted on there how about eight weeks ago This is what I use
Fagor
TRIAC, Logic Level; TO-220AB; 8 A; 600 V; 8 A @ 95 degC; 1.6 V (Max.); 1.6 degC
Mfr's Part#: FT0816MH you can turn it on from the pick I use a transistor just because
I can't see hooking a pic to one chip that has 120 volts running in it This is ac bulbs bing flashed with a pic and triac
[embed]http://www.youtube.com/v/gebVAw49TPs&hl=en&fs=1[/embed]
 

Attachments

  • dimmer.PNG
    dimmer.PNG
    13.1 KB · Views: 199
Last edited:
What was that little hicup there at 2 seconds? With something like that you should probably put a zero cross detector in then you can dim the light by adjust the phase angle you turn it on at. You can use the protection diodes built into most MCU's and a large resistor to feed main AC directly into an I/O line for checking zero cross.
 
Yes you can put a 1mohm resistor and check zero crossing
What was that little hicup there at 2 seconds
i had turned the cam off and hit the button and started it back up. Blinking wasn't what i was trying for but it easy to do. I had put to big
of resistor on the gate it takes 10 to a max of 20 ma to turn the triac full on I had a used
a 1k resistor on the gate which made it blink.
 
heh i dont trust bread boarding this kinda stuff. I have proteus on cd around here gota look through draws but will it simulate AC and stuff like this?

I might just use a RELAY and a TIP31A(G) for switching my light on and off. Im sure i can make the board nice and small to fit inside the switch box in the wall. Of course ill protect the back of board since its all metal.

I might get a little plastic radioshack box and cut it to place inside. Then ima make my remote on a bread board with about 4-8 buttons to send out different signals so i can turn on upto 8 devices in my room with my remote. I might use it for ....

1. Light Bulb
2. PC Monitor
3. Air Conditioner (ill tie it to the power button since its digital i lost my remote lol)

I know not to use it on something over 1A since the relay i have only handles 120VAC/1A
 
That's why if you look in the video you see a transformer I lowered the Ac line down to what a bread board can take
 
Trying to port my sony code to a PIC12F629 using BoostC everything compiles ok but nothing is working lol

Code:
#pragma CLOCK_FREQ 4000000

#include <system.h>
#include <PIC12F629.h>

#pragma DATA _CONFIG, _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT 

unsigned char lTime;

unsigned char MyAdd;
unsigned char MyCmd;

#define irPin gpio, 5


void main(void);
void GetSIRC(unsigned char *address, unsigned char *command);

void main(void){
    char tmp;
    cmcon = 0x00;
    option_reg = 0x00;

    gpio = 0b00010000;


    while(1){
        GetSIRC(&MyAdd,&MyCmd);
        if(MyCmd == 0x01){
            set_bit(gpio, 4);
        } else {
            clear_bit(gpio, 4);
        }
    }
}

void GetSIRC(unsigned char *address, unsigned char *command){
    unsigned char ir_add;
    unsigned char ir_cmd;
    char x;

StartLook:
    ir_add = ir_cmd = 0;

    while(irPin);               //wait for it to be low
    lTime = 0;                  //reset the counter

    while(irPin == 0){          //while the pin is low which is our pulse count
        lTime++;                //increment every 200uS until pin is high
        delay_100us(2);         //200uS delay
    }

    if(lTime <= 10)             //Start too short
        goto StartLook;         //Restart
    if(lTime >= 14)             //Start too long
        goto StartLook;         //Restart
			
    lTime = 0;
    for(x=0;x<7;x++){           //repeat 7 times for command
        ir_cmd >>= 1;           //if it was skipped or is done ORing then shift over the 1

        while(irPin);           //wait for it to be low
        lTime = 0;              //reset the counter

        while(irPin == 0){      //while the pin is low which is our pulse count
            lTime++;            //increment every 200uS until pin is high
            delay_100us(2);     //200uS delay
        }

        if(lTime >= 6)          //If its high then OR a 1 in else skip
            ir_cmd |= 0x40;     //if its less than 6 its a 0 so dont OR it		
								
    }
    for(x=0;x<5;x++){           //repeat 5 times for address/device
        ir_add >>= 1;           //if it was skipped or is done ORing then shift over the 1

        while(irPin);           //wait for it to be low
        lTime = 0;              //reset the counter

        while(irPin == 0){      //while the pin is low which is our pulse count
            lTime++;            //increment every 200uS until pin is high
            delay_100us(2);     //200uS delay
        }

        if(lTime >= 6)          //If its high then OR a 1 in else skip
            ir_add |= 0x10;     //if its less than 6 its a 0 so dont OR it			
    }

    *address = ir_add;
    *command = ir_cmd;
}
 
YAY! it works now.... heh its for a 12F629. Now ima use it since its cheaper than a 18F :D

$1 each and 10 for $8-$9 at dipMicro so ima order a bunch. Maybe SOIC. And connect my relay and transistor , and ir stuff so i can now turn off my light with a remote. Ill post schematics and full code and picture and video lol when done maybe tomorrow afternoon.
Code:
/* **************************************************************************
;																			*
;	Filename: SIRC															*
;	Date: May 29, 2009														*
;	File Version: 001														*
;																			*
;	Author:   Jason Lopez													*
;	Company:  AtomSoft														*
;																			*
;****************************************************************************
; Notes:
; I am delaying in this code a nice even number every 200uS. Mainly because if
; i count each pulse it would be accurate but too many counts for a char type
; and i dont want to use a int. So i can get a 600 count by skipping every 300uS
; and the count will be a nice low number...3
; 
; For a 1.2mS aka HIGH i should get a count of 6 and for the start 2.4mS i should
; get a count of 12. Since this isnt too accurate i range it about 1-2 numbers 
; above or below the standard.
; 
;****************************************************************************
*/
#pragma CLOCK_FREQ 4000000

#include <system.h>
#include <PIC12F629.h>

#pragma DATA _CONFIG, _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT 

unsigned char lTime;

unsigned char MyAdd;
unsigned char MyCmd;

#define irPin gpio.GP5

void main(void);
void GetSIRC(unsigned char *address, unsigned char *command);

void main(void){
    char tmp;

    cmcon = 7;                        // comparator off, digital I/O
    trisio = 0b00100000;              // GP0 output, GP1 input
    gpio = 0;                         // make all outputs '0'
    //option_reg.NOT_GPPU = 0;          // enable weak pull-ups

    while(1){
        GetSIRC(&MyAdd,&MyCmd);
        if(MyCmd == 0x01){
            set_bit(gpio, 4);
        } else {
            clear_bit(gpio, 4);
        }
    }
}

void GetSIRC(unsigned char *address, unsigned char *command){
    unsigned char ir_add;
    unsigned char ir_cmd;
    char x;

StartLook:
    ir_add = ir_cmd = 0;

    while(irPin);               //wait for it to be low
    lTime = 0;                  //reset the counter

    while(irPin == 0){          //while the pin is low which is our pulse count
        lTime++;                //increment every 200uS until pin is high
        delay_100us(2);         //200uS delay
    }

    if(lTime <= 10)             //Start too short
        goto StartLook;         //Restart
    if(lTime >= 14)             //Start too long
        goto StartLook;         //Restart
			
    lTime = 0;
    for(x=0;x<7;x++){           //repeat 7 times for command
        ir_cmd >>= 1;           //if it was skipped or is done ORing then shift over the 1

        while(irPin);           //wait for it to be low
        lTime = 0;              //reset the counter

        while(irPin == 0){      //while the pin is low which is our pulse count
            lTime++;            //increment every 200uS until pin is high
            delay_100us(2);     //200uS delay
        }

        if(lTime >= 6)          //If its high then OR a 1 in else skip
            ir_cmd |= 0x40;     //if its less than 6 its a 0 so dont OR it		
								
    }
    for(x=0;x<5;x++){           //repeat 5 times for address/device
        ir_add >>= 1;           //if it was skipped or is done ORing then shift over the 1

        while(irPin);           //wait for it to be low
        lTime = 0;              //reset the counter

        while(irPin == 0){      //while the pin is low which is our pulse count
            lTime++;            //increment every 200uS until pin is high
            delay_100us(2);     //200uS delay
        }

        if(lTime >= 6)          //If its high then OR a 1 in else skip
            ir_add |= 0x10;     //if its less than 6 its a 0 so dont OR it			
    }

    *address = ir_add;
    *command = ir_cmd;
}
 
Last edited:
I read it and posted when it reloaded I was like wasn't that a 0 there you done fixed it. That code
should work easy with a 12f683 just mostly change osc setting you can set osc to 4mhz up to 8 I think
I looked you can so it would be a good chip to use to I have about 20 of them Good work Atom
But would the delays work if set to 8mhz your letting the software make it based on clock right ?
 
Last edited:
since im using BoostC on the 12F629 it does the delays auto.. i just use the Delay100us function and it calculates it all for me.

It works well! No issues and i tried it wit relay and its OK!
 
One of the reasons I like BoostC is the fact that it works on these little chips and it's free.

Mike.
 
I just run Atoms code on a 12f683 I have to say I like BoostC far better then C18. Just
set the chip and it finds what it needs. C18 you almost have to hold it's hand.
fits on one of these boards: 69 x 50mm
Them boards look good I use some like that going to look in to getting me some of them
 
Last edited:
yeah there nice. I finally found a use for them. I have the set with the: SnapTrack Channel.

Its nice since i can screw straight to the wall if need be.
 
Ok here is the new code i use to control this PIC12F629. It can learn SIRC codes and control a relay which can be anything you want up to 1A MAX!
To Send the device into LEARNING MODE you have to:
1.TURN OFF
2.TURN ON WHILE HOLDING PROGRAM BUTTON DOWN.

The PROG. LED will light and then you press a button on remote and the PROG. LED will blink a few times confirming its done saving.

Ill post the schematic when i make it aka like 15 minutes..
Code:
/* **************************************************************************
;																			*
;	Filename: SIRC															*
;	Date: May 29, 2009														*
;	File Version: 001														*
;																			*
;	Author:   Jason Lopez													*
;	Company:  AtomSoft														*
;																			*
;****************************************************************************
; Notes:
; I am delaying in this code a nice even number every 200uS. Mainly because if
; i count each pulse it would be accurate but too many counts for a char type
; and i dont want to use a int. So i can get a 600 count by skipping every 300uS
; and the count will be a nice low number...3
; 
; For a 1.2mS aka HIGH i should get a count of 6 and for the start 2.4mS i should
; get a count of 12. Since this isnt too accurate i range it about 1-2 numbers 
; above or below the standard.
; 
;****************************************************************************
*/
#pragma CLOCK_FREQ 4000000

#include <system.h>
#include <PIC12F629.h>

#pragma DATA _CONFIG, _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT 

unsigned char lTime;

unsigned char MyAdd;
unsigned char MyCmd;

unsigned char MainAdd;
unsigned char MainCmd;

#define irPin gpio.GP5
#define RecordIt gpio.GP2

#define RelayPin gpio.4
#define progStat gpio.1

void main(void);
void GetSIRC(unsigned char *address, unsigned char *command);
char WriteEE(char address, char data);
char ReadEE(char address);

char ReadEE(char address){
    eeadr = address;
    eecon1.RD = 1;
    return eedata;       
}
char WriteEE(char address, char data){
    char tmp;
    eeadr = address;
    eedata = data;
    eecon1.WREN = 1;
    eecon2 = 0x55;
    eecon2 = 0xAA;
    eecon1.WR = 1;
    while(!pir1.EEIF);
    pir1.EEIF = 0;

    tmp = ReadEE(address);

    if(tmp == data)
        return 0;
    else
        return 1; //ERROR
}

void main(void){
    char tmp;
    char IsSet = 0;

    cmcon = 7;                        // comparator off, digital I/O
    trisio = 0b00100100;              // GP0 output, GP1 input
    gpio = 0;                         // make all outputs '0'

    delay_ms(250);
    if(RecordIt == 0){
        progStat = 1;
        GetSIRC(&MyAdd,&MyCmd);

        if(WriteEE(0x00,MyAdd))
            goto MainApp;
        if(WriteEE(0x01,MyCmd))
            goto MainApp;
       
        progStat = 0;
        delay_ms(250);
        progStat = 1;                                                
        delay_ms(250);
        progStat = 0;
        delay_ms(250);
        progStat = 1;
        delay_ms(250);
        progStat = 0;
        delay_ms(250);
    }
MainApp:
    MainAdd = ReadEE(0x00);
    MainCmd = ReadEE(0x01);

    while(1){
        GetSIRC(&MyAdd,&MyCmd);

        if(MyAdd == 0x01)
            if(MyCmd == 0x00){
                if(IsSet == 0){
                    RelayPin = 1;
                    IsSet = 1;
                } else {
                    RelayPin = 0;
                    IsSet = 0;
                }
            }

        delay_ms(250);
        delay_ms(250);
    }
}

void GetSIRC(unsigned char *address, unsigned char *command){
    unsigned char ir_add;
    unsigned char ir_cmd;
    char x;

StartLook:
    ir_add = ir_cmd = 0;

    while(irPin);               //wait for it to be low
    lTime = 0;                  //reset the counter

    while(irPin == 0){          //while the pin is low which is our pulse count
        lTime++;                //increment every 200uS until pin is high
        delay_100us(2);         //200uS delay
    }

    if(lTime <= 10)             //Start too short
        goto StartLook;         //Restart
    if(lTime >= 14)             //Start too long
        goto StartLook;         //Restart
			
    lTime = 0;
    for(x=0;x<7;x++){           //repeat 7 times for command
        ir_cmd >>= 1;           //if it was skipped or is done ORing then shift over the 1

        while(irPin);           //wait for it to be low
        lTime = 0;              //reset the counter

        while(irPin == 0){      //while the pin is low which is our pulse count
            lTime++;            //increment every 200uS until pin is high
            delay_100us(2);     //200uS delay
        }

        if(lTime >= 6)          //If its high then OR a 1 in else skip
            ir_cmd |= 0x40;     //if its less than 6 its a 0 so dont OR it		
								
    }
    for(x=0;x<5;x++){           //repeat 5 times for address/device
        ir_add >>= 1;           //if it was skipped or is done ORing then shift over the 1

        while(irPin);           //wait for it to be low
        lTime = 0;              //reset the counter

        while(irPin == 0){      //while the pin is low which is our pulse count
            lTime++;            //increment every 200uS until pin is high
            delay_100us(2);     //200uS delay
        }

        if(lTime >= 6)          //If its high then OR a 1 in else skip
            ir_add |= 0x10;     //if its less than 6 its a 0 so dont OR it			
    }

    *address = ir_add;
    *command = ir_cmd;
}
Video of it in action:
[embed]http://www.youtube.com/v/DUfHTRLBCNQ[/embed]
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top