CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to enable 16x clock output for IRDA on 24FJ256 [SOLVED]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
LVelectronics



Joined: 18 Nov 2015
Posts: 6

View user's profile Send private message

How to enable 16x clock output for IRDA on 24FJ256 [SOLVED]
PostPosted: Wed Nov 18, 2015 12:51 pm     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Nov 18, 2015 3:43 pm     Reply with quote

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



Joined: 18 Nov 2015
Posts: 6

View user's profile Send private message

PostPosted: Thu Nov 19, 2015 11:49 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu Nov 19, 2015 3:02 pm     Reply with quote

Aaargh, yes, should have twigged I needed 'word' for the 16bit register.Embarassed
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.
LVelectronics



Joined: 18 Nov 2015
Posts: 6

View user's profile Send private message

PostPosted: Fri Nov 20, 2015 12:42 am     Reply with quote

Thank's for the help! SOLVED
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Fri Nov 20, 2015 2:27 am     Reply with quote

Edit the post header to say 'solved'.

Best Wishes
LVelectronics



Joined: 18 Nov 2015
Posts: 6

View user's profile Send private message

How to enable 16x clock output for IRDA on 24FJ256 [RE_OPEN]
PostPosted: Fri Jul 15, 2016 8:40 am     Reply with quote

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?
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Fri Jul 15, 2016 2:00 pm     Reply with quote

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



Joined: 18 Nov 2015
Posts: 6

View user's profile Send private message

PostPosted: Sat Jul 16, 2016 2:35 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sat Jul 16, 2016 10:39 am     Reply with quote

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
LVelectronics



Joined: 18 Nov 2015
Posts: 6

View user's profile Send private message

PostPosted: Sun Jul 17, 2016 12:53 am     Reply with quote

Ahhh...
Seems indeed like a hardware problem. I'll have to work at higher baudrate...
Thanks for the excellent help!
Kind regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group