HighSpeed A/D and Baud Rates
Long time reader first time poster.
Right now I am running a PIC 16F688 at 20Mhz. I'm taking the AD of a 1 Khz 50% duty cycle signal and sending it at 1250000 baud out to a serial terminal on a PC. Yes, my 232 converter is capable of this speed.
Could someone help me with the math involved in the approximate time it is taking to do a conversion and then send the data. This is what I have come up with:
1/1250000 = .8 us per bit
Im sending HSEROUT [ bin ADRESH,Bin ADRESL," "] Is this 3 bytes of data total or 6 bytes?
I seemed to have read somewhere in PBP manual that serout can send up to 65535 dec which would be a word.
Assuming its 6 bytes of data and a stop and start bit for each word for the serial com gives 6*18 + 3*2 = 54 bits per result sent.
54*.8 us = 43us
The AD conversion is around 20 us according to datasheet.
Now is this conversion happening at the same time as the HSEROUT is? Or is it 20 us for the conversion and then 43 us to send it? I think they can happen at the same time.......
Ok, now the 1 Khz square wave has a duty cycle of 1 ms
1ms/43us = around 23 samples per duty cycle. I seem to get around 4 or 5.
Can anyone enlighten me on where the extra ~800 something us are going each cycle? Or how my math is wrong.
Thanks!
Here is my code:
'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 1/12/2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
@ __config _HS_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF
DEFINE OSC 20
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 0 ' 1250000 @ 20MHz
GoDone VAR ADCON0.1
ADCON1 = %00100000 ; Fosc/32
ADCON0 = %10010101 ;Right Justified, ch5(AN5), A/D on
loop1:
GoDone = 1 ;start conversion
loop2:
if GoDone = 0 Then ; is conversion done?
HSEROUT [ bin ADRESH,Bin ADRESL," "] ;spit out answer
else
goto loop2 ; go back and check if A/D is done if it wasn't before
endif
goto loop1 ;do forever