News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

CODIGO NEC FOR CONTROL TX

Started by superpro, Jul 22, 2022, 01:59 AM

Previous topic - Next topic

Teo

Hi Pepe
There are also problems with duty cycle
Teo

RGV250

Hi,
I wondered if you also need to change the timing values here as well.
just one of the proceedures.
Proc RC5_SendZero()
    PinOutput TX_Pin                            ' Enable the 38 KHz modulation
    DelayUS 887                                 ' Delay for the required time
    PinInput TX_Pin                             ' Disable the 38 KHz modulation
    DelayUS 884                                 ' Delay for the required time
EndProc

Bob

Teo

Hi Bob,
I'm referring to the duty cycle of the 56 Khz signal.
Teo

Pepe

#23
887 and 884 in the RC5_SendZero() and RC5_SendOne() procedures and 87 in RC5_TX are good

Teo

#24
Hi Pepe,
I'm referring to the duty cycle of the 56 Khz signal.
If I write:

HPWM 1, 127, 56000
PR2=17
PinOutput TX_Pin

Duty cycle is not 50%
Teo

Pepe

change 127 until duty cycle is corrected

Teo

That's what I did.
I don't understand why it doesn't work with PIC16f1826, strange.
Maybe you have an idea.
Thanks in advance,
Teo

Teo

Code:

Device = 16F1826

Config1 FOSC_XT, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_ON, CLKOUTEN_OFF, IESO_ON, FCMEN_ON
Config2 WRT_OFF, PLLEN_OFF, STVREN_ON, BORV_25, LVP_OFF

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
    Declare Xtal = 4                                   ' Tell the compiler what frequency the device will be operating at
    Declare CCP1_Pin = PORTB.0                      ' Tell the compiler what pin is used for the CCP1 peripheral
    Symbol TX_Pin = PORTB.0                         ' The CCP1 peripheral's pin to use for the IR LED
'
' Create some variables
'
    Dim RC5_bSystem  As Byte                        ' Holds the system value
    Dim RC5_bCommand As Byte                        ' Holds the command value
    Dim RC5_tToggle  As Bit                         ' Holds the toggle bit

'-------------------------------------------------------------------------------------------------------
' The main program starts here
' Transmit the system and command values using the RC5 infrared protocol
'
Main:
    Setup()                                         ' Setup the program

Proc Setup()
    HPWM 1, 127, 56000
    PR2=17                         
    PinOutput TX_Pin                             
    RC5_tToggle = 0
EndProc

It doesn't work

Teo

Pepe

proteus demo

Pepe

#29
isis demo

top204

#30
The PWM frequency can also be set using the datasheet and a procedure, instead of the HPWM command:

$define PWM_Pulse_On() PinOutput PORTB.3
$define PWM_Pulse_Off() PinInput PORTB.3

'-----------------------------------------------------------
' Setup the EPWM peripheral on a PIC16F1826 device
' Input     : None
' Output    : None
' Notes     : Uses Timer2, that is set for 18uS (approx 55.55KHz)
'           : On a device operating at 4MHz.
'           : PWM reolution is 6-bits, and duty cycle is set for approx 50%
'
Proc EPWM_56KHz()
    PinInput PORTB.3
    PR2 = 17                ' Set Timer2 period
    TMR2 = 0
    T2CON = %00000100       ' Setup Timer2
    CCP1CON = $3C
    ECCP1AS = $00
    PWM1CON = $80
    PSTR1CON = $01
    CCPR1H = 0
    CCPR1L = 8
EndProc

The PWM resolution at that high a frequency with a low device operating frequency is only 6-bits. i.e. A value of 63, so an exact 50% duty cycle would require a value of 31.5. However, this value cannot be placed in the EPWM SFRs, so it will need to be 31 or 32, and the duty cycle will not be 'exactly' 50%. But for your type of use, it does not need to be exactly 50%.

With a device operating at 4MHz, the exact 56KHz frequency cannot be acheived with a timer. So the above is approx 55.5KHz.

The PWM_Pulse_On() and PWM_Pulse_Off() meta macros, will enable or disable the waveform from the pin.



Teo

Thanks everyone for the help.
Teo

Pepe

#32
 :(

Teo

Thank you very much !
Please use Proteus 7.8 if possible.
Thank you in advance!
Teo

Pepe

#34
 :(

Teo


Pepe

Fixed files

Teo


Pepe

demo for 16f877a

Teo

Thank you very much !
Please use Proteus 7.8 if possible.
Thank you in advance!
Teo