View previous topic :: View next topic |
Author |
Message |
LVelectronics
Joined: 18 Nov 2015 Posts: 6
|
How to enable 16x clock output for IRDA on 24FJ256 [SOLVED] |
Posted: Wed Nov 18, 2015 12:51 pm |
|
|
Hi,
I'm trying to configure a serial port for IRDA interface, requiring TX, RX and a 16x clock for the IRDA chip.
How can this be configured?
Code: |
// IRDA serial bus
#pin_select U2TX=PIN_F4
#pin_select U2RX=PIN_F5
#use rs232(stream=IRDA,baud=38400,parity=N,xmit=PIN_F4,rcv=PIN_F5,bits=8,RTS=PIN_F3, errors) |
The RTS pin should be the 16x baudrate clock out.
Any help is welcome!
LVE
Last edited by LVelectronics on Sun Jul 17, 2016 12:54 am; edited 2 times in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Wed Nov 18, 2015 3:43 pm |
|
|
I'd suggest:
Code: |
// IRDA serial bus
#pin_select U2TX=PIN_F4
#pin_select U2RX=PIN_F5
#pin_select U2RTS=PIN_F7
#use rs232(stream=IRDA,baud=38400,parity=N,UART2, errors)
#BYTE U2MODE=getenv("SFR:U2MODE")
#define BCLK_MODE 0x30
//then in the code
U2MODE=U2MODE | BCLK_MODE;
|
Generally when using pin_select it is better to select the pins, and then just use the UART name in #use RS232.
This switches the UART mode to generate the 16* output on the RTS pin. |
|
![](templates/subSilver/images/spacer.gif) |
LVelectronics
Joined: 18 Nov 2015 Posts: 6
|
|
Posted: Thu Nov 19, 2015 11:49 am |
|
|
Hi Ttelmah,
Thank's for the valuable inputs.
I had to tweak it a little bit and convert to 16 bits:
Code: | // IRDA serial bus
#pin_select U2TX=PIN_F4
#pin_select U2RX=PIN_F5
#pin_select U2RTS=PIN_F3
#use rs232(stream=IRDA,baud=38400,parity=N,UART2, errors)
#WORD U2MODE=getenv("SFR:U2MODE")
#define BCLK_MODE 0x0300
//then in the code
U2MODE=U2MODE | BCLK_MODE; |
This runs fine. I noticed that the duty cycle of the 16X clock is not 50%, but (15/16)%. Runs OK for the IRDA encoder, no problem
Kind regards,
LVE |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Thu Nov 19, 2015 3:02 pm |
|
|
Aaargh, yes, should have twigged I needed 'word' for the 16bit register.
Hit head on wall....
The clock is synthesised by division from the master CPU clock, so the irregularity will change according to the ratio of baud to master clock. As you have found though it shouldn't matter.
Glad it (basically) worked. |
|
![](templates/subSilver/images/spacer.gif) |
LVelectronics
Joined: 18 Nov 2015 Posts: 6
|
|
Posted: Fri Nov 20, 2015 12:42 am |
|
|
Thank's for the help! SOLVED |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Fri Nov 20, 2015 2:27 am |
|
|
Edit the post header to say 'solved'.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
LVelectronics
Joined: 18 Nov 2015 Posts: 6
|
How to enable 16x clock output for IRDA on 24FJ256 [RE_OPEN] |
Posted: Fri Jul 15, 2016 8:40 am |
|
|
I re-opened this one...
When I use the following code, the BCLK output is 16x the baudrate clock.
Code: |
// IRDA serial bus
#pin_select U2TX=PIN_F4
#pin_select U2RX=PIN_F5
#pin_select U2RTS=PIN_F3
#use rs232(stream=IRDA,baud=38400,parity=N,UART2, errors)
#WORD U2MODE=getenv("SFR:U2MODE")
#define BCLK_MODE 0x0300
//then in the code
U2MODE = U2MODE | BCLK_MODE;
|
BUT, when I lower the baud rate clock, eg to 9600, the BLCK output is not 16x, but 4x the baudrate.
Although the bit settings UEN0 and UEN1 both true.
Code: |
// IRDA serial bus
#pin_select U2TX=PIN_F4
#pin_select U2RX=PIN_F5
#pin_select U2RTS=PIN_F3
#use rs232(stream=IRDA,baud=9600,parity=N,UART2, errors)
#WORD U2MODE=getenv("SFR:U2MODE")
#define BCLK_MODE 0x0300
//then in the code
U2MODE = U2MODE | BCLK_MODE;
|
BCLK output is 38.4 kHz instead of 153kHz.
Any ideas how to solve this? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Fri Jul 15, 2016 2:00 pm |
|
|
First, tell use us exactly which chip you are using?. So PIC24FJ256?????. Fill in the question marks please....
Also what your clock rate is?.
And compiler version?.
The odd thing is that *4, is what would happen if you went for a fast baud rate, and BRGH got set to 1, so the UART has an /4 prescaler, rather than /16.
Sounds as if your compiler version is selecting this mode for some reason, so would want to check compiler versions versus clock rates on the specific chip to see any pattern. |
|
![](templates/subSilver/images/spacer.gif) |
LVelectronics
Joined: 18 Nov 2015 Posts: 6
|
|
Posted: Sat Jul 16, 2016 2:35 am |
|
|
Hi,
The chip is 24FJ256DA206
The clock is running at 32 Mhz
Code: | // External crystal is 8Mhz. Max clock speed is 96 Mhz
// Set clock to 32 Mhz to have some extra head room
#use delay(clock=32MHz,crystal=8MHz,restart_wdt)
|
Compiler version is 5.058
I already tried to force the BRGH bit to zero in U2MODE reg, but didn't help.
Code: | // IRDA serial bus
#pin_select U2TX=PIN_F4
#pin_select U2RX=PIN_F5
#pin_select U2RTS=PIN_F3
#use rs232(stream=IRDA,baud=9600,parity=N,UART2, errors)
#WORD U2MODE=getenv("SFR:U2MODE")
#define BCLK_MODE 0x0300
#define BRGH0 0xFFF7 |
In the code:
Code: | // Configure IRDA
U2MODE = U2MODE | BCLK_MODE; // Set UEN0 and UEN1 to 1 for IRDA
U2MODE = U2MODE & BRGH0; // Set BRGH to 0 for 16x clock speed |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Sat Jul 16, 2016 10:39 am |
|
|
I suspect you may be hitting a hardware problem in the PIC....
Though this applies to the PIC32, have a look at this thread:
<http://www.microchip.com/forums/m511255.aspx>
Look at reply #10.
Sound familiar?......
Have a nasty feeling not many people have used/tried IRDA at low baud rates, and the fault may be common. ![Sad](images/smiles/icon_sad.gif) |
|
![](templates/subSilver/images/spacer.gif) |
LVelectronics
Joined: 18 Nov 2015 Posts: 6
|
|
Posted: Sun Jul 17, 2016 12:53 am |
|
|
Ahhh...
Seems indeed like a hardware problem. I'll have to work at higher baudrate...
Thanks for the excellent help!
Kind regards |
|
![](templates/subSilver/images/spacer.gif) |
|