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. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,018
    Likes:
    317
    Location:
    Brisbane Australia
    ONLINE
    If it helps, here is the C18 code to read a Sony remote. If you can program it on a stand alone chip you might be able to work out whats wrong.

    Mike.
    Code (text):

    #define IR_in   PORTAbits.RA6       //define as needed
    #define IR_tris TRISAbits.TRISA6

    unsigned char GetPulse(void){
    unsigned char count;
        count=0;
        IR_tris=1;
        while(IR_in==1);            //wait for high
        while(IR_in==0){            //time low period
            count++;
            Delay100TCYx(1);        //50uS assumes 8MHz
        }
        return count;
    }

    void GetIR(char *cmd,char *dev){
    char i;
        *cmd=0;
        *dev=0;
        while(GetPulse()<40);       //wait for start pulse
        for(i=0;i<7;i++){
            *cmd=*cmd>>1;
            if(GetPulse()>18)
                *cmd|=0x40;
        }
        for(i=0;i<5;i++){
            *dev=*dev>>1;
            if(GetPulse()>18)
                *dev|=0x10;
        }
    }

    //you would call it by doing,

    char command,device;
        GetIR(&command,&device);      //note pointers passed

    //command and device are now valid.
     
    P.S. have you looked at an actual remote through the camera for comparison.
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,218
    Likes:
    641
    Location:
    Derbyshire, UK
    You normally pulse IR diodes in remote controls at between 1 and 2 amps! - notice that there's a LOT of time spent outputting nothing in the datastream, this allows the diode not to overheat or fail.

    Generally the mark/space ratio of the 38KHz itself is 50/50 - I've played with different ratios, and it seems to make very little difference.
     
  3. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I think what Pommie was trying to say is a narrow pulse would keep the LED average current lower while allowing a higher peak current. All is well and good but the LED may not like single stepping via a debugger. I also though IR LEDs were closer to 100ma max pulsed.
     
  4. dave

    Dave New Member

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


     
  5. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA

    AtomSoft,

    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) {    

      [B]  OSCCON=0x72;[/B] // speed up the clock to 8MHz

    Code (text):

    bit 6-4 IRCF2:IRCF0: Internal Oscillator Frequency Select bits

    111 = 8 MHz (8 MHz source drives clock directly)
    110 = 4 MHz
    101 = 2 MHz
    100 = 1 MHz
    011 = 500 kHz
    010 = 250 kHz
    001 = 125 kHz
    000 = 31 kHz (INTRC source drives clock directly)

    If the people gave you PWM setups for a 8MHz clock you need to change your ckock freq from 4 to 8MHz. I would check but I am running behind.
     
  6. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    It blinks because one cannot see the individual On/OFF of the 38KHz carrier wave cycle but eye can detect the period between "carrier present" and "no carrier".

    Changing the mark/space ratio of 38KHz allows one to use still higher pulse current to the IR emitter.
     
  7. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,018
    Likes:
    317
    Location:
    Brisbane Australia
    ONLINE
    OSCCON=0x72 does give 8MHz. Even if you have the config set to HS and a 20MHz crystal attached.

    Mike.
     
  8. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    My bad. very :eek:

    :) May be a good day to stay in bed :)

    EDIT:

    I would go to radio shack and get an IR detector and see if it can detect the modulated IR. If that works it has to be the data.
     
    Last edited: Apr 9, 2008
  9. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    ok this sucks! lol i can always make my own protocol right?

    I wanted to use sony's because i have code to read sonys already but i guess ill have to remake everything which shouldnt be that hard if i make my own code just change some variables around and stuff..

    So is it possible to make a custom protocol?

    Like

    Start Bit = 4ms
    Space = 1ms
    Logic High = 3ms
    Logic Low = 2ms


    Something like that.... but about 16bit instead of sony 12bit
     
    Last edited: Apr 9, 2008
  10. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Im trying to finish this and understand it quick because i got my LCD and want to start on that soon :D
     
  11. AtomSoft

    AtomSoft Well-Known Member

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

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,218
    Likes:
    641
    Location:
    Derbyshire, UK
    Yes, but what's wrong with using Sony's?.

    Check my tutorials, Sony have three different word lengths, with 12 being the shortest.

    Nothing wrong with using the Sony SIRC's system, it's simple and easy, just allocate your own device ID for an interference free system.
     
  13. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I'm missing something, why would you have to make your own protocol? 8MHz is uber fast for an IR transmission. Especially if it's done with the PWM.

    Here's a suggestion, here's the unmodified TX source from
    http://www.sixca.com/eng/articles/remote/index.html
    It shouldn't be difficult to make it work on the Junebugs 18F1320 (the code will get smaller) It's only 4MHz and doesn't even use the PWM module. I've got to run but I'll take a look this afternoon to get it running on the Junebug.

    Code (text):
    ;------------------------------------------------------
    ; PROJECT : 3 CHANNEL TX IR REMOTE
    ; CRYSTAL 4 MHz
    ; MPLAB : 7.11 , Assembly
    ; RC5 FORMAT @38KHz , 35% DUTY CYCLE
    ; ADDRESS = 0X0B  0000 1011 you may change
    ; CH1  = 0X01
    ; CH2  = 0X02
    ; CH3  = 0X03
    ; NOT USE TOGGLE ALWAY = 0
    ; WWW.SIXCA.COM
    ; 4-JULY 2005
    ;
    ; FREE TO USE FOR PERSONAL OR EVEN COMERCIAL PRODUCT
    ;------------------------------------------------------

        list P=12F629
        #include <P12F629.INC>
        __config _WDT_OFF & _XT_OSC & _CP_ON & _CPD_ON & _BODEN_OFF & _MCLRE_OFF & _PWRTE_ON


    #DEFINE CH1    GPIO,0    ; CONNECT WITH TX SWITCH CHANNEL 1
    #DEFINE CH2    GPIO,1    ; CONNECT WITH TX SWITCH CHANNEL 2
    #DEFINE CH3    GPIO,3    ; CONNECT WITH TX SWITCH CHANNEL 3
    #DEFINE IR    GPIO,2    ; CONNECT WITH IR LED WITH TRANSISTOR DRIVES
    #DEFINE TOG_BIT TOGGLE,0 ; TOGLE BIT NOT USE FOR THIS PROJECT    
    #DEFINE CH1_CMD    0X01    ; CHANNEL 1 COMMAND
    #DEFINE CH2_CMD    0X02    ; CHANNEL 2 COMMAND
    #DEFINE CH3_CMD    0X03    ; CHANNEL 3 COMMAND


    CNT1    EQU    20H
    CNT2    EQU    21H
    CNT3    EQU    22H
    CNT4    EQU    23H
    TOGGLE    EQU    24H
    CMD    EQU    25H    ; IR COMMAND BUFFER

        ORG    000
       
        BCF    IR
        ;BSF    STATUS,RP0
        ;CALL    0X3FF
        ;MOVWF    OSCCAL
        ;BCF    STATUS,RP0
        CALL    DEBOUNCE
        ;
        MOVLW    0X07
        MOVWF    CMCON    ; MAKE ALL GPIO TO DIGITAL I/O
        BSF    STATUS,RP0
        BCF    OPTION_REG,7    ; ENABLE WEAK PULL-UP
        BCF    WPU,2        ; DISABLE WEAK PULL-UP FOR GPIO2
        MOVLW    B'00001011'    ; GPIO<0,1,3> = INPUT , GPIO 2 = OUTPUT
        MOVWF    TRISIO
        BSF    IOCB,IOCB0
        BSF    IOCB,IOCB1
        BSF    IOCB,IOCB3
        BSF    INTCON,GPIE
        BCF    STATUS,RP0    
        BCF    INTCON,GIE    
        BCF    TOG_BIT
       
    ;------------------------------------
    ; MAIN LOOP    
    MAIN:    SLEEP    ; GOTO SLEEP MODE(I a sleepy! and need to save my energy)
        BTFSS    CH1
        GOTO    DO_CH1
        BTFSS    CH2
        GOTO    DO_CH2
        BTFSS    CH3
        GOTO    DO_CH3
        GOTO    MAIN    

    ;------------------------------------
    DO_CH1:    CALL    DEBOUNCE
        BTFSC    CH1
        GOTO    MAIN
        MOVLW    CH1_CMD    ; LOAD COMMANE FOR CHANNEL 1
        MOVWF    CMD
        CALL    SEND_RC5
        ;
        BTFSS    CH1
        GOTO    $-1    ; WAIT FOR SWITCH RELEASED
        ;
        CALL    DEBOUNCE    ; DELAY AFTER SWITCH RELEASED
        GOTO    MAIN

    ;------------------------------------    
    DO_CH2:    CALL    DEBOUNCE
        BTFSC    CH2
        GOTO    MAIN
        MOVLW    CH2_CMD    ; LOAD COMMANE FOR CHANNEL 1
        MOVWF    CMD
        CALL    SEND_RC5
        ;
        BTFSS    CH2
        GOTO    $-1    ; WAIT FOR SWITCH RELEASED
        ;
        CALL    DEBOUNCE    ; DELAY AFTER SWITCH RELEASED
        GOTO    MAIN
        ;
    ;------------------------------------    
    DO_CH3:    CALL    DEBOUNCE
        BTFSC    CH3
        GOTO    MAIN
        MOVLW    CH3_CMD    ; LOAD COMMANE FOR CHANNEL 1
        MOVWF    CMD
        CALL    SEND_RC5
        ;
        BTFSS    CH3
        GOTO    $-1    ; WAIT FOR SWITCH RELEASED
        ;
        CALL    DEBOUNCE    ; DELAY AFTER SWITCH RELEASED
        GOTO    MAIN
        ;    
    ;======================================
    ; SEND LOGIC 0
    ;======================================
    LOGIC0:    MOVLW    .32        ; 1
        MOVWF    CNT1        ; 1
        ;
    LOG0_1:    BSF    IR        ; 1 MAKE IR HIGH 35% Duty cycle = 9 uS
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        ;
        ;===================================
        BCF    IR        ; 1 MAKE IR LOW 17 uS
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        NOP            ; 1
        ;
        DECFSZ    CNT1,F        ; 1/2
        GOTO    LOG0_1        ; 2    26 uS
        ;
        CALL    DELAY_OFF
        RETURN            ; 2
        ;
    ;======================================
    ; SEND LOGIC 1
    ;======================================
    LOGIC1:    CALL    DELAY_OFF    ; DELAY 899 uS
        MOVLW    .32        ; 1
        MOVWF    CNT1        ; 1
        ;
    LOG1_1:    BSF    IR        ; 1 MAKE IR HIGH 35% Duty cycle = 9 uS
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        ;
        ;===================================
        BCF    IR        ; 1 MAKE IR LOW 17 uS
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        GOTO    $+1
        NOP            ; 1
        ;
        DECFSZ    CNT1,F        ; 1/2
        GOTO    LOG1_1        ; 2
        ;
        RETURN            ; 2
        ;
    ;======================================
    ; DELAY FOR NO CARRAIR
    ; DELAY ABOUT 835 uS
    ;======================================
    DELAY_OFF:
        MOVLW    5        ; 1
        MOVWF    CNT3        ; 1    
        MOVLW    .54        ; 1
        MOVWF    CNT4        ; 1
        DECFSZ    CNT4,F        ; 1/2
        GOTO    $-1        ; 2    
        DECFSZ    CNT3,F      ; 1/2
        GOTO    $-5        ; 2
        RETURN            ; 2
       
    ;======================================
    ; SEND RC5 TO REMOTE
    ; INPUT : CMD (6 BIT IR COMMAND)
    ;======================================
    SEND_RC5:
        ; SEND 2 START  BIT
        CALL    LOGIC1
        CALL    LOGIC1
        ; SEND TOGGLE BIT
        BTFSS    TOG_BIT
        GOTO    $+3
        CALL    LOGIC1
        GOTO    $+2
        CALL    LOGIC0

        ; SEND ADDRESS 5 BIT FIX AT 01011 (0X0B) IT MAY BE CHANGED BY YOU
        CALL    LOGIC0    ; 0  MSB FIRST BIT 4
        CALL    LOGIC1    ; 1
        CALL    LOGIC0    ; 0
        CALL    LOGIC1    ; 1
        CALL    LOGIC1    ; 1  LSB BIT 0
        ;
        ; SEND COMMAND 6 BIT(00HH LLLL) MSB FIRST
        BCF    STATUS,C
        RLF    CMD,F    ; AFTER FIRST ROTAGE 0HHL LLL0
        RLF    CMD,F    ; AFTER SECOND ROTAGE HHLL LL00
        ;
        MOVLW    6
        MOVWF    CNT2
        ;
        RLF    CMD,F        ; SEND MSB FIRST
        BTFSS    STATUS,C
        GOTO    $+3
        CALL    LOGIC1
        GOTO    $+2
        ;
        CALL    LOGIC0
        DECFSZ    CNT2,F
        GOTO    $-7
        ;
        RETLW    0        
        ;    
       
    ;======================================
    ; DEBOUNCE SWITCH
    ; DELAY 15 mS
    ;======================================
    DEBOUNCE:
        MOVLW    .1        ; 1
        MOVWF    CNT1        ; 1
    DEL_1:    MOVLW    .20
        MOVWF    CNT2        ; 1
    DEL_2:    CLRF    CNT3        ; 1
    DEL_3:    DECFSZ    CNT3,F        ; 1/2
        GOTO    DEL_3        ; 2
        DECFSZ    CNT2,F        ; 1/2
        GOTO    DEL_2        ; 2
        DECFSZ    CNT1,F        ; 1/2
        GOTO    DEL_1        ; 2
        RETLW    0        ; 2
       
        END
     
  14. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    ok cool cant wait
     
  15. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,018
    Likes:
    317
    Location:
    Brisbane Australia
    ONLINE
    This finally got to me and I dug out my scope and had a play.

    Can you try,
    Code (text):

    #include <p18f1320.h>
    #include "delays.h"

    #pragma config WDT = OFF, LVP = OFF, OSC = INTIO2

    void sendbyte(char Num,char bits){
    char i;
        for(i=0;i<bits;i++){
            CCPR1L = 0x1A;                  // 0
            CCP1CON = 0x1C;                 // 50%
            if(Num&1==1)
                Delay100TCYx(24);           //1.2mS
            else
                Delay100TCYx(12);           //0.6mS
            Num=Num>>1;
            CCPR1L = 0x00; //Space
            CCP1CON = 0x0C ; // 0%
            Delay100TCYx(12);               //0.6mS
        }
    }

    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) {
            CCPR1L = 0x1A; // 0
            CCP1CON = 0x1C ; // 50%
            Delay100TCYx(48);               //2.4mS pulse
            CCPR1L = 0x00; //Space
            CCP1CON = 0x0C ; // 0%
            Delay100TCYx(12);               //0.6mS
            sendbyte(18,7);                 //device 18
            sendbyte(1,6);                  //command 1
            Delay1KTCYx(100);
         }    
    }
    The problem with your original code was you just aren't sending enough bits.

    Mike.
     
    Last edited: Apr 9, 2008
  16. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    no go pommie i even tried sending command then device but nothing...

    .. also how come i cant open LA anymore. For some reason its greyed out now

    EDIT: Also tried to send 5 bits for not 6
     
    Last edited: Apr 9, 2008
  17. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    My codes are
    [​IMG]
     
  18. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Well I've just got the code converted yet it's untested. I'm just posting it because I've got work that has to be done before I can play.
    Code (text):
    ;------------------------------------------------------
    ; PROJECT : 3 CHANNEL TX IR REMOTE
    ; CRYSTAL 4 MHz
    ; MPLAB : 7.11 , Assembly
    ; RC5 FORMAT @38KHz , 35% DUTY CYCLE
    ; ADDRESS = 0X0B  0000 1011 you may change
    ; CH1  = 0X01
    ; CH2  = 0X02
    ; CH3  = 0X03
    ; NOT USE TOGGLE ALWAY = 0
    ; WWW.SIXCA.COM
    ; 4-JULY 2005
    ;
    ; FREE TO USE FOR PERSONAL OR EVEN COMERCIAL PRODUCT
    ; Modified by William Richardson for use with the
    ; blueroomelectronics Junebug Tutor
    ; BETA (not tested...)
    ;------------------------------------------------------

        list P=18F1320
        #include <P18F1320.INC>
        CONFIG    OSC=INTIO2,WDT=OFF,LVP=OFF

    #DEFINE CH1    PORTB,0    ; CONNECT WITH TX SWITCH CHANNEL 1
    #DEFINE CH2    PORTB,2    ; CONNECT WITH TX SWITCH CHANNEL 2
    #DEFINE CH3    PORTB,5    ; CONNECT WITH TX SWITCH CHANNEL 3
    #DEFINE IR    LATB,3    ; CONNECT WITH IR LED WITH TRANSISTOR DRIVES
    #DEFINE TOG_BIT    TOGGLE,0
    #DEFINE CH1_CMD    0X01    ; CHANNEL 1 COMMAND
    #DEFINE CH2_CMD    0X02    ; CHANNEL 2 COMMAND
    #DEFINE CH3_CMD    0X03    ; CHANNEL 3 COMMAND

        cblock     0x00
        CNT1,CNT2,CNT3,CNT4,TOGGLE,CMD
        endc
       
        ORG    0x00
        movlw    0x62        
        movwf    OSCCON        ; 4MHz clock (1us instruction)
        setf    ADCON1        ; set all I/O to digital
        bcf    INTCON2,RBPU    ; enable PORTB input pullups
        clrf    PORTB        ; zero the output bits        
        MOVLW    B'11110111'    ; IR Output on RB3
        MOVWF    TRISB
        rcall    DEBOUNCE
        BCF    TOG_BIT
       
    ;------------------------------------
    ; MAIN LOOP    
    MAIN:    
    ;    SLEEP    ; removed for test GOTO SLEEP MODE(I a sleepy! and need to save my energy)
        BTFSS    CH1
        bra    DO_CH1
        BTFSS    CH2
        bra    DO_CH2
        BTFSS    CH3
        bra    DO_CH3
        bra    MAIN    

    ;------------------------------------
    DO_CH1:    rcall    DEBOUNCE
        BTFSC    CH1
        bra    MAIN
        MOVLW    CH1_CMD        ; LOAD COMMANE FOR CHANNEL 1
        MOVWF    CMD
        rcall    SEND_RC5
        BTFSS    CH1
        bra    $-2        ; WAIT FOR SWITCH RELEASED
        rcall    DEBOUNCE    ; DELAY AFTER SWITCH RELEASED
        bra    MAIN

    ;------------------------------------    
    DO_CH2:    rcall    DEBOUNCE
        BTFSC    CH2
        bra    MAIN
        MOVLW    CH2_CMD        ; LOAD COMMANE FOR CHANNEL 1
        MOVWF    CMD
        rcall    SEND_RC5
        BTFSS    CH2
        bra    $-2        ; WAIT For SWITCH RELEASED
        rcall    DEBOUNCE    ; DELAY AFTER SWITCH RELEASED
        bra    MAIN
        ;
    ;------------------------------------    
    DO_CH3:    rcall    DEBOUNCE
        BTFSC    CH3
        bra    MAIN
        MOVLW    CH3_CMD        ; LOAD COMMAND FOR CHANNEL 1
        MOVWF    CMD
        rcall    SEND_RC5
        BTFSS    CH3
        bra    $-2        ; WAIT FOR SWITCH RELEASED
        rcall    DEBOUNCE    ; DELAY AFTER SWITCH RELEASED
        bra    MAIN
        ;    
    ;======================================
    ; SEND LOGIC 0
    ;======================================
    LOGIC0:    MOVLW    .32        ; 1
        MOVWF    CNT1        ; 1
    LOG0_1:    BSF    IR        ; 1 MAKE IR HIGH 35% Duty cycle = 9 uS
        bra    $+2
        bra    $+2
        bra    $+2
        bra    $+2
        BCF    IR        ; 1 MAKE IR LOW 17 uS
        bra    $+2
        bra    $+2
        bra    $+2
        bra    $+2
        bra    $+2
        bra    $+2
        nop            ; 1
        DECFSZ    CNT1,F        ; 1/2
        bra    LOG0_1        ; 2    26 uS
        rcall    DELAY_OFF
        RETURN            ; 2
        ;
    ;======================================
    ; SEND LOGIC 1
    ;======================================
    LOGIC1:    rcall    DELAY_OFF    ; DELAY 899 uS
        MOVLW    .32        ; 1
        MOVWF    CNT1        ; 1
    LOG1_1:    BSF    IR        ; 1 MAKE IR HIGH 35% Duty cycle = 9 uS
        bra    $+2
        bra    $+2
        bra    $+2
        bra    $+2
        BCF    IR        ; 1 MAKE IR LOW 17 uS
        bra    $+2
        bra    $+2
        bra    $+2
        bra    $+2
        bra    $+2
        bra    $+2
        nop            ; 1
        DECFSZ    CNT1,F        ; 1/2
        bra    LOG1_1        ; 2
        RETURN            ; 2
        ;
    ;======================================
    ; DELAY FOR NO CARRAIR
    ; DELAY ABOUT 835 uS
    ;======================================
    DELAY_OFF:
        MOVLW    .5        ; 1
        MOVWF    CNT3        ; 1    
    Loop1:    MOVLW    .54        ; 1
        MOVWF    CNT4        ; 1
        decfsz    CNT4,F        ; 1/2
        bra    $-2        ; 2    
        decfsz    CNT3,F      ; 1/2
        bra    Loop1:        ; 2
        return            ; 2
       
    ;======================================
    ; SEND RC5 TO REMOTE
    ; INPUT : CMD (6 BIT IR COMMAND)
    ;======================================
    SEND_RC5:
        rcall    LOGIC1    ; SEND 2 START  BIT
        rcall    LOGIC1
        BTFSS    TOG_BIT    ; SEND TOGGLE BIT
        bra    $+6
        rcall    LOGIC1
        bra    $+4
        rcall    LOGIC0

    ; SEND ADDRESS 5 BIT FIX AT 01011 (0X0B) IT MAY BE CHANGED BY YOU
        rcall    LOGIC0    ; 0  MSB FIRST BIT 4
        rcall    LOGIC1    ; 1
        rcall    LOGIC0    ; 0
        rcall    LOGIC1    ; 1
        rcall    LOGIC1    ; 1  LSB BIT 0
       
    ; SEND COMMAND 6 BIT(00HH LLLL) MSB FIRST
        bcf    STATUS,C
        rlcf    CMD,F    ; AFTER FIRST ROTAGE 0HHL LLL0
        rlcf    CMD,F    ; AFTER SECOND ROTAGE HHLL LL00
        MOVLW    .6
        MOVWF    CNT2
        rlcf    CMD,F        ; SEND MSB FIRST
        btfss    STATUS,C
        bra    $+6
        rcall    LOGIC1
        bra    $+4
        rcall    LOGIC0
        decfsz    CNT2,F
        bra    $-14        ; seems wrong..
        retlw    0        
       
    ;======================================
    ; DEBOUNCE SWITCH
    ; DELAY 15 mS
    ;======================================
    DEBOUNCE:
        MOVLW    .1        ; 1
        MOVWF    CNT1        ; 1
    DEL_1:    MOVLW    .20
        MOVWF    CNT2        ; 1
    DEL_2:    CLRF    CNT3        ; 1
    DEL_3:    DECFSZ    CNT3,F        ; 1/2
        bra    DEL_3        ; 2
        DECFSZ    CNT2,F        ; 1/2
        bra    DEL_2        ; 2
        DECFSZ    CNT1,F        ; 1/2
        bra    DEL_1        ; 2
        RETLW    0        ; 2
        END
     
  19. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,018
    Likes:
    317
    Location:
    Brisbane Australia
    ONLINE
    The code I posted above (changed to 5 bits - doh), gives a very clear signal on the scope (and so did your original code) and so I would guess it is your actual transmitter part that is at fault.

    Mike.
     
  20. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    yeah thats what im thinking so i ordered some new LEDs along with some 18f1320s should come in about a week...
     
  21. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    He're an App note on IR Remote control transmitter from Microchip
    AN1064
    40KHz is the carrier frequency so here are the values for a 4MHz OSC.
    Code (text):
    /*
     * PWM registers configuration
     * Fosc = 4000000 Hz
     * Fpwm = 40000.00 Hz (Requested : 40000 Hz)
     * Duty Cycle = 35 %
     * Resolution is 6 bits
     * Prescaler is 1
     * Ensure that your PWM pin is configured as digital output
     * see more details on http://www.micro-examples.com/
     * this source code is provided 'as is',
     * use it at your own risks
     */
    PR2 = 0b00011000 ;
    T2CON = 0b00000100 ;
    CCPR1L = 0b00001000 ;
    CCP1CON = 0b00101100 ;
     

    Attached Files:

Share This Page