Heart rate sensor MAX30102


Closed Thread
Results 1 to 40 of 85

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    Ok the FIFODT, FIFO DATA is not the one we are looking for.

    Just tried to see what could i get by requesting it using the following code. Also the code is not right but that is why i would like your help in here.
    Code:
    REG_FIFO_DATA = $07
    i2cread  sda,scl,contrd,REG_FIFO_DATA,[fifod1,fifod2,fifod3],error
    
    HSEROUT [$73,$04,$0C,$11,$F8,$1F,dec fifod1,dec fifod2,dec fifod3,$00]   ' fuchsia color $F8, $1F
    Hserin  timeout,error,[wait(6)]
    First i would like to retrieve the raw data of the IR LED.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    my code , you should know i have no idea :-
    1, what led pwr to use
    2, what led pwidth to use
    3, what sample rate to use
    4, what sample resolution to use
    5, if there are any fifo overflows and if it matters much
    6, what led the readings represents
    7, how to interpret the data
    8, how much data to collect [i assume at least 2 seconds worth]

    when graphed i see no regular pattern that could be a heart beat
    there is a difference between finger and no finger pattern



    Code:
    '****************************************************************'*  Name    : MAX30102  FOR PIC 18 test                         *
    '*  Author  :  Richard                                          *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    : 9/1/2022                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : MAX30102                                          *        
    '*          :18f26k22 @64Mhz                                    *
    '****************************************************************
     
      #CONFIG   ;  The PBP configuration for the PIC18F26K22 is:
        CONFIG FOSC     = INTIO67	       
        CONFIG PLLCFG   = OFF	        ;Oscillator multiplied by 4                       
        CONFIG PRICLKEN  = ON	        ;Primary clock enabled
        CONFIG FCMEN     = OFF	        ;Fail-Safe Clock Monitor disabled
        CONFIG IESO      = OFF	        ;Oscillator Switchover mode disabled
        CONFIG  BOREN    = SBORDIS      ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        CONFIG  WDTEN    = ON           ; WDT is always enabled. SWDTEN bit has no effect                     ;|
        CONFIG  WDTPS    = 32768        ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale;|
        CONFIG  PWRTEN   = ON
        CONFIG  HFOFST   = ON           ; HFINTOSC output and ready status are not delayed by the oscillator stable status
        CONFIG  MCLRE    = EXTMCLR      ; MCLR pin enabled, RE3 input pin disabled
        CONFIG  LVP      = OFF          ; Single-Supply ICSP disabled
        CONFIG  XINST    = OFF          ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG    = OFF          ; Disabled
        CONFIG  CP0 = OFF             ; Block 0 (000800-003FFFh) not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (004000-007FFFh) not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (008000-00BFFFh) not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (00C000-00FFFFh) not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-003FFFh) not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (004000-007FFFh) not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (008000-00BFFFh) not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (00C000-00FFFFh) not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG  WRTB = OFF            ; Boot Block (000000-0007FFh) not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
     #ENDCONFIG    
     
      
    'define I2C_SLOW 1
    define  OSC 64
    
    
    OSCCON    = %01110000   ; 16Mhz
    OSCTUNE.6 = 1           ; Enable 4x PLL
    
    
    while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code
    
    
       
    TRISC = %11011000                  
    ANSELC=0
    
    
    #DEFINE    DEBUGING 1   
    
    
    #IFNDEF  DEBUGING       
        DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
        DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
        DEFINE HSER_CLROERR 1 ' Clear overflow automatically
        DEFINE HSER_SPBRG 160 ' 38400 Baud @ 64MHz, -0.08%
        SPBRGH = 1
        BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    #ELSE        
        DEFINE DEBUG_REG PORTB
        DEFINE DEBUG_BIT 7
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0
        ANSELB=0
        LATB.7=1
    #ENDIF
    SDA     var portc.4  ' DATA PIN
    SCL     VAR portc.3  ' CLOCK PIN
    
    
    Timeout    cON 2000
    reg        var BYTE
    fifo       var byte[6]
    addr       var byte 
    REVISION   var byte
    PARTID     var byte
    buffer     var byte[1152]
    ptr        var byte
    btr        var byte
    index      var word
    ;-----------------------  REGISTER -------------------------
    REG_TEMP_INT         con $1F
    REG_TEMP_FRAC        con $20
    REG_TEMP_CONFIG      con $21
    REG_PART_REVISION    con $FE
    REG_MODE             con $09
    REG_SPO2_CONFIG      con $0A        ;SPO2_ADC_RGE[6:5]SPO2_SR[4:2]LED_PW[1:0]
    REG_LED1_PA          con $0C
    REG_LED2_PA          con $0D
    FIFO_WR_PTR          con $04        ;FIFO_WR_PTR[4:0]
    FIFO_RD_PTR          con $06
    FIFO_DATA            con $07
    FIFO_CONFIG          con $08        ;FIFO_A_FULL[3:0]   SMP_AVE[7:5]
    STATUS1              con 0          ;A_FULL[7]
    
    
    ' -----------------------------------------------------------------------------|  
    
    
    #IFDEF  DEBUGING
        PAUSE 2000
        DEBUG 13,10,  "READY"
    #ENDIF
        ADDR  =  $ae     ; addr is  0x57 << 1
        reg= REG_PART_REVISION
        i2cread  SDA,scl,ADDR,reg,[REVISION,PARTID]
        reg= REG_MODE 
        i2cwrite  SDA,scl,ADDR,reg,[3] 
        reg= REG_SPO2_CONFIG
        i2cwrite  SDA,scl,ADDR,reg,[$30]
        reg = REG_LED2_PA 
        i2cwrite  SDA,scl,ADDR,reg,[2]
        reg = REG_LED1_PA 
        i2cwrite  SDA,scl,ADDR,reg,[2]
        reg = FIFO_CONFIG  
        i2cwrite  SDA,scl,ADDR,reg,[16]        
        
    #IFNDEF  DEBUGING
        HSEROUT [$73,$03,$04,$11,$ff,$ff,"PART ID: 0X",hex PARTID,"/0X", hex REVISION,$00]
        Hserin  timeout,error,[wait(6)]
    #ELSE
        DEBUG 13,10,  "PART ID: 0X",hex PARTID,"/0X",hex REVISION
    #ENDIF 
    
    
    '********************************************************************************
    start:
        reg= REG_TEMP_CONFIG
        i2cwrite  SDA,scl,ADDR,reg,[1] 
        reg= REG_TEMP_INT        
        i2cread  sda,scl,ADDR,reg,[fifo[0],fifo[1]]
    #IFNDEF  DEBUGING
        HSEROUT [$73,$05,$0A,$11,$07,$E0,"TEMP: ",DEC fifo[0],".",DEC2( fifo[1]<<6),$00]  
        Hserin  timeout,error,[wait(6)]
    #ELSE
        DEBUG 13,10, "TEMP: ",DEC fifo[0],".",DEC2( fifo[1]<<6) 
    #ENDIF
        GOSUB AQUIRE
        pause 5000
    goto start
    
    
    aquire:
        reg= FIFO_WR_PTR
        i2cwrite  SDA,scl,ADDR,reg,[0]
        reg= FIFO_RD_PTR
        i2cwrite  SDA,scl,ADDR,reg,[0]
         
     FOR index = 0 TO 1151 STEP 0
        
        btr =0
        reg= STATUS1
        WHILE btr&$80=0
        i2cread  sda,scl,ADDR,reg,[btr]
              
        WEND
        reg= FIFO_RD_PTR
        i2cread  SDA,scl,ADDR,reg,[btr]
        btr =  (btr- ptr) &  31
        WHILE btr
        reg = FIFO_DATA         
        i2cread  sda,scl,ADDR,reg,[buffer[index],buffer[index+1],buffer[index+0],buffer[index+5],buffer[index+4],buffer[index+3]]
        index=index+6
        btr=btr-1
        ptr = (Ptr+1) &  31
        WEND
        pause 200 ; no sure about this either
     NEXT  
        FOR index = 0 TO 1151 STEP 0
        DEBUG 13,10,HEX2 buffer[index+0],HEX2 buffer[index+1],9,HEX2 buffer[index+3],HEX2 buffer[index+4]     
        index=index+6
       NEXT 
    RETURN
    Last edited by richard; - 11th January 2022 at 21:21.
    Warning I'm not a teacher

  3. #3
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    thanks Richard,

    i will read carefully your code and will come back because i have couple of questions.

    In the begging i got confused the way you use addr and reg names inside the I2Cread or write command.

    Code:
    ADDR  =  $ae     ; addr is  0x57 << 1
        reg= REG_PART_REVISION
        i2cread  SDA,scl,ADDR,reg,[REVISION,PARTID]
    I followed the manual example: so i wont get consfused.

    Code:
    I2CWRITE PORTA.0,PORTA.1,cont,addr,[B2]

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    I followed the manual example: so i wont get consfused.
    not really

    addr is the i2c device address , reg is the register you are accessing. that example you refer is for an eeprom
    where those words make a little sense, in this context they are totally misleading
    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    Quote Originally Posted by richard View Post
    not really

    addr is the i2c device address , reg is the register you are accessing. that example you refer is for an eeprom
    where those words make a little sense, in this context they are totally misleading
    once again you are right. I will change the names in the code as well.

    One more question. What is the difference on the following?

    With the [] and without them. I noticed that i get completely different results. The ones with the [] looks like is the right one as once i place them, i can control the values of the LED's pulse amplidute. Now it is visible the difference.

    Code:
    addr = $09   ' MODE CONFIGURATION 
    i2cwrite  SDA,scl,contwr,addr,[%00000011],error  ' ModLED = $02 as per data sheet heart rate mode, $03 SpO2 mode
    pause 10
    
    addr = $0A   ' SpO2 mode configuration 
    i2cwrite  SDA,scl,contwr,addr,[%01111101],error  ' check the manual for this configuration
    pause 100
    
    addr = $0C    'LED PULSE AMLIDUDE FOR for LED1_PA[7:0] 0x0C
    i2cwrite  SDA,scl,Contwr,addr,[$03],error' if LED1_PA = $3F  , 12.6 mA , ($7F is 25.4 mA)
    pause 10
    
    addr = $0D    'LED PULSE AMLIDUDE FOR LED2_PA[7:0] 0x0D
    i2cwrite  SDA,scl,contwr,addr,[$03],error ' if LED2_PA = $1F , 6.2 mA  , ($7F is 25.4 mA)
    pause 10
    and the following:

    Code:
    addr = $09   ' MODE CONFIGURATION 
    i2cwrite  SDA,scl,contwr,addr,%00000011,error  ' ModLED = $02 as per data sheet heart rate mode, $03 SpO2 mode
    pause 10
    
    addr = $0A   ' SpO2 mode configuration 
    i2cwrite  SDA,scl,contwr,addr,%01111101,error  ' check the manual for this configuration
    pause 100
    
    addr = $0C    'LED PULSE AMLIDUDE FOR for LED1_PA[7:0] 0x0C
    i2cwrite  SDA,scl,Contwr,addr,$03,error' if LED1_PA = $3F  , 12.6 mA , ($7F is 25.4 mA)
    pause 10
    
    addr = $0D    'LED PULSE AMLIDUDE FOR LED2_PA[7:0] 0x0D
    i2cwrite  SDA,scl,contwr,addr,$03,error ' if LED2_PA = $1F , 6.2 mA  , ($7F is 25.4 mA)
    pause 10

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    no brackets means no data will be written
    Warning I'm not a teacher

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    fifo read was stuffed up

    reg = FIFO_DATA
    i2cread sda,scl,ADDR,reg,[buffer[index+2],buffer[index+1],buffer[index+0],buffer[index+5],buffer[index+4],buffer[index+3]]

    the fifo print out is incorrect also , not yet solved
    Warning I'm not a teacher

Similar Threads

  1. New PIC failure rate
    By timmers in forum General
    Replies: 5
    Last Post: - 26th March 2009, 12:11
  2. Rf module baud rate
    By tazntex in forum Serial
    Replies: 4
    Last Post: - 5th August 2008, 18:47
  3. Replies: 6
    Last Post: - 18th January 2008, 08:17
  4. SHIFTOUT Clock rate
    By Brock in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th July 2006, 23:42
  5. Detect baud rate
    By Dick M in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd July 2005, 21:10

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts