Infrared HPWM setup


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Infrared HPWM setup

    Hi Richard,

    thanks for the clarification and answer.

    I found in the manual what you said regarding the Resolution bits.

    Name:  Resolution.jpg
Views: 1975
Size:  90.0 KB

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Infrared HPWM setup

    the duty cycle is a 10 bit value at best for that chip, not all frequencies can have the full 10bit range available
    it totally depends on choices made with regard to prescaler and period.
    no matter what bit resolution is possible the CPRxL value is the upper 8 bits of the duty cycle word valueCCP1CON bit 4 and 5 are the lower two bits
    Warning I'm not a teacher

  3. #3
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Infrared HPWM setup

    i've also noticed you've shifted 2 bits on the right the CCPR1L

    CCPR1L = 210>>2 ' Set PWM Duty-Cycle to 50%

    So the CCPR1L value will be 52.

    (11010010) 210>>2 = 00110100 = 52

    why have we shifted?
    Last edited by astanapane; - 1st June 2023 at 08:01.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Infrared HPWM setup

    why have we shifted?
    CPRxL value is the upper 8 bits of the duty cycle word valueCCP1CON bit 4 and 5 are the lower two bits



    (011010010) 210>>2 = 00110100 = 52 ;high 8bits
    (011010010) 210 & 3 = 00000010 = 2 ;low 2 bits

    00000010<<4 = 00100000
    CCP1CON = 00100000 |12 to set low bits in pwmmode

    C version from microchip
    Code:
    void PWM1_LoadDutyValue(uint16_t dutyValue)
    {
       // Writing to 8 MSBs of pwm duty cycle in CCPRL register
        CCPR1L = ((dutyValue & 0x03FC)>>2);
        
       // Writing to 2 LSBs of pwm duty cycle in CCPCON register
        CCP1CON = ((uint8_t)(CCP1CON & 0xCF) | ((dutyValue & 0x0003)<<4));
    }
    Last edited by richard; - 1st June 2023 at 08:07.
    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Infrared HPWM setup

    thanks Richard. now is clear.

    i will get back once i have a working code and establish an IR communication.

  6. #6
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Infrared HPWM setup

    with the following configuration i got this on the scope. So i guess we are in a good path.

    To mention that the main OSC is at 64Mhz using HPWM on the PIC18f26K22 on portc.2

    Code:
    TRISC.2 = 0          ' CCP1 (PortC.2 = Output)
    PR2 = 104            ' Set PWM Period for approximately 38KHz
    CCPR1L = 52          ' Set PWM Duty-Cycle to 50% (011010010) 210>>2 = 00110100 = 52
    T2CON = %00000101    ' Timer2 ON + 4 prescale
    CCP1CON = %00001100  ' Mode select %00001100 = PWM
    Name:  38khz frequency.jpg
Views: 1864
Size:  403.1 KB

    all thanks to Richard.

    now im going on the next step.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Infrared HPWM setup

    very good.
    you could set the lower two bits of the Duty-Cycle word [CCP1CON bits 4:5] to get the duty cycle
    even closer to exactly 50%, if you wanted to
    CCP1CON = %00101100
    Warning I'm not a teacher

  8. #8
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Infrared HPWM setup

    I will do that thanks a lot.

    Yesterday i tried till late at night to set a code for the TX and RX, a very simple one but didnt work.

    tx:

    Code:
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 1 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|                                                                             |
            DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
            DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
            DEFINE HSER_CLROERR 1 ' Clear overflow automatically
            DEFINE HSER_SPBRG 130 ' 9600 Baud @ 64MHz, -0.02%
            SPBRGH = 6
            BAUDCON.3 = 1         ' Enable 16 bit baudrate generator             
    '------------------------------------------------------------------------------|
    
    ID	    VAR BYTE
    button1 var porta.0  ' we configure this button 1 at porta.0
    button2 var porta.1  ' we configure this button 2 at porta.1
    RED     var latc.3   ' a RED LED indicates the PIC working condition
    Blue    var lata.2   ' a Blue LED indicates the push button everytime
    
    high red
    pause 100
    low red 
    pause 50
    high red
    '------------------------------------------------------------------------------|
    BEGIN:
    
       ID	= 10
    if button1 = 0 then 
        gosub button1_pressed
    	endif
    
    low blue
    	GOTO BEGIN
    '------------------------------------------------------------------------------|
    
    button1_pressed:
    high blue
    	    hSEROUT [ID]  ' we send at portc.6 which is connected the IR module at the 74LS00 in pin No2 
    	    PAUSE 100
        return
    
    button2_pressed:
    high blue
    	    hSEROUT [ID]  ' we send at portc.6 which is connected the IR module at the 74LS00 in pin No3 
    	    PAUSE 100
        return
    end
    RX:
    Code:
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 2 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|                                                                             |
    
            DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
            DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
            DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
            DEFINE HSER2_SPBRG 130 ' 9600 Baud @ 64MHz, -0.02%
            SPBRGH2 = 6
            BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
            
    '-------------------------------------------------------------------------------|
    ID	    con 10
    Green   var lata.1   ' a Green LED which indicates the 1st output of the IR input code
    Blue    var lata.0   ' a Blue LED indicates the 2nd output of the IR input code 
    Red     var lata.2   ' a Red LED indicates the PIC working condition
    '------------------------------------------------------------------------------|
    '                 RED LED indicates that PIC is up and running                 |
    '------------------------------------------------------------------------------|
    
    high red
    pause 100
    low red 
    '------------------------------------------------------------------------------|
    
    Begin:
    
    hSERin2 [wait(ID)]
    high red
    'pause 100
    
       gosub FIRST_SIGNAL
    '   endif
    
    '------------------------------------------------------------------------------|
    
    FIRST_SIGNAL:
    high green
    pause 500
    low green
    return
    
    end

Similar Threads

  1. Replies: 3
    Last Post: - 23rd October 2011, 12:53
  2. InfraRed Data Com
    By rayzrocket in forum Off Topic
    Replies: 5
    Last Post: - 29th March 2010, 15:42
  3. Infrared x PIC
    By ewandeur in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th December 2009, 18:30
  4. infrared help
    By griffin in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th December 2008, 05:34
  5. infrared
    By bmohnsen in forum General
    Replies: 1
    Last Post: - 2nd May 2007, 16:35

Members who have read this thread : 4

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts