|
|
View previous topic :: View next topic |
Author |
Message |
tonymcc
Joined: 27 Jul 2010 Posts: 15 Location: Northampton UK Home of the 'Big Sheds'
|
PIC24FJ128GA010 - UART operation with fast rise PSUs |
Posted: Thu Jul 05, 2012 7:07 am |
|
|
I am using a 24FJ128GA010 in an industrial instrument, developing under PCD V4.134, CCSLOAD V4.037. I use UART2 to transfer data between the processor and a standalone OEM HART modem using a private(ish) Modbus protocol. I developed this using a BIG bench linear power supply with no problems. When I tried using a smaller switch mode supply the communication with the HART modem cut off.
I tried four other supplies, 2 switch mode and 2 linear, all with the same problem. I was starting to believe that I had a production instrument that would only work with my bench power supply! I checked the rise times of the supplies and found that the 'good' supply rise time was 155mS to 90% rail whereas the 'failed' supplies were between 1mS and 80mS. Obviously, a straight switch in the dc supply to the unit failed as well.
I tried all sorts of delays and re-initialisations to no avail and then I thought of the UART. I set this up using #USE in the project header file:
Code: |
#use RS232 (UART2, baud=9600, xmit=PIN_F5, rcv=PIN_F4, parity = E, bits = 8, stream=hart, restart_wdt)
|
I though that I would try giving the UART a reminder in the code stream and added the following:
Code: |
void io_initialisation(void)
{ init_LCD(); //initialise LCD
timer_init(); //internal timer
ir_init(); //IR900 detect
adc_init(); //internal and external A-D
rtc_init(); //real time clock
led_io_init(); //LED driver
op_io_init(); //external I/O driver
enable_interrupts(INT_RDA2); //enable HART Rx - will eventually include Tx
enable_interrupts(INTR_GLOBAL);
setup_uart(9600,hart); //make sure that HART UART is switched on
}
void main() //final function
{ setup_wdt(WDT_ON); //start watchdog
timer1_scale = 0xE0D8; //setup timer 1 for 2mS timeout
io_initialisation(); //initialise SPI I/O
|
etc to the final loop. This seemed to cure the problem completely.
Whilst I am pleased that I have found a solution I should like to know why it should work. How and when are the #USE instructions executed on power up? Is there a more elegant solution to setting up a UART?
Cheers,
Tony McCormick |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Jul 05, 2012 9:14 am |
|
|
You didn't include "errors" in the use RS232. "errors" makes the firmware reset the UART in the event of hardware errors. Without it the UART can lock up. It maybe that noise/funny edges in the incoming data happen while the PSUs are running up, and these cause the UART in the PIC to lock up, making comms impossible.
Just a thought... may be wrong.
RF Developer |
|
|
tonymcc
Joined: 27 Jul 2010 Posts: 15 Location: Northampton UK Home of the 'Big Sheds'
|
Thanks - a more elegant solution! |
Posted: Mon Jul 16, 2012 2:27 am |
|
|
Hi RF,
Thanks for the suggestion and my apologies for not getting back to the forum any sooner. The inclusion of 'errors' in the #use RS232 statement sorted out the start up problem with the on-board UART.
Thanks for your help.
Tony |
|
|
|
|
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
|