Heart rate sensor MAX30102


Closed Thread
Results 1 to 40 of 85

Hybrid View

  1. #1
    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

  2. #2
    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

  3. #3
    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

  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

    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

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    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]
    most of the drivers i've seen over the net are using the following...


    1, what led pwr to use : 0x1F about 6.2 mA
    2, what led pwidth to use : 411 which is 18 ADC BIT RESOLUTION based on the manual.
    3, what sample rate to use : sample rate per second 100

    a configuration should also include: sampleAverage = 8

    4, what sample resolution to use :
    5, if there are any fifo overflows and if it matters much.
    6, what led the readings represents. I will search and find out.
    7, how to interpret the data....
    8, how much data to collect [i assume at least 2 seconds worth]

  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

    this looks like something, probably needs a lpf and sum of the squares function to remove dc drift

    Code:
    '****************************************************************'*  Name    : MAX30102  FOR PIC 18 DEMO                         *
    '*  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
    result     var word ext
    @result = _fifo 
    ;-----------------------  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,[$20]
        reg = REG_LED2_PA 
        i2cwrite  SDA,scl,ADDR,reg,[9]
        reg = REG_LED1_PA 
        i2cwrite  SDA,scl,ADDR,reg,[9]
        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]
        pause 200 
     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 + 2],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 
        DEBUG "."
     NEXT  
        FOR index = 0 TO 1151 STEP 0
        for ptr = 0 to 2
        fifo[ptr] = buffer[index + ptr]
        next
        DEBUG 13,10;,  hex2 fifo[2] , hex2 fifo[1],  hex2 fifo[0]
    '    asm         ;ROTATE READING TO GET SUFFICIENT RESOLOUTION INTO UPPER WORD
    '    banksel _fifo 
    '    bcf STATUS,C
    '    RRCF  _fifo + 2 ,f
    '    RRCF  _fifo + 1 ,f
    '    RRCF  _fifo    ,f
    '    bcf STATUS,C
    '    RRCF  _fifo + 2 ,f
    '    RRCF  _fifo + 1 ,f
    '    RRCF  _fifo    ,f
    '    banksel 0
    '    endasm
        DEBUG 9,HEX4 result 
        index = index + 3
    '    DEBUG 13,10, hex2 buffer[index+2],hex2 buffer[index+1],hex2 buffer[index],9 ,HEX4 result  
    '    DEBUG 9,  hex2 fifo[2] , hex2 fifo[1],  hex2 fifo[0]
        for ptr = 0 to 2
        fifo[ptr] = buffer[index + ptr]
        next
        
    '    DEBUG 9,  hex2 fifo[2] , hex2 fifo[1],  hex2 fifo[0]
    '    asm         ;ROTATE READING TO GET SUFFICIENT RESOLOUTION INTO UPPER WORD 
    '    banksel _fifo
    '    bcf STATUS,C
    '    RRCF  _fifo +2 ,f
    '    RRCF  _fifo +1 ,f
    '    RRCF  _fifo    ,f
    '    bcf STATUS,C
    '    RRCF  _fifo +2 ,f
    '    RRCF  _fifo +1 ,f
    '    RRCF  _fifo    ,f
    '    banksel 0
    '    endasm
        DEBUG 9,HEX4 result
        index = index + 3
       NEXT 
    RETURN
    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

    its alive i think
    Name:  hb.jpg
Views: 5200
Size:  192.7 KB
    gives me a 63 rpm
    Warning I'm not a teacher

  8. #8
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    Richard,

    looking at your code,i'm learning lots of things.

    All the registers you have are constants. And that is what i've thought also in the beggining.
    Code:
    ;-----------------------  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]
    
    
    ' -----------------------------------------------------------------------------|
    But in the manual it says that we never use constants for the I2C command.

    What i have realised is that you refer to the

    Code:
    reg var byte
    everytime you need to asign a constant value to it. Is that right? with that way we alter the restriction of using constants. (or am i wrong?)

    Sencod question.

    I see you are always using the Write Address:

    Code:
    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,[$20]
        reg = REG_LED2_PA 
        i2cwrite  SDA,scl,ADDR,reg,[9]
        reg = REG_LED1_PA 
        i2cwrite  SDA,scl,ADDR,reg,[9]
        reg = FIFO_CONFIG  
        i2cwrite  SDA,scl,ADDR,reg,[16]
    even if you want to read from:

    Code:
        reg= REG_TEMP_INT        
        i2cread  sda,scl,ADDR,reg,[fifo[0],fifo[1]]
    im confused here. When do we use the write address and when do we use the read address!!!

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