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.

Adc Pic16f877a

Status
Not open for further replies.
derrick826 said:
thanks eric.... i owe you a lot really! i think i will have to do more research and post my problems later on

hi derrick,
Look at these sites.

The audacity is a great program for audio work, its free, try it.

**broken link removed**
**broken link removed**
http://www.oscilloscope-lib.com/
 
those are the programs (something like GUI) that display on the pc screen using the soundcard. Eric, it seems that the project i'm doing has a bit of limitation which is using either a serial port or a paralel port, my preferably serial port.

the https://www.oscilloscope-lib.com/ is quite useful, i have also downloaded this morning. thanks a bunch
 
derrick826 said:
those are the programs (something like GUI) that display on the pc screen using the soundcard. Eric, it seems that the project i'm doing has a bit of limitation which is using either a serial port or a paralel port, my preferably serial port.

the https://www.oscilloscope-lib.com/ is quite useful, i have also downloaded this morning. thanks a bunch

hi,
If you have free choice in the method of capturing analog signals, look at the fast, 8 bit or 12 bit parallel ADC convertors.
These can be connected to the PC's parallel port, many thousands of reading/sec can be taken and displayed.
 
hi eric,
i'm not allowed to use any external ADC , only the internal ADC of the pic, what i had in mind is that maybe when i'm sampling a high freqeuncy sinewave, i will have to store the converted values into a RAM , once it reached to a max amount in the ram, i will send it to the pc. i have calculated my sampling rate and it is more than can be trasmitted using rs232. I haven't checked about the parallel yet.can this eliminate my problem regarding on to low baudrate to send a high sampling data?
 
derrick826 said:
hi eric,
i'm not allowed to use any external ADC , only the internal ADC of the pic, what i had in mind is that maybe when i'm sampling a high freqeuncy sinewave, i will have to store the converted values into a RAM , once it reached to a max amount in the ram, i will send it to the pc. i have calculated my sampling rate and it is more than can be trasmitted using rs232. I haven't checked about the parallel yet.can this eliminate my problem regarding on to low baudrate to send a high sampling data?

It's still very limited. If you check EPE, they did a PIC 'scope' a few years OK, which used the internal PIC A2D and wrote to a 2K static RAM chip, then this was transferred via the parallel port when full. But it's a fairly low spec.

More recently, earlier this year, they did a higher spec version. This uses a MAX118 external A2D, writing directly to a static RAM under PIC control. When full the PIC then transfers the contents to the PC via a serial link. This version gives a 40KHz sampling speed!.
 
wow, but for now as a learner i think i will just make a low spec frequency scope first... start from a beginner is much better for now.
 
i nigel, i would like to ask how to create an additional RX pin so that my PIC will have 2 RX pin or more? i followed ur tutorial using the portB 7,6 as a TX and RX .. and by using the simulation of the PIC simulator IDE, i couldn't see any character transmitted on the screen even though the character's has been received. this time i put AN0 as my RX pin and to indicate that there's LED lighted up if the character is being received but the porgramme is not working. below are my codes.. can you help me check if there's anything which i miss out??


list p=pic16f877, f=inhx8m
include <P16F877.INC>
__config _CP_OFF & _PWRTE_ON & _HS_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF

ERRORLEVEL -302 ;Suppress bank warning




cblock h'20'
Xmit_Byte ;Equ 0x20 ;holds byte to xmit
Rcv_Byte ; Equ 0x21 ;holds received byte
Bit_Cntr ; Equ 0x22 ;bit counter for RS232
Delay_Count ; Equ 0x23 ;delay loop counter
endc

ORG 0x00
call RECEIVE ; receive using pin A0

int ORG 0x04
goto int

RECEIVE
CALL SER_INIT
CALL Rcv_RS232
RETURN

SER_INIT
BSF STATUS, RP0 ;select bank 1
; BCF TRISB, 6 ;set B6 as an output
CLRF TRISB ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; i set as trisb
BSF TRISA,0 ;set A0 as an input ;;;;;;;;;;;;;;; i set as trisA
BCF STATUS, RP0 ;select bank 0
; BSF PORTB, 6 ;set B6 high
RETURN



Rcv_RS232 BTFSC PORTA, 7 ;wait for start bit
GOTO Rcv_RS232
CALL Start_Delay ;do half bit time delay
BTFSC PORTA, 7 ;check still in start bit
GOTO Rcv_RS232
MOVLW 0x08 ;set up to read 8 bits
MOVWF Bit_Cntr
CLRF Rcv_Byte
Next_RcvBit CALL Bit_Delay
BTFSS PORTA, 7
BCF STATUS , C
BTFSC PORTA, 7
BSF STATUS , C
RRF Rcv_Byte , f
DECFSZ Bit_Cntr , f ;test if all done
GOTO Next_RcvBit
CALL Bit_Delay
MOVF Rcv_Byte, W
MOVWF PORTB ;; display on leds on what data received
RETURN

Start_Delay MOVLW 0x3C
MOVWF Delay_Count
Start_Wait NOP
DECFSZ Delay_Count , f
GOTO Start_Wait
RETURN

Bit_Delay MOVLW 0x78
MOVWF Delay_Count
Bit_Wait NOP
DECFSZ Delay_Count , f
GOTO Bit_Wait
RETURN

END
 
On a quick glance it looks like you're not setting the pin as a digital one, by default AN0 is an analogue input - you MUST set it to be a digital input if you want to use it as one.
 
Nigel Goodwin said:
On a quick glance it looks like you're not setting the pin as a digital one, by default AN0 is an analogue input - you MUST set it to be a digital input if you want to use it as one.

i have already assign into digital by assigning all AN0-AN7 digital I/O by applying h'06' to ADCON1 but it still didn't work.. i used the software UART simulation to input a character into AN0 for testing , one of the simlation tools for PIC simulator IDE.

list p=pic16f877, f=inhx8m
include <P16F877.INC>
__config _CP_OFF & _PWRTE_ON & _HS_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF

ERRORLEVEL -302 ;Suppress bank warning




cblock h'20'
Xmit_Byte ;Equ 0x20 ;holds byte to xmit
Rcv_Byte ; Equ 0x21 ;holds received byte
Bit_Cntr ; Equ 0x22 ;bit counter for RS232
Delay_Count ; Equ 0x23 ;delay loop counter
endc

ORG 0x00
call RECEIVE ; receive using pin A0

int ORG 0x04
goto int

RECEIVE
CALL SER_INIT
CALL Rcv_RS232
RETURN

SER_INIT
BSF STATUS, RP0 ;select bank 1
; BCF TRISB, 6 ;set B6 as an output
MOVLW h'06'
MOVWF ADCON1
CLRF TRISB ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; i set as trisb
BSF TRISA,0 ;set A0 as an input ;;;;;;;;;;;;;;; i set as trisA
BCF STATUS, RP0 ;select bank 0

; BSF PORTB, 6 ;set B6 high
RETURN



Rcv_RS232 BTFSC PORTA, 0 ;wait for start bit
GOTO Rcv_RS232
CALL Start_Delay ;do half bit time delay
BTFSC PORTA, 0 ;check still in start bit
GOTO Rcv_RS232
MOVLW 0x08 ;set up to read 8 bits
MOVWF Bit_Cntr
CLRF Rcv_Byte
Next_RcvBit CALL Bit_Delay
BTFSS PORTA, 0
BCF STATUS , C
BTFSC PORTA, 0
BSF STATUS , C
RRF Rcv_Byte , f
DECFSZ Bit_Cntr , f ;test if all done
GOTO Next_RcvBit
CALL Bit_Delay
MOVF Rcv_Byte, W
MOVWF PORTB ;; display on leds on what data received
RETURN

Start_Delay MOVLW 0x3C
MOVWF Delay_Count
Start_Wait NOP
DECFSZ Delay_Count , f
GOTO Start_Wait
RETURN

Bit_Delay MOVLW 0x78
MOVWF Delay_Count
Bit_Wait NOP
DECFSZ Delay_Count , f
GOTO Bit_Wait
RETURN

END
 
You appear to have a confusing number of incorrect calls and returns, with Ser_Init called from within the receive routine - it should only be called once, in the initialisation section of the program. I suggest you check the structure of my tutorials.

As it stands the program will do nothing but crash as the stack underflows.
 
Nigel Goodwin said:
You appear to have a confusing number of incorrect calls and returns, with Ser_Init called from within the receive routine - it should only be called once, in the initialisation section of the program. I suggest you check the structure of my tutorials.

As it stands the program will do nothing but crash as the stack underflows.

Yeap, had been corrected... i followed the sequence which i think is perfect but still no results displayed on the software UART simulation interface using the PIC simulator IDE program... i wonder why?


list p=pic16f877, f=inhx8m
include <P16F877.INC>
__config _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF

ERRORLEVEL -302 ;Suppress bank warning




cblock h'20'
Xmit_Byte ;Equ 0x20 ;holds byte to xmit
Rcv_Byte ; Equ 0x21 ;holds received byte
Bit_Cntr ; Equ 0x22 ;bit counter for RS232
Delay_Count ; Equ 0x23 ;delay loop counter
endc

ORG 0x00

CALL SER_INIT ; receive using pin A0
again
CALL Rcv_RS232
goto again

int ORG 0x04
goto int



SER_INIT
BSF STATUS, RP0 ;select bank 1
; BCF TRISB, 6 ;set B6 as an output
MOVLW h'06'
MOVWF ADCON1
CLRF TRISB ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; i set as trisb
BSF TRISA,0 ;set A0 as an input ;;;;;;;;;;;;;;; i set as trisA
BCF STATUS, RP0 ;select bank 0

; BSF PORTB, 6 ;set B6 high
RETURN



Rcv_RS232
BTFSC PORTA, 0 ;wait for start bit
GOTO Rcv_RS232
CALL Start_Delay ;do half bit time delay
BTFSC PORTA, 0 ;check still in start bit
GOTO Rcv_RS232
MOVLW 0x08 ;set up to read 8 bits
MOVWF Bit_Cntr
CLRF Rcv_Byte
Next_RcvBit
CALL Bit_Delay
BTFSS PORTA, 0
BCF STATUS , C
BTFSC PORTA, 0
BSF STATUS , C
RRF Rcv_Byte , f
DECFSZ Bit_Cntr , f ;test if all done
GOTO Next_RcvBit
CALL Bit_Delay
MOVF Rcv_Byte, W
MOVWF PORTB ;; display on leds on what data received
RETURN

Start_Delay MOVLW 0x0C
MOVWF Delay_Count
Start_Wait NOP
DECFSZ Delay_Count , f
GOTO Start_Wait
RETURN

Bit_Delay MOVLW 0x18
MOVWF Delay_Count
Bit_Wait NOP
DECFSZ Delay_Count , f
GOTO Bit_Wait
RETURN

END
 
derrick826 said:
Yeap, had been corrected... i followed the sequence which i think is perfect but still no results displayed on the software UART simulation interface using the PIC simulator IDE program... i wonder why?

Personally I never use simulators, I don't consider them reliable enough - unless they work EXACTLY as the real world, and they don't.

You should also post code surrounded by the 'code' tags, this keeps the formatting correct, I would also suggest you do what I do at the beginning of the program, it's easer to read and makes problems less likely.


Code:
list	p=pic16f877, f=inhx8m		
include <P16F877.INC>
	__config _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF	
			
   ERRORLEVEL      -302    ;Suppress bank warning
			
			


			cblock h'20'
	        Xmit_Byte   ;Equ  0x20        ;holds byte to xmit
            Rcv_Byte    ; Equ  0x21        ;holds received byte 
            Bit_Cntr    ; Equ  0x22        ;bit counter for RS232
            Delay_Count ; Equ  0x23        ;delay loop counter
			endc
			
           ORG 0x00
           GOTO Main

	int	    ORG 0x04
	                RETFI
	   
Main			CALL SER_INIT    ; receive using pin A0


again	    
			CALL Rcv_RS232
			goto  again
			
			



SER_INIT
            BSF     STATUS, RP0           ;select bank 1
           ; BCF     TRISB, 6              ;set B6 as an output
	MOVLW  h'06'
      MOVWF  ADCON1
	CLRF    TRISB                 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; i set as trisb
            BSF     TRISA,0              ;set A0 as an input ;;;;;;;;;;;;;;; i set as trisA
            BCF     STATUS, RP0           ;select bank 0
		
           ; BSF     PORTB, 6              ;set B6 high
            RETURN
 
i'll try to burn the codes into the pic to test if it works. in your tutorial, it is possible to assign any pins as a RX or a TX pin except for portc,7 and portc,6 ?
 
derrick826 said:
i'll try to burn the codes into the pic to test if it works. in your tutorial, it is possible to assign any pins as a RX or a TX pin except for portc,7 and portc,6 ?

Yes, subject to any individual pin restrictions - such as RA4 that tends to be an open-collector output.
 
derrick,
Ref my PM reply of a few minutes ago.

Yeap, had been corrected... i followed the sequence which i think is perfect but still no results displayed on the software UART simulation interface using the PIC simulator IDE program... i wonder why?

You are not transmitting to the software uart within the program.
Just tested your program on the Sim with the software uart as the transmitter and the transmitted character appears on PORTB as per the program. It works in simulation.

As a side issue, there is no point in sending members PM's at the same time as you are posting. Its confusing and timewasting;)
 
ok eric,
as in the pm

what is the possiblities of the codes to be changed if i want to change to a 20hz ocs and a 115200 baudrate?

i used 0x09 for my delay_count in the start_delay and
0x05 for my delay_count in my bit_delay. Is it possible?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top