Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Improve System Sampling Frequency

Status
Not open for further replies.

lowkb

New Member
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....
 
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!.
 
Nigel Goodwin said:
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!.

Hi Nigel,

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?
 
lowkb said:
Nigel Goodwin said:
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!.

Hi Nigel,

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?

I don't know?, you haven't posted enough code, nor answered any of the previous questions!. But 9600 baud will transfer a maximum of 960 bytes a second.

My tutorials sample considerably slower than that, with extra delays added.
 
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?
 
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.
 
Nigel Goodwin said:
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.


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.
 
lowkb said:
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.

The 16F84 is a VERY old PIC, and essentially obselete, it was replaced by the modern, higher spec, cheaper, 16F628 last century!.

The 16F628 has a hardware USART, and would make fast RS232 no problem.
 
Status
Not open for further replies.

Latest threads

Back
Top