View previous topic :: View next topic |
Author |
Message |
pulurumbuluruciu
Joined: 06 Nov 2013 Posts: 27
|
Running UART with external clock |
Posted: Wed Nov 06, 2013 10:22 am |
|
|
Hello Forum.
Trying to build a SIM emulator and the documentation says that the SIM must follow the external clock of the interface. My first thought was to use UART, but how can i use UART with a external clock? Also a serial byte must be read/write every 372 clocks to interpret the data correctly. Any thoughts?
I'm running on 18f14k50 on 32M speed on PCH 4.124. Thank you very much. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Wed Nov 06, 2013 11:04 am |
|
|
First thought is that you should post a link to whatever documentation is related to 'SIM emulator'. I can't be the only guy here who has no clue what it is....
2nd thought..syncing every 372 clocks is easy as is the reading/writing, depending on the real speed of the I/O operations
jay |
|
|
pulurumbuluruciu
Joined: 06 Nov 2013 Posts: 27
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Wed Nov 06, 2013 11:57 am |
|
|
I'd say, you probably should look for a PIC that has a USART, rather than UART. This then allows data transfers to be synchronised to an external clock. Then triggering the transmission after 'x' clocks, would be easily done using the CCP. I'm fairly sure the 14K50 does have a USART, so you should be able to select 'SYNC_SLAVE' in the #use_rs232, which will then clock bits on the external clock. Start the transmission after 371 clocks, and the data will clock out on the next clock.
Best Wishes |
|
|
pulurumbuluruciu
Joined: 06 Nov 2013 Posts: 27
|
|
Posted: Wed Nov 06, 2013 12:40 pm |
|
|
Indeed it has a USART, but how can i make the CCP trigger at 372? using timer0 or timer1? How can i make the timer interrupt exactly at 372 external pulses? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu Nov 07, 2013 1:15 am |
|
|
You'd want it to trigger one pulse earlier. The data starts transferring on the _next_ clock after the UART register is loaded. Hence my 371.
You'd need to feed the clock into two pins on the PIC, The USART synchronous clock input, and the CCP timer input (for count modes, normally Timer1). Setup the timer to count using the external clock.
Then program the CCP register to 371, and reset the timer. 371 clocks later the CCP will trigger, and you load the USART register.
Best Wishes |
|
|
|