|
|
View previous topic :: View next topic |
Author |
Message |
aroonkriss
Joined: 03 Dec 2012 Posts: 19 Location: kerala
|
setup_timer2 function of dsPIC30f3013 |
Posted: Sat Jan 12, 2013 2:16 am |
|
|
Hi,
I need to set up a 3.5 character silent space between message frames for modbus protocol. I am using dspic30f3013. 20MHz clock.
baud rate=9600
each character is 16 bit wide
I calculated the 3.5 character time as (16/9600)*3.5 = 5.8mSec
I prescaled the frequency 20 MHz into F=20,000,000/(4*256) i.e divide_by_256.
F=19531.25
1/F =.0512 mSec, timer 2 increment rate.
So in order to get 5.8 msec, I set the count as 5.8/.0512 = 113
I set the post scale as 1.
I have used the following function
Code: | setup_timer2(TMR_DIV_BY_256,113,1); |
but i found that all the parameters are for setup_timer_2() not for setup_timer2() for dsPIC30f3013.
How could I set the timer exactly for 5.8 sec using the function setup_timer2(); ?
In one example I found
Code: | setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8, 10000); |
but could not understand the significance of 10000, is it the count or post scale value?
Any help would be appreciated, thanks in advance. _________________ I dream world peace |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Sat Jan 12, 2013 4:43 am |
|
|
Start with three things:
Manual
The header file for the PIC
The data sheet
Key thing is that on these later PIC's, the timers are much more flexible, which is why 90% of the configuration values are no longer specific to one timer.
All the timers support /1,/8,/64, and /256 prescalers.
All _even numbered_ timers support 16 or 32bit operation
From the manual:
"setup_timerX(mode,period)"
"Period is an optional 16 bit integer parameter that specifies the timer period. The default value is 0xFFFF"
Now from data sheet, identify that the clock for the timer prescaler is Fosc/2 (different from the older PIC's where it is Fosc/4).
So for 5.8mSec, you need a count of (20000000*0.0058)/2 = 58000
So:
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1,57999);
Remember the period value is one less than the count the timer will generate. It counts from 0.
However a lot more comments.
If you are using MODBUS serial, it does not send 16bit data as one character. The 'character' is _11bits_ long, One start bit, 8 data bits, one parity bit, and one stop bit. So your timing is 'wrong'. A sixteen bit transmission is two characters, not one.
Then the pause required won't start till the hardware transmit buffer is empty. If you have sent a packet, you are going to have to test the TBE bit, and then the TRMT bit, to verify both the buffer, and the shift register have emptied, before starting your delay.
Finally, the 3.5byte time delay, is a _minimum_. You can exceed it a little, provided you don't mind loosing a little speed.
Best Wishes |
|
|
|
|
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
|