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.

PIC help

Status
Not open for further replies.

hondacivic

New Member
I am building a project for a college electronics class. I am using a
PIC16F873A. I am using a light to frequency converter that provides a square output that is proportional to light level. I need to sample each pulse output over appoximately 5 seconds. I then need to count the the peaks of the samples. The project I am working on is a pulse monitor. It would take a detect a human pulse and transmit the heart rate to a monitor. I am new to the PIC and don't know where to start. i have read an article, but I really don't understand how he done a project like this. He talks about the pulse counts overflowing. If you would like to read the article, here is a link.**broken link removed** and **broken link removed**. Any help in understanding this will be greatly appreciated. Thanks.
 
I am building a project for a college electronics class. I am using a
PIC16F873A. I am using a light to frequency converter that provides a square output that is proportional to light level. I need to sample each pulse output over appoximately 5 seconds. I then need to count the the peaks of the samples. The project I am working on is a pulse monitor. It would take a detect a human pulse and transmit the heart rate to a monitor. I am new to the PIC and don't know where to start. i have read an article, but I really don't understand how he done a project like this. He talks about the pulse counts overflowing. If you would like to read the article, here is a link.**broken link removed** and **broken link removed**. Any help in understanding this will be greatly appreciated. Thanks.

it's not an easy project to start with if you're a beginner
 
In the class we have done a few programs programming a PIC with Microcode Studio. We have done a voltmeter and displayed it on an LCD. We have also done a temperature sensor, and communicated to a computer using the COM1 port. I am not totally new, just don't have any experience using the timer and the overflow.

I oonly have two weeks left to finish the program and build the project, hopefully I will figure out something.
 
hi,

>> I am using a light to frequency converter that provides a square output that is proportional to light level.
As you may know, there are number of ready made devices that will give an output pulse rate proportional to light intensity.

>> I need to sample each pulse output over appoximately 5 seconds.
Using a counter in the PIC, to accumulate the pulses from the L2F[ Light to Frequency] over a 5 second period is not difficult to do.

As the human heart beat rate is typically between 50 and 200 beats/min, so over a 5 sec period,
you will only get about 4 to 16 pulses to count, thats a very low resolution?

You could use a polling method on one of the PIC's port pins to detect and accumulate the counts in a byte register.
Use a delay loop for 5 seconds.[ there is a N sec delay loop in a recent post]

To send the result to a PC monitor, you could use a RS232 link from the PIC to the PC.

>> I then need to count the the peaks of the samples.
Its this sentence I dont understand, ie: 'the peaks' , as the signal is a square wave?

>> The project I am working on is a pulse monitor. It would take a detect a human pulse and transmit the heart rate to a monitor.
Do you mean a PC type 'monitor' or a 'heart monitor' display?

If I had to count a rate as low as you require and display it on a PC, I would
connect the L2F device directly to the PC's parallel port and use the PC program to do all the work!

Its also possible to use a spare RS232 handshaking line to capture the pulses into a PC.
 
ericgibbs said:
hi,



>> I need to sample each pulse output over appoximately 5 seconds.
Using a counter in the PIC, to accumulate the pulses from the L2F[ Light to Frequency] over a 5 second period is not difficult to do.

As the human heart beat rate is typically between 50 and 200 beats/min, so over a 5 sec period,
you will only get about 4 to 16 pulses to count, thats a very low resolution?

The light to frequency converter always has an output. I am geting a square signal in the KHz. So I need to sample each pulse to get a sample. I then need to detect the peaks of the level which should indicate a heartbeat. If I would only get an output of a pulse with each heartbeat it would make it so much better.

You could use a polling method on one of the PIC's port pins to detect and accumulate the counts in a byte register.
Use a delay loop for 5 seconds.[ there is a N sec delay loop in a recent post]

To send the result to a PC monitor, you could use a RS232 link from the PIC to the PC.

>> I then need to count the the peaks of the samples.
Its this sentence I dont understand, ie: 'the peaks' , as the signal is a square wave?

It will be transmitted to the monitor via RF and displayed on an LCD.
 
hi honda,

Like to help, but your description is not very clear.

>> The light to frequency converter always has an output. I am geting a square signal in the KHz. So I need to sample each pulse to get a sample. I then need to detect the peaks of the level which should indicate a heartbeat. If I would only get an output of a pulse with each heartbeat it would make it so much better

If you already have the heart beat signal, why not just amplify and square it up and count that pulse over a short period?
say 6 secs rather than 5 secs [ it makes the sums easier]

Why do you need the L2F device?

Obviously I appear to missing something?

Regards
 
The light to frequency converter outputs a square signal that is propotional to light. The output changes with change in light. As blood is pulsed through the body the amount of light absorbed by the blood changes. I need to measure the changes in the outputed pulses from the light to frequency converter. I a lot of research as to how to detect a human pulse, and this is the only way I could find. I don't know if it is the best way to do this project, but I am trying. As for the links, they should work. If not it is at circuitcellar.com. It is under archives. Issue #173 and 174 under THE BENCH section. Any further help is greatly appreciated. Thanks.
 
Your links do indeed work. Must have been a glitch earlier.

Having now looked at the article I can see what your doing. In effect, what you have to do is convert the frequency back to a voltage and then convert that voltage into a pulse rate.

To convert back to a voltage, the author of the article uses a 32Hz sample rate. I assume in that case that the maximum frequency encountered would be 30*256Hz or approx 7.5KHz. To do this you need to setup a timer to produce a 32Hz interrupt and use RB0 to count pulses.

Your ISR code would do something like,
Code:
if RBIF=1
   Inc IntCount
   RBIF=0
Endif
if TMR1IF = 1
   Count=IntCount
   IntCount=0
   NewValue=true
   TMR1IF=0
Endif

Whenever NewValue becomes true (set) then count will be your converted voltage.

To convert this voltage into a pulse I would keep a running average of the voltage and count the number of times it goes above and below it.

You don't state what language you are using or what speed your pic is running at so it's difficult to give more accurate code. Hopefully the pseudo code above will give you some ideas.

Mike.
 
You don't state what language you are using or what speed your pic is running at so it's difficult to give more accurate code. Hopefully the pseudo code above will give you some ideas.

Mike.[/QUOTE]

I am doing the initial tests on a PIC16f877a using a mikro electronika developement board. My teacher is giving me a PIC12F675 using a 4MHz crystal. I am using assembly language or PicBasic. Thanks for your help and finding the article. I am sorry the link didn't work and sending you there the hard way. Thanks so much.
 
In assembler, to get a 32mS interrupt you could use the special events trigger with Timer1.

This should work,
Code:
		movlw	(b'10'<<T1CKPS0|0<<T1OSCEN|0<<NOT_T1SYNC|0<<TMR1CS|1<<TMR1ON)
		movwf	T1CON			;enable timer 1 with prescaler 4
		movlw	(0<<CCP1X|0<<CCP1Y|b'1011'<<CCP1M0);	enable special event trigger on CCP1
		movwf	CCP1CON
		movlw	high(.4000000/4/.32/4)	;4000000 = crystal speed
		movwf	CCPR1H			;set CCPR1=1/32 seconds
		movlw	low(.4000000/4/.32/4)
		movwf	CCPR1L
		bsf	STATUS,RP0
		bsf	PIE1,CCP1IE		;enable CCP1 interupt
		bcf	STATUS,RP0
		movlw	(1<<GIE|1<<PEIE|0<<T0IE|0<<INTE|0<<RBIE|0<<T0IF|0<<INTF|0<<RBIF)
		movwf	INTCON			;enable Peripheral interupts and global ints

This will give you a CCP1 interrupt every 31.25mS.

Your ISR should be something like,
Code:
interrupt	movwf	int_work;	Save Context
		swapf	STATUS,W
		movwf	int_status
		bcf	STATUS,RP0;	make sure we are in bank 0
		bcf	STATUS,RP1
		btfss	INTCON,RBIF
		goto	NotRB0
		incf	IntCount,F
		bcf	INTCON,RBIF
NotRB0		btfss	PIR1,CCP1IF
		goto	NotTimeUp
		movfw	IntCount
		movwf	Count
		clrf	IntCount
		bsf	Flags,NewTime
		bcf	PIR1,CCP1IF	;reset special event trigger interupt
NotTimeUp	swapf	int_status,W	;restore context
		movwf	STATUS
		swapf	int_work,F	;swap to file
		swapf	int_work,W	;swap to work
		retfie

Have a play around with the above and see if you can get something working.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top