Close

Keeping my head above water and making progress

A project log for Universal Glucometer

Did your test strips just get more expensive? Has the drug store run out of strips for YOUR meter? Like to be able to use any test strip?

tom-meehanTom Meehan 08/16/2016 at 04:570 Comments

While I've been able to find quite a few online sources for instruction in 'C', I really wanted a decent reference book (a physical one made of actual paper) to use. I finally broke down and ordered a copy of “The C Programming Language” by Kernighan and Ritchie.

I've been able to find a solution to an issue that's been vexing me for awhile – sending the values in variables out to the LCD.

char s[12]={0}; //declares a char array with 12 positions and clears the array
sprintf(s,"The value of J =",var1 ); // saves formatted characters, including 'var1' to the array 's'  
LCDString(s); //sends formatted array to print on the LCD

So far this is working fine and lets me combine text and values from variables and print the results to the LCD. This was tough for me to figure out because it is something that seems to be obvious to anyone who has learned 'C'. Most courses on 'C' seem to cover 'printf' and 'sprintf' fairly early. So, being pretty new to 'C' and not formally taught I missed it - well now I will not forget that little piece of knowledge.

I've posted my most recent changes to the full source code at Github Universal Glucometer.

I keep reviewing the datasheets again and again. As I understand more I end up having even more questions and have to delve deeper to find the answers – it is slowly becoming less intimidating.

Illustration of the hardware/software implementation for strip reading.

Below is the Initialization code for the meter, the sets up the Fixed Voltage Reference, DAC, ADC, OpAmp, etc. (it is in the user.c file of the source code). This code shows the settings for the register pins in the illustration above.

void InitApp(void)
{
    /* FVR CONFIGURATION */
    //FVRCON = 0x88;
    FVRCONbits.FVREN = 1;
    FVRCONbits.CDAFVR = 0b10; //Comparator and DAC Fixed Voltage Reference Peripheral output is 2x (2.048V)
    FVRCONbits.ADFVR = 0b10;// ADC Fixed Voltage Reference Peripheral output is 2x (2.048V)
    // PORT A CONFIGURATION
    ANSELA = 0x3F;
    TRISA = 0x3F;
    ANSELAbits.ANSA3 = 0;
    TRISAbits.TRISA3 = 0;
    // PORT B CONFIGURATION
    TRISB = 0;            //PortB to output? then set individual bits?
    ANSELB = 0;           //Port B pins all set to digital++++
    TRISBbits.TRISB0 = 1; // PortB bit0 digital input STRIP_SENSE
    TRISBbits.TRISB5 = 1; // PortB bit5 digital input (REF_OUT Vref for strip)
    TEMP_SENSE_VDD = 0;
    TRISBbits.TRISB2 = 1; // PortB bit2 analog input TEMP_OUT
    ANSELBbits.ANSB2 = 1; // PortB bit2 analog input TEMP_OUT
    TRISBbits.TRISB3 = 1; // PortB bit3 digital input SW3
    TRISBbits.TRISB4 = 1; // PortB bit4 digital input SW1
    IOCBNbits.IOCBN4 = 1;
    IOCBFbits.IOCBF4 = 0;
    IOCBNbits.IOCBN3 = 1;
    IOCBFbits.IOCBF3 = 0;
    REF_OUT = 0;
    // PORT C CONFIGURATION
    TRISC = 0;
    //TRISCbits.TRISC7 = 1; //Rx is input
    // OPAMP CONFIGURATION
    OPA1CONbits.OPA1EN = 1;
    OPA1CONbits.OPA1SP = 0;
    OPA1CONbits.OPA1PCH0 = 0b1;// 0b10; // SELECT DAC AS INPUT TO  OPAIN+
    OPA1CONbits.OPA1PCH1 = 0b1;// 0b10; // SELECT DAC AS INPUT TO  OPAIN+
    // DAC CONFIGURATION
    DACCON0bits.DACEN = 1;
    DACCON0bits.DACOE1= 1;
    DACCON0bits.DACNSS = 0;
    DACCON0bits.DACPSS= 0b10;
    OPTION_REGbits.INTEDG = 0;
    OPTION_REGbits.PS = 0b111; // timer 0 prescale = 256
    // Enable interrupts
    INTCONbits.INTF = 0;
    INTCONbits.INTE = 1;
    INTCONbits.GIE = 1;
    INTCONbits.PEIE = 1;
    PIE1bits.ADIE=1;
    INTCONbits.IOCIF= 0;
    INTCONbits.IOCIE= 1;
    VREGCONbits.VREGPM= 1;
}

For additional information about the different modules (OpAmp, DAC, ADC, Comparator, FVR) I've listed the page numbers of the data sheet for the PIC16F1784 (includes -84, -85, -86 and -87) that each module begins on.

I've been concerned about the bias voltage for different test strips and I was happy to find that it is possible to adjust the outputs from the DAC's through the software/firmware and adjust the bias voltage.

The other issue I'm working to resolve - the Vref supply to the strip. Currently this is assigned to RB5 (which is configured as a digital input). I believe the Vref should be a negative polarity (so configuring the pin as an input makes sense) but I do not see regulation of the potential (V-). So, to begin I'll need to read this pin to see what it's potential is with reference to GND and to 3.3V. I'll be checking this ASAP, since it could have direct implications on my board design.

Additional pieces of the design I've been working on:

I'll be posting up the new schematics shortly, that includes the changes mentioned above.

Discussions