Schoolproject

Forum for problems or queries regarding other Flowcode Components. Eg LEDs, Switches, LCD, Gfx LCD etc

Moderators: Benj, Mods

Post Reply
Diet
Posts: 9
Joined: Tue Feb 23, 2010 8:41 am
Contact:

Schoolproject

Post by Diet »

Hey, Matrix

The intention of our project is to build a heart rate monitor.
We already build the hardware for detecting hartpulses. And this works.

On input RA0. We count the positive flanks of the heartbeat signal.
And every 10 seconds we multiply the heartbeats with 6.
For example: we measured 12 heart pulses during 10 secondes.
If we multiple 12 x 6. We have a heartbeat of 120 beats per minute(=BPM)

Now, we have the heart beats per minute. We willl show it on a 7 segementen display
(every 10 seconds) and send this data to the PC. Where we monitoring the data.

Can you help us with the program? We have already made a second counter buth we
have problems with showing the data on 7 segmenten display every 10 seconds and send it to the PC

Image

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Schoolproject

Post by Benj »

Hello

There are a couple of ways of connecting your hardware to a PC. One way is to use RS232 or the USB232 E-Block to convert UART data into a PC compatible format that will come in via a port emulator such as hyperterminal.

Another way is to use the USB components in Flowcode along with the EB055 USB E-Block and a USB enabled microcontroller.

7 segment displays are a litlle tricky to control as you can only have one of the digits on at any one time. It is normally best to use a timer interrupt that cycles through the digits outputting the value. An example of this is available from our main examples download available from the Flowcode product page.

Diet
Posts: 9
Joined: Tue Feb 23, 2010 8:41 am
Contact:

Re: Schoolproject

Post by Diet »

Hey Benj,

Thanks for helping us so quickly.
We used TMR0 overflow for updating the values.
On RAO we count the heartpulses. The value "number" counts up if a heart pulse
is detected. If 10 seconds are passed the value (BPM) calculate the beats per minute.
If we have 6 heart pulses on port RA0 during 10 seconds the BPM = 36 beats per minute.
Buth we can't get the value (BPM) on the 3 times 7 segmenten display using macro LED7seg4(0).
The macro can't see the difference between honderds, douzens and units. So how can we get the value
for example 120 bpm on the 7 segmenten display ? And how can we send data from our microcontroller using max232
to the com-poort of our PC? For our program (see attachment).

Greetz, Dieter
Attachments
3 segmenten V2.fcf
(10 KiB) Downloaded 538 times
3 segmenten V2 Macro - UPDATE_VALUES.JPG
(36.9 KiB) Downloaded 7398 times
3 segmenten V2 - Main.JPG
(32.58 KiB) Downloaded 7399 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Schoolproject

Post by Benj »

Hello

Firstly you will probably need to move the 7segment outputs and the while 1 loop from your interrupt Update_Values macro.

In your interrupt you should check if the Heartbeat variable is set and if it is then increment a count value.

To seperate the count value into your individual 7 seg variables you would do something like this.

seg0 = count MOD 10

seg1 = count / 10
seg1 = seg1 MOD 10

seg2 = count / 100
seg2 = seg2 MOD 10

etc

KeithSloan
Posts: 114
Joined: Fri Jul 27, 2007 10:50 am
Been thanked: 1 time
Contact:

Re: Schoolproject

Post by KeithSloan »

Do you have a better image of the circuit for the heart beat monitor & construction?

I am not able to make out component values in the image you posted and others maybe interested in your project.

Thanks Keith

Diet
Posts: 9
Joined: Tue Feb 23, 2010 8:41 am
Contact:

Re: Schoolproject

Post by Diet »

Hey Benj,

I used your idea in my code. Now we can see after 10 seconds the beats per minute on the 3 x 7segemtendisplay ( see attachment for the program).
The intention is to show the beats per minute after 10 seconds on the displays for a few seconds and write this value to the computer and restart this process automatically again. So the computer gets every 10 seconds the value ( BPM). Now, we switched from chip. First we used the PIC16F84A buth now we use
the PIC16F88 because this chip has UART on board. In my code i tried to use the RS232(0) macro for sending the beats per minute to the computer. Where we monitore the average beats per minute. Buth we have problems using this macro. Can you help us out?
Thanks for the support, Benj

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Hey Keith,

Here is a better image of the circuit for you.
Image

Components:

• LED3 = High intensity led, at least 1000 mcd.
• LDR1 = light dependent resistor;
• ( resistance in the dark = 1M Ohm and resistance in light = circa 300 Ohm)
• R1 = 100K Ohm
• R2 = 1K Ohm
• R3 = 47K Ohm
• R4 = 10K Ohm
• R5 = 220 Ohm
• R6 = 1K8 Ohm
• R7 = 220 Ohm
• P1 = 100K Ohm (potentiometer)
• P2 = 100 K Ohm (potentiometer)
• C1 = 470nF
• IC1 = LM358 ( comporator).


Discripton circuit:


LED3 shines through the finger on the LDR1. Each time the heart is pumping a 'wave' blood through the finger. The finger is getting darker inside so less light falls on the LDR1. This phenomenon is measurable and convertible to an electrical pulse. For each heart pulse the resistance of the LDR1 changes and the voltage on the input of comparator IC1a also changes. The reinforcement of the opamp is adjustable with potentiometer P1. The sensitivity of the circuit is adjustable with potentiometer P2.Output driver transistor T1 controls LED2 and will blink on the frequency of the heart. Remark: You must see that LRD1 only catch the light that’s comes from LED3 trough your finger and not the light from the environment.
which can lead to interference. So you need to experiment with the construction of LED3 and LDR1. We used a box (see picture).
Image

I hope i helped you with this post,

Greetz,
Dieter
Attachments
3 segmenten V2.fcf
(11 KiB) Downloaded 521 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Schoolproject

Post by Benj »

Hello Dieter

The TX pin of the RS232 is connected to pin RB5. However this pin is also used for the 7-segments. This is not going to work.

The input pin is also commoned with the 7-segs but I think this should still work correctly.

You have also set the target to 16F88 (xtal - lvp) which means that you are also loosing the functionality of pin RB3. The 16F88 (xtal) would be a better option here.

I can see you having several options at this point.

1) Use a larger chip so that you have enough free I/O to do the 7-segment and RS232 comms.

2) Use the onboard internal oscillator to free up the pins RA6 and RA7 and this way you can bit bang RS232 via these pins using the software function available from here. To do this you would have to set the target to a standard 16F88 and then setup the configuration appropriatley to disable LVP and enable the internal oscillator. You would also have to adjust your clock speed and interrupt rate to match the speed of the internal oscillator.

http://www.matrixmultimedia.com/Downloa ... .php?id=34

Diet
Posts: 9
Joined: Tue Feb 23, 2010 8:41 am
Contact:

Re: Schoolproject

Post by Diet »

Hey Benj,

Using a lager chip is not an option because of schoolbudget and efficiency of using pins.
It's perfectly possible to use the PIC16F88 for our project. How can we change the macro LED7Seg4(0) ?
Because we can only select port A or port b for the whole 7 segments Display. Because we lose RB5 for RS232
That's not efficient in our project. Is there no way to change the pins for the macro to free pins?
Is it possible to use this configuration ( see picture below).
Image


I hope you understand our problem, Benj
How can we solve this problem?

Thx for helping us out with the problem.

Greetz,

Dieter

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Schoolproject

Post by medelec35 »

Great school project by the way. Make me wish I was back at school. Would of loved to do projects like that!
For a solution, I agree with Ben can't you use the internal oscillator set at 8MHz, and that will free up 2 extra pins (RA7 and RA7)?
I am using internal oscillator with my projects and not found a problem with that.
Martin

Diet
Posts: 9
Joined: Tue Feb 23, 2010 8:41 am
Contact:

Re: Schoolproject

Post by Diet »

Hey medelec35,

I tried to bitbang RS232 from port RB5 to port RA6. So we can use the 7 segments displays and RS232 at the same time.
Can anyone experienced look my code ? Do anyone know how you can make your own 7 segmenten macro in flowcode V3?

Greetz,
Dieter
Attachments
Project.fcf
(11.5 KiB) Downloaded 484 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Schoolproject

Post by medelec35 »

You program will require quiet a few adjustments.
I have made a few of them, but there are more changes required, and won’t have time until tonight to look further.
I have made following changes.

1) Changed target to 16F88 to make use of int osc.
2) added C code osccon=0x70; to configure int osc to 8MHz
Changed configurations e.g. as Ben Suggested LVP disabled etc.

When you first create a program, it is always wise to create a very simple 1Hz flasher. This will check your configurations and timing are correct.
See: http://www.matrixmultimedia.com/mmforum ... =26&t=6936
Another problem is your timer0 interrupt routine is far to long. It is always wise to keep interrupts as short as possible. Do not have delays esp milliseconds or greater. Do not have LED or LCD or other component macros within your interrupt.

Best way is if after time you required is up, then set a variable as 1. if this variable is 1 then don’t count in interrupt routine, activate all the things in main like LEDs on, delays etc then set variable to 0, then allow timer0 to start counting again.
On the subject of interrupts, You have got 75 x interrupt = 1 Second, that is only true for osc of 19.660800MHz. For 8MHz its 31x interrupt = 1 Second true value is 30.5. so for 10 seconds you could use 16bit int so value is 30.5*10 = 305. However doing 10 * 1 second in bytes is fine.
Attachments
Project.fcf
(12 KiB) Downloaded 465 times
Martin

Diet
Posts: 9
Joined: Tue Feb 23, 2010 8:41 am
Contact:

Re: Schoolproject

Post by Diet »

Hey Medelec35,

Thanks for making some time for us.

The school allows us the use a lager chip because of al the problems we had.
We know use an ECIO-40 from Matrix Multimedia.
Buth we have one problem in your program ( see attachment):
If we send the beats per minute (BPM) by the way of macro RS232(0) our application program recieves characters instead of a decimal value.
For example our BPM = 54. Our application programma (labVIEUW) recieves char '6' instead of 54. What do we wrong ?
Image

Has anyone an idea to solve this problem?

Thank you for your time!
Attachments
labVIEUW application.rar
application program running on the pc
(75.79 KiB) Downloaded 413 times
ECIO40P.fcf
Flowcode code
(15.5 KiB) Downloaded 393 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Schoolproject

Post by Benj »

Hello

You should be able to use the string conversion function ToString to convert the numeric value to an ascii representation. You will then need to send the String (v4) or send the individual bytes of the string (v3).

Diet
Posts: 9
Joined: Tue Feb 23, 2010 8:41 am
Contact:

Re: Schoolproject

Post by Diet »

Benj wrote:Hello

You should be able to use the string conversion function ToString to convert the numeric value to an ascii representation. You will then need to send the String (v4) or send the individual bytes of the string (v3).
Hey Benj i tried something else for making ASCII code from a byte.
Just add 48 to the beats per minute

Buth i can't send after 5 seconds the BPM?? Why ? Is there something wrong with my interrupts ?
Please see my code http://www.uploadarchief.net/files/down ... cii%29.zip,
because i could not upload attachment by using this site. Error ==> Could not upload attachment to ./files/13845_f08af17057aecaa655a7819874880573

Main program:
Image

Interrupt on TMR0 overflow
Image

Interrupt on RB0 (Heartbeat)
Image

Greetz, Diet

Diet
Posts: 9
Joined: Tue Feb 23, 2010 8:41 am
Contact:

Re: Schoolproject

Post by Diet »

There are stil some problems in my code.
After 5 seconds my 7segments display doesn't refresh his value's for starting again.
Attachments
ECIO40P (new).fcf
(17 KiB) Downloaded 441 times

Post Reply