![]() |
![]() |
![]() |
|
|
|||||||
| General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion? |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
I have use a controller for my system which reads an ADC and send to the PC via RS-232.
However, i found out that the sampling frequency is very low and i want it to be higher. I cant think of a way changing the time taken for the interface to do all the nesscessary stuff. seems like im quite stuck. hope you guys can help... Below is my code attached for the ADC read and RS232 transmit subroutine. ;****** ADC Routine adc_value bcf PORTB,cs clrf adc_buffer movlw d'8' movwf adc_count loop2 btfsc PORTB,dataout bsf STATUS,C btfss PORTB,dataout bcf STATUS,C bsf PORTB,clk ;clock high NOP bcf PORTB,clk ;clock low rlf adc_buffer,f decfsz adc_count,f goto loop2 bsf PORTB,cs return ;***** RS 232(2) Transmit Xmit_rs232 movwf Xmit_Byte movlw 0x08 movwf Bit_Cntr bcf ser_port2,ser_out2 call bit_delay ser_loop2 rrf Xmit_Byte , f ;send one bit btfss STATUS , C bcf ser_port2,ser_out2 btfsc STATUS,C bsf ser_port2,ser_out2 call bit_delay decfsz Bit_Cntr,f ;test if all done goto ser_loop2 bsf ser_port2,ser_out2 ;SEND STOP BIT call bit_delay return bit_delay movlw 0x18 movwf Delay_Count bit_wait nop decfsz Delay_Count , f goto bit_wait return Hope you all can help....
__________________
************************************ Hello All..... ************************************ |
|
|
|
|
|
|
(permalink) |
|
Firstly, you don't mention how fast it currently is, and you don't mention how fast you want to make it - or even how fast the serial port needs to run.
Also, you haven't posted the code that governs the sampling rate, so we've no idea what it might be!. If you post code, please use the Code button to surround the text, this keeps the formating intact. You might also like to look at my PIC tutorials, which will probably explain what you need!. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
was impressed by your tutorial site... i think i know the solution to my problem. I saw on your site for RS232 the holding to 104us of the rs232 signal. this is for baud rate of 9600. if i want to restrict or reduce the holding time, i'll just hold it such that my receiver baud rate increases to suit it. is this correct?
__________________
************************************ Hello All..... ************************************ |
||
|
|
|
|
|
(permalink) | ||
|
Quote:
My tutorials sample considerably slower than that, with extra delays added. |
|||
|
|
|
|
|
(permalink) |
|
Hi NIgel,
Pardon me... Was anxious to see the results... Din work though... I shall now try to explain more detail in view of to get an answer. Ok im using an adc to read an analog voltage, it is interface by a microcontroller. i then output using RS232 protocol so that i can read on my pc. i used code as follows and found that the rs232 takes a long time (the 8bits of 104us delay) and this slows down my sampling frewuency of the adc. my program is as follows: Code:
;************Equates
; *** Port B Declaration
ser_port equ PORTB
ser_out equ 0x06 ;Bank Select Issue
cs equ 0x03 ;ADC handshake lines
dataout equ 0x04
clk equ 0x05
; *** Port A Declaration
ser_port2 equ PORTA
ser_out2 equ 0x01
;***********************Program
org 0x0000
clrf PORTA
clrf PORTB
call main
main
call initialise
loop
call adc_value
movf adc_buffer,w ; store the ADC value into register
call Xmit_rs232 ; to transmit serial interface
goto loop
;******************* Initialise Routine
initialise
bsf STATUS,RP0 ;select bank 1
movlw b'01111000' ;set PORTA
movwf TRISA
movlw b'00010000' ;set portB
movwf TRISB
bcf STATUS,RP0 ;select bank 0
bsf PORTB,ser_out ;make B6 High
bsf PORTA,ser_out2
return
;****************** ADC Routine
adc_value
bcf PORTB,cs
clrf adc_buffer
movlw d'8'
movwf adc_count
loop2
btfsc PORTB,dataout
bsf STATUS,C
btfss PORTB,dataout
bcf STATUS,C
bsf PORTB,clk ;clock high
NOP
bcf PORTB,clk ;clock low
rlf adc_buffer,f
decfsz adc_count,f
goto loop2
bsf PORTB,cs
return
;**************** ADC Routine End
;************ RS 232(2) Transmit
Xmit_rs232
movwf Xmit_Byte ;move W to Xmit_Byte
movlw 0x08 set 8 bits out / bit_cntr is loaded
movwf Bit_Cntr
bcf ser_port2,ser_out2
call bit_delay
ser_loop2
rrf Xmit_Byte , f ;send one bit
btfss STATUS , C
bcf ser_port2,ser_out2
btfsc STATUS,C
bsf ser_port2,ser_out2
call bit_delay
decfsz Bit_Cntr,f ;test if all done
goto ser_loop2
bsf ser_port2,ser_out2 ;SEND STOP BIT
call bit_delay
return
bit_delay
movlw 0x18
movwf Delay_Count
bit_wait
nop
decfsz Delay_Count , f
goto bit_wait
return
end
i measure the time between adc CS line period. it reads 1.4ms. 715Hz then, that is the sampling frequency i supposed. i saw the program and notice that RS232 subroutine take the most time(all the 104us). i hope to reduce it. this will increase my system sampling frequency. i want to increase the sampling frequency to about few KHz say 4k? is it possible? anyways to do it?
__________________
************************************ Hello All..... ************************************ |
|
|
|
|
|
|
(permalink) |
|
You have no extra delays in your system, so the main restriction is the RS232 transmission time. The only solution is to increase the RS232 speed, which PIC are you using? - some have hardware USART's, which makes going fast easier. As it stands, with the software RS232, you could increase the speed four fold by using 38400 baud, by simply reducing the bit delay to 26uS (1/4 of 104uS) - you may also need to trim it slightly, as the faster you go the more effect the call and return times have. Going faster still is possible, but again, you need to be careful over your timing - the faster you go, the more effect single instruction have.
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
Thanks Nigel for your prompt response. Im using PIC16F84A. i tried to increase the baud as well but miss out the single insruction timing that could have taken effect. will consider them n try them out again. Thanks alot for the help. Appreciate deeply.
__________________
************************************ Hello All..... ************************************ |
||
|
|
|
|
|
(permalink) | |
|
Quote:
The 16F628 has a hardware USART, and would make fast RS232 no problem. |
||
|
|
|