2013-10-23

LPC board hardware bug found, MCP3208 function working OK

I found a hardware bug in the Olimex board, the MISO signal at the end of the wiring is still OK, but RxBuf is not receiving anything.  I suspected the Olimex's MISO part is not working, so I swapped it with the WHUT board and the program works OK, with the following results.  I used a calculator to find the voltage of 1.633V, which is almost exactly as 1.64V I hoped to get. 

*** MCP3208 Test - 2013oct23hk1453 ***

*** Before ADC values of TxBuf and RxBuf *** 
Index    0  1   2
TxBuf  06 80 00 
RxBuf  00 00 00 

*** After ADC (Ch 2 = 1.64V, ARef = 2.49V) *** 
Index    0  1   2
TxBuf  06 80 00 
RxBuf  ff ea 7f 

*** End of Test. *** 


Rx012 = ff ea 7f
Rx12 =  ea 7f
Rx1 &0f = a
results in hex = a7f = decimal 2687

voltage = 2.49V * (2687 / 4096) = 2.49v * 0.656 = 1.63v

So the MCP3208 is almost perfect!


// ***********************************************************************
// Program  - Fong EKG v5.0
// Function - Olimex EKG Board Evaluation
// Author   - TL Fong
// Build    - 2013.10.23.01
// Date     - 2013oct23hkt1508
// Hardware - Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301/FN28
//            Olimex EKG board (SHIELD-EKG/EMG Rev B, Bulgaria 2011)
// Software - GCC ARM 4.7, CoIDE 1.7.4,  CoLinkEx 1.1, Flash Magic v7.51
// ***********************************************************************

#include "test050.h"

// ***********************************************************************
// Main Function
// ***********************************************************************

int main()
{
...
testMcp320802();

...
}

// ***********************************************************************
// End
// ***********************************************************************

// ***********************************************************************
// test050.h 2013oct23hkt1507
// ***********************************************************************

#include "led050.h"
#include "key050.h"
#include "spi050.h"

void testMcp320802() // 2013oct23
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

// *** Test MCP3028 ***
mcp320802();
}

... 

// ***********************************************************************
// End
// ***********************************************************************

// ***********************************************************************
// spi050.h 2013oct23hkt1506
// ***********************************************************************

#include "gpio050.h"
#include "led050.h"
#include "lpc11xx_ssp.h"
#include "semihosting.h"
#include "stdio.h"

void mcp320802()
{
    // *** Print title ***
printf("*** MCP3208 Test - 2013oct23hk1453 ***\n\n");

// Setup SPI0 with clock pin = P06
setUpSpi050(SCK0_PIO0_6);

// Setup SSEL0 pin = P02
setupSpiSsel();

    // Setup transfer buffers TxBuf, RxBuf
#define BUFFER_SIZE 3
uint8_t TxBuf[BUFFER_SIZE];
uint8_t RxBuf[BUFFER_SIZE];

    // Setup xferConfig = TxBuf, RxBuf
    SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = (void*)TxBuf;
    xferConfig.rx_data = (void*)RxBuf;
    xferConfig.length = BUFFER_SIZE;

    // Initialize MCP3208 Tx and Rx buffers

    // *** Select input mode and channel number ***

    uint8_t inputMode;
    uint8_t channelNumber;

    #define SINGLE_END_MODE 0x06; // bit 1 = 1
    #define DIFFERENTIAL_END_MODE 0x04; // bit 1 = 0

    inputMode = SINGLE_END_MODE;
channelNumber = 2;

    // *** Initialize TxBuf and RxBuf ***

    TxBuf[0] = inputMode | (channelNumber >> 2);
    TxBuf[1] = channelNumber << 0x6;
    TxBuf[2] = 0x00; // Don't care

RxBuf[0] = 0x00;
RxBuf[1] = 0x00;
RxBuf[2] = 0x00;

// *** Print TxBuf and RxBuf

char TxTitle[10];
char RxTitle[10];

strcpy(TxTitle, "TxBuf ");
strcpy(RxTitle, "RxBuf ");

// *** Before ADC ***
printf("\n*** Before ADC values of TxBuf and RxBuf *** \n\n");
printf("Index    0  1   2\n\n");
printXferBuffers(TxBuf, RxBuf, TxTitle, RxTitle);

// *** ADC once and print results ***

setSselLow();
    SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
    setSselHigh();

// *** After ADC (Ch 2 = 1.64V) ***
printf("\n*** After ADC (Ch 2 = 1.64V, ARef = 2.49V) *** \n\n");

printf("Index    0  1   2\n\n");
printXferBuffers(TxBuf, RxBuf, TxTitle, RxTitle);

// *** Print End of Test ***
printf("\n*** End of Test. *** \n\n");


    // *** calculate ADC results ***

    uint16_t adcOutputHex;

    // adcOutputHex = ((Rx_Buf[1] & 0x0f) * (2 ** 8)) + Rx_Buf[2];
    adcOutputHex = ((RxBuf[1] & 0x0f) * 256) + RxBuf[2];

    // *** Loop to display waveform by scope ***
    uint8_t i;
    for (i = 0; i < 10000000; i++)
    {
    delayMilliSecond(1);
    setSselLow();
        SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
        setSselHigh();
    }
}

void printXferBuffers(uint8_t TxBuf[BUFFER_SIZE], uint8_t RxBuf[BUFFER_SIZE], char TxTitle[10], char RxTitle[10])
{
uint8_t Tx0 = TxBuf[0];
uint8_t Tx1 = TxBuf[1];
uint8_t Tx2 = TxBuf[2];

uint8_t Rx0 = RxBuf[0];
uint8_t Rx1 = RxBuf[1];
uint8_t Rx2 = RxBuf[2];

printf("%s %02x %02x %02x \n", TxTitle, Tx0, Tx1, Tx2);
printf("%s %02x %02x %02x \n", RxTitle, Rx0, Rx1, Rx2);
}

/*

*** Sample output ***

*** MCP3208 Test - 2013oct23hk1453 ***

*** Before ADC values of TxBuf and RxBuf ***
Index    0  1   2
TxBuf  06 80 00
RxBuf  00 00 00

*** After ADC (Ch 2 = 1.64V, ARef = 2.49V) ***
Index    0  1   2
TxBuf  06 80 00
RxBuf  ff ea 7f

*** End of Test. ***

*/

...

// ***********************************************************************
// End
// ***********************************************************************




.END








No comments:

Post a Comment