Project code - advice/tips

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Project code - advice/tips

1,863 Views
Iain
Contributor I

Using:

CW 5.9, HCS08QE32, DEMOQE

Polar RMCM-01 heart-rate receiver - outputs 1ms, 3V pulse each beat detected

SiRF Starlll EM-406A GPS receiver - spits out NMEA data string (SCI communication)

4D μDrive-USD-G1 μSD card module (SCI communication)

 

I am currently working on a device (intended for a runner) that will log heart-rate, GPS data, and store on a μSD card. 

 

I am coding in C, and have some experience of this language and HCS08 μCs, but am not a great programmer. I have found lots of helpful documentation online and also have Fabio Pereira's "HCS08 Unleashed" book, but would appreciate any information or tips that might help me build my code.

 

Issues such as:

1) How should I set out my code - all in main.c file, or split into the separate sections (how to link    together)?

2) calculate average HR every few pulses from HRr, set up as an interrupt?

3) GPS output @ default frequency 1Hz (as interrupt) or somehow synchronize with HR output?

4) will 2 data types need to be stored to onboard flash or buffer, before being written to μSD, or can I write to it in real time?

5) HR and GPS data must be sychronised in time, can this just be achieved by starting both data logging at same time?

6) end user should have μSD card with 2 files (GPS data and HR data) in .txt format?

7) split data types by simply allocating different memory blocks for each one on μSD card?

 

Any advice with regards to to above points, ways to code it better, or any general tips on how to tackle the program as a whole would be greatly appreciated.

 

Iain

Labels (1)
Tags (1)
0 Kudos
Reply
3 Replies

780 Views
pgo
Senior Contributor V

Dear Iain,

 

Some suggestions:

 

Issues such as:

1) How should I set out my code - all in main.c file, or split into the separate sections (how to link    together)?

- Separate modules.  If you are using codewarrior then it should only be a matter of adding them to the project and defining suitable header files to "export" shared details about a module to other modules.

 

2) calculate average HR every few pulses from HRr, set up as an interrupt?

- Use timer input capture with interrupt.  You will need to do some averaging and reject "out of bounds" results for missed pulses.  Store the average is a static variable with get() function if you like information hiding :smileyhappy:

 

3) GPS output @ default frequency 1Hz (as interrupt) or somehow synchronize with HR output?

- perhaps interrupt driven reception.  Log current position in static variable upon  complete NMEA message.  Provide get() function.

 

4) will 2 data types need to be stored to onboard flash or buffer, before being written to μSD, or can I write to it in real time?

- Don't know.  Accessing uSD is quite complicated.  There are some FAT file systems drivers available that I believe allow the card to be viewed as a simple file.  Alternatively, and much simplier, there are some SD card modules that take care of the details for you e.g. http://www.flashgenie.net/ (for SD card but others are available.

 

5) HR and GPS data must be sychronised in time, can this just be achieved by starting both data logging at same time?

- I suggest you just have a regular interrupt at the desired sampling rate.  Access the current HR and GPS data produced by the above modules and log to SD card.  What is you sampling rate? What timing accuracy do you want?  Keeping in mind the inherent errors in the GPS I wouldn't be too obsessive about "synchronising" the GPS data.  Log the HR data at your sampling rate along with the current GPS location. 

 

6) end user should have μSD card with 2 files (GPS data and HR data) in .txt format?

- If using a file system then a single .CSV file would be more suitable.

 

7) split data types by simply allocating different memory blocks for each one on μSD card?

 

 

0 Kudos
Reply

780 Views
Iain
Contributor I

Thanks pgo!

 

How do I go about implementing a FAT file system for my uSD card module? I naively thought that I could just send the data I wanted via the SPI Tx pin, and the uSD module would take care of how it stored it.

 

I have been looking at a circular buffer example in Pereira's book, to store data to be receiver/transmitted with SCI. Would this be a good idea to use for my GPS NMEA data string, as I could specify buffer size to accommodate string size?

 

As for interrupt sample rate - possibly output HR every 2-3 seconds? This would be long enough to calculate an accurate average, yet still be frequent enough for this application. Also GPS at that frequency would be fine for tracking a runner/jogger. 

 

 

Anybody know of the best way to get my 2 sets of data written to the uSD module, or any other suggestions for things I've missed or improvements. 

 

I am starting to piece bits together, but am still struggling with the general set-up and structure of the program.

 

Appreciate the help,

 

Iain

 

   

0 Kudos
Reply

780 Views
bigmac
Specialist III

Hello Iain,


Iain wrote:

As for interrupt sample rate - possibly output HR every 2-3 seconds? This would be long enough to calculate an accurate average, yet still be frequent enough for this application. Also GPS at that frequency would be fine for tracking a runner/jogger. 

  

The measurement of HR would actually involve the measurement of the period between successive heart pulses, possibly with the use of TPM input capture.  Possibly a TPM clock period of 1ms would be appropriate to give a reading in milliseconds, but this is flexible.  You will also need to set an upper limit for the measurement period, beyond which it is deemed that the HR monitor is, or has become disconnected.

 

One approach would be to store the "raw" period data to a file, that would be periodically punctuated with a time (and date) stamp.  This data can then be correlated with the GPS position data issued at one second intervals.

 

The mathematical processing of the period data to ascertain HR might then be done at the time of download from the uSD module (assuming no real time HR display is required).  The results could then be "filtered" in multiple ways during data analysis.

 

Regards,

Mac

0 Kudos
Reply