Hello Experts,
I am working on 24 bit adc with 1ksps rate. My problem is divided into two parts here:
1. I am sending data at 115200 BPS successfully but I wish to increase its 460800 for assurance(of not having any data loss). Now I have read the data sheet and used couple of baud rate calculators but it seem what I get in the terminal is complete garbage also I used PICOSCOPE to monitor UART signal form MCU but again there was no data I coud interprette. Can someone help me with fixing this issue of changing baudrate?
2. I have written code for get data from ADC via SPI and then transferring it to PC via UART but for some reason the UART only works properly(I get meaningful data) when I add delay of 1000 cycle after each 8 bit transactions. Due to this delay my overall sample rate of ADC get hurt significantly.For eg I am scanning 4 channel of my ADC at 1000 sps(so practically I get 250 SPS for each channel) and plus the delay of 1000 cycles in mcu. so on 1 hZ sin wave I roughly get 50 data points( i should get 250, right?). SO can someone help me with removing delay of 1000 cycles from my programss
by the way I am using ADS1220 as ADC.
Here is the code the delay you can find on line 19
I am working on 24 bit adc with 1ksps rate. My problem is divided into two parts here:
1. I am sending data at 115200 BPS successfully but I wish to increase its 460800 for assurance(of not having any data loss). Now I have read the data sheet and used couple of baud rate calculators but it seem what I get in the terminal is complete garbage also I used PICOSCOPE to monitor UART signal form MCU but again there was no data I coud interprette. Can someone help me with fixing this issue of changing baudrate?
2. I have written code for get data from ADC via SPI and then transferring it to PC via UART but for some reason the UART only works properly(I get meaningful data) when I add delay of 1000 cycle after each 8 bit transactions. Due to this delay my overall sample rate of ADC get hurt significantly.For eg I am scanning 4 channel of my ADC at 1000 sps(so practically I get 250 SPS for each channel) and plus the delay of 1000 cycles in mcu. so on 1 hZ sin wave I roughly get 50 data points( i should get 250, right?). SO can someone help me with removing delay of 1000 cycles from my programss
by the way I am using ADS1220 as ADC.
Here is the code the delay you can find on line 19
Code:
#include <msp430.h>
#include "ADS1220.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "BCUart.h"
unsigned int j = 0x00;
unsigned int i;
int channel;
/*variable to store single smaple read from adc*/
volatile long adc_value1;
static void putDataToUart(uint8_t byte);
static void putDataToUart(uint8_t byte){
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = byte;
__delay_cycles(1000); <---------------------------------------------------------- THIS DELAY
//while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
}
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
//******************SPI****************************//
P3SEL |= BIT0+BIT1+BIT2; // P3.3,4 option select
UCB0CTL1 |= UCSWRST; // **Put state machine in reset**
UCB0CTL0 |= UCSYNC+UCMSB+UCMST; // 3-pin, 8-bit SPI Master, MSB
UCB0CTL1 |= UCSSEL_2; // SMCLK 16Mhz
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
//***************UART********************//
P3SEL |= BIT3+BIT4; // P3.3,4 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 34; // 1MHz 115200 (see User's Guide)
UCA0BR1 = 0; // 1MHz 115200
UCA0MCTL |= UCBRS_6 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
//*************************ADS1220*******************************//
ADS1220Init();
ADS1220Config();
// ADS1220SetClockMode(ADS1220_MODE_TURBO);
ADS1220SetPGABypass(ADS1220_PGA_BYPASS);
ADS1220SetVoltageReference(ADS1220_VREF_SUPPLY);
__delay_cycles(1000);
ADS1220SendStartCommand();
channel |= 0;
volatile uint8_t tmp = 0;
__delay_cycles(1000);
int channels[4] = {ADS1220_MUX_0_G, ADS1220_MUX_1_G, ADS1220_MUX_2_G, ADS1220_MUX_3_G};
int crChannel = 0;
while(1)
{
ADS1220SetChannel(channels[crChannel]);
// ADS1220SetPGABypass(ADS1220_PGA_BYPASS);
ADS1220SendStartCommand();
while(0 != P2IN & BIT6);
adc_value1 = ADS1220ReadData();
uint8_t tmp = ((adc_value1 >> 24) & 0xff);
//uint8_t tmp = crChannel;
/*put the first byte to Uart*/
putDataToUart(tmp);
/*prepare the third byte data*/
tmp = ((adc_value1 >> 16) & 0xff);
/*put the first byte to Uart*/
putDataToUart(tmp);
/*prepare the second byte data*/
tmp = ((adc_value1 >> 8) & 0xff);
/*put the first byte to Uart*/
putDataToUart(tmp);
/*prepare the first byte data*/
tmp = (uint8_t )(adc_value1 & 0x000000FF);
/*put the first byte to Uart*/
putDataToUart(tmp);
j = 2;
/*
*adc index
*ch0 ch1
*ch1 ch2
*ch2 ch3
*ch3 ch0
*/
if(crChannel == 3)
{
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 0x2F;
// __delay_cycles(1000);
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 0x41;
//__delay_cycles(1000);
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 0x2F;
//__delay_cycles(1000);
}
crChannel += 1;
crChannel %= 4;
}
}