1. 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.
    Dismiss Notice

PWM on a PIC

Discussion in 'Microcontrollers' started by AtomSoft, Apr 7, 2008.

  1. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Its for my surround sound not a TV... And The Command is 0x00 for the 1 button and the device code which i assume to be the address is 0x0D
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,205
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    Presumably this is a Sony SIRC's remote?, as you say the numeric button codes are one less than their labelled value.

    I've not seen a device ID of 0x0D, it wasn't amongst the remotes I tested, but is perfectly possible.
     
  3. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    maybe its my code tho .. you are right i think.. I have to work from 8am to 1 pm today thats like only 5 hours so its time to leave now. Ill try a tv code soon then when i get hom but i need to buy a universal (cheap like $3.99 in the 99Cent stores in NY lol. maybe $5 but heh its cheap and worth the cause :D Thanks so far for the help everyone!
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US

    This is my remote....
    http://esupport.sony.com/US/perl/model-home.pl?mdl=RMU304&LOC=3


    So how is the code standing as is? Do you think with the correct code it would possibly work?
     
  6. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
  7. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,008
    Likes:
    316
    Location:
    Brisbane Australia
    I have a remote for a Sony HiFi which sends device 13 (0x0d) when Tuner is selected. It also sends 18 for Amp and 17 for CD. The cursor keys always send 18 no matter what device is selected.

    Have you tried my Swordfish code (scroll down a bit) to read your remote?

    Mike.
     
  8. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    The output from the LA verifies that the code is good.

    The Sony info Bill linked to has the address of surround as 12 decimal. Give that a try...

    If not do as Mike suggested and listen to the current remote to see what it is sending. But I have not seen any bad info on the sony remotes.
     
  9. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Ok this is getting me mad :( this is my code:
    Code (text):

    // 37.7kHZ PWM IR carrier signal
    #include <p18f1320.h>
    #include <delays.h>
    #pragma config WDT = OFF,OSC = INTIO2,LVP = OFF

    void Delay10TCYx(PARAM_SCLASS unsigned char);
    void Delay100TCYx(PARAM_SCLASS unsigned char);
    void Delay1KTCYx(PARAM_SCLASS unsigned char);
    void Delay10KTCYx(PARAM_SCLASS unsigned char);
    void MyL0(void);
    void MyL1(void);

    void main(void) {    

        OSCCON=0x72; // speed up the clock to 8MHz
        ADCON1 = 0;
        TRISBbits.TRISB3 = 0;
        PR2 = 0b00110100 ;
        T2CON = 0b00000100 ;
        CCPR1L = 0b00011010 ;
        CCP1CON = 0b00011100 ;

        while(1) {
    ///////////////////////////////////////
    //////// Start Bit
    /////////////////////////////////////////
            CCPR1L = 0x1A; // Start
            CCP1CON = 0x1C ; // 50%
            Delay1KTCYx(4);
            Delay100TCYx(8);

            CCPR1L = 0x00; //Space
            CCP1CON = 0x0C ; // 0%
            Delay1KTCYx(1);
            Delay100TCYx(2);

    //////////////////////////////////////////
    ///////// Command Code
    ////////////////////////////////////////

            MyL0();
            MyL0();
            MyL1();
            MyL0();
            MyL0();
            MyL1();
            MyL0();

    ////////////////////////////////////////////
    ///////// Below is DEVICE CODE
    ///////////////////////////////////////////

            MyL1();
            MyL0();
            MyL0();
            MyL0();
            MyL0();

    //////////////////////////////////////////////
    //////// Just a wait to restart send /////////
    //////////////////////////////////////////////
            Delay1KTCYx(4);
         }    
    }
    void MyL0(void){
            CCPR1L = 0x1A; // 0
            CCP1CON = 0x1C ; // 50%
            Delay1KTCYx(1);
            Delay100TCYx(2);

            CCPR1L = 0x00; //Space
            CCP1CON = 0x0C ; // 0%
            Delay1KTCYx(1);
            Delay100TCYx(2);
    }
    void MyL1(void){
            CCPR1L = 0x1A; // 1
            CCP1CON = 0x1C ; // 50%
            Delay1KTCYx(2);
            Delay100TCYx(4);


            CCPR1L = 0x00; //Space
            CCP1CON = 0x0C ; // 0%
            Delay1KTCYx(1);
            Delay100TCYx(2);
    }
     
    To be sure what type of LED should i use..im trying :
    http://www.radioshack.com/product/i...origkw=infrared&kw=infrared&parentPage=search

    Im connecting the Long lead to RB3 and the short to GND. Is this correct?
     
  10. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,008
    Likes:
    316
    Location:
    Brisbane Australia
    The space is always 0.6mS so you should be sending a 2.4mS on pulse followed by a 0.6mS off pulse as the start bit and then, a one bit is 1.2mS on + 0.6mS off, a zero is 0.6 on + 0.6 off. Your timing seems to be double this. EDIT, just realised your delays are in clock cycles so ignore this.

    Here is a good page explaining it.

    Is it also your intention to send device code 1 and command 36?

    Mike.
     
    Last edited: Apr 8, 2008
  11. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    actually no the device is 1 but the command is more like 18

    MyL0();
    MyL1();
    MyL0();
    MyL0();
    MyL1();
    MyL0();
    MyL0();

    is actual i tried it in reverse to see lol
     
  12. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Here is a closer look at my signal does it look ok? like does it look normal?

    [​IMG]

    [​IMG]
     
    Last edited: Apr 8, 2008
  13. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,008
    Likes:
    316
    Location:
    Brisbane Australia
    Yes, that looks like a start bit followed by 010.

    Mike.
     
  14. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
  15. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Do you have a video camera? Most of them see IR and will let you see it too. Might be handy.
     
  16. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,008
    Likes:
    316
    Location:
    Brisbane Australia
    What value have you got for the emitter resistor. It should be about 14Ω for an LED current of 50mA or 35Ω for 20mA.

    You will get better results with a lower duty cycle and higher current.

    Mike.
     
    Last edited: Apr 8, 2008
  17. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Never thought about that, how much lower?
     
  18. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,008
    Likes:
    316
    Location:
    Brisbane Australia
    It depends on the peak current of the diode. If the peak is 4 times the average then 25% would be a good place to start.

    Mike.
     
  19. BaCaRdi

    BaCaRdi Member

    Joined:
    Apr 7, 2008
    Messages:
    233
    Likes:
    2
    Location:
    Hoboken / NYC
    Just two add my 2cents, you don't need a video camera, you can use any digital camera in preview mode, even your cellphone!

    I think they all have a preview mode to see on the lcd what the CCD is looking at, that will see the IR without a video camera or taking a picture:)

    -Bac
     
  20. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Im using a end delay of 10,000 cycles which is 50 ms... 45ms is recommended in between sends so i added 5 for cleanliness.

    I used the cam to see if LED is on and it looks solid..like its doesnt blink but i assume thats because its so fast. Its shows like a slight dim and back on
     
  21. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,205
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    It should blink, VERY clearly - if it's not then you're not modulating it properly (or at all).
     

Share This Page