-
Content Count
24 -
Joined
-
Last visited
Reputation Activity
-
muzay reacted to B@tto in Msp430g2553 Launchpad v1.5 ADC Sampling Freq Setting Using Energia
Never that everything you do, even if it's written in decimal, hexadecimal ... Is always managed as binary. You would write :
Serial.write(sensorValue&255); or
Serial.write(sensorValue&0b11111111); instead of
Serial.write(sensorValue&0xFF); It would exactly the same
If your connection is not saturated, I recommand to you to send 255 two times before a new transmission, to ensure that on computer side a new transmission is arriving. Because if for a reason or another, the LSB transmission is lost (it could happen, it's rare but ...) your program will be desynchronised : MSB interpreted as LSB and vice versa.
-
muzay reacted to B@tto in Msp430g2553 Launchpad v1.5 ADC Sampling Freq Setting Using Energia
As I said, G2553 can support even much higher than 115200, so the G2553 is not a problem at all in your case. The problem comes from the conversion from uart out of the g2553 to your computer. So if you want to use BT, the limitation will come from your BT module.
Some tricks to improve speed : firstly, do not use texte like you did. You wasted a lot of bandwitch Serial.print("sensor = " ). Secondly use binary transmission. If you want to send your analogRead() value you can use a routine like this :
Measure = analogRead(Sensor); Serial.write(Measure>>8); Serial.write(Mesure&0xFF); And on the computer side, just read the serial buffer as binary, not ASCII, do the invert bitwise and you may get your analog reading
And it takes only two bytes of data so :
9600/10 = 960 <=> 960 / 2 = 490 hz , even in 9600 bauds
-
muzay reacted to B@tto in Msp430g2553 Launchpad v1.5 ADC Sampling Freq Setting Using Energia
It does not mean that's it's the best for your usage
+1
It was my idea when I asked for the code.
~30 bytes are sended each loop + 9600 baud <=> 9600/10 = 960 bytes/s <=> 960/30 => ~30 S/s max
So your low speed is normal. If you want to have a better acquisition speed, you may store it in an array during an acquisition period, and then send it by serial after.
Another way is to only send significant value : if you are studying a PWM signal, only transition are significant, so no need to send value if the precedent was the same
-
muzay reacted to semicolo in Msp430g2553 Launchpad v1.5 ADC Sampling Freq Setting Using Energia
I think it's the serial 9600bps that's holding the ADC frequency here, when the serial buffer is full, the Serial.print must be waiting until some chars are transmitted before returning.
Try without the Serial.print
void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 1023); //outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(analogOutPin, outputValue); delay(1); } -
muzay reacted to B@tto in Msp430g2553 Launchpad v1.5 ADC Sampling Freq Setting Using Energia
Hi,
Can you post your code ? G2553 datasheet allowed 200 kS/s, even if Energia "eat" some cycles, I don't think your low sample frequency comes from Energia, but from your code.
-
muzay reacted to B@tto in Msp430g2553 Launchpad v1.5 ADC Sampling Freq Setting Using Energia
The problem just comes from the UART debugger interface. If you use another usb<->serial converter, you will be able to rise much higher than 115200 baud
-
muzay reacted to dubnet in Msp430g2553 Launchpad v1.5 ADC Sampling Freq Setting Using Energia
The 2553 UART under Energia supports 115200 but not through the USB backchannel interface which is fixed at 9600. You would need to wire directly to the serial lines on the 2553 and use a RS232 level converter to talk to a standard PC serial port (+/-12V levels).
-
muzay reacted to RobG in dual channel ADC conversion
Look at this example, you will only need to make few small changes.
ADC10CTL1 = INCH_5 + CONSEQ_1; ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; ADC10DTC1 = 0x02; ADC10AE0 |= 0x30; -
muzay reacted to RobG in ADC to UART problem
Change your clock to 16MHz ( BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; ) and update UCA0BR0, UCA0BR1, and anything else that relies on the clock accordingly. This will speed up some tasks, like int to ASCII conversion.
-
muzay reacted to roadrunner84 in ADC to UART problem
You should be able to get 200 ksps. Probably your UART is slowing things down.
Considering your UART runs at 9600Bdps, the data rate is 960 characters per second. Assuming you're writing a 4 digit number and a new-line you're using 6 characters per measurement. The maximum data rate over UART is then about 150 measurements.
-
muzay reacted to roadrunner84 in ADC to UART problem
Yes, but then you'd need to use a separate serial cable. The UART driver on the Launchpad (not the MSP430, but the emulation part) can only do 9600 baud max.
-
muzay reacted to RobG in ADC to UART problem
#include "msp430g2553.h"
unsigned char txData[6] = {0,0,0,0,'\r','\n'};
void binaryToASCII(unsigned int n, unsigned char * digits);
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT2; // P1.2 is TXD
P1SEL2 = BIT2;
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 104;
UCA0BR1 = 0;
UCA0MCTL = UCBRS_1;
UCA0CTL1 &= ~UCSWRST;
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE;
ADC10CTL1 = INCH_0; // P1.0 analog input
ADC10AE0 |= BIT0;
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 6400; // sample every 50ms
TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode
_bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void) {
binaryToASCII(ADC10MEM, txData);
char c = 0;
while(c < 6) {
while (!(IFG2 & UCA0TXIFG))
;
UCA0TXBUF = txData[c];
c++;
}
}
// Timer A0 interrupt service routine
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void) {
ADC10CTL0 |= ENC + ADC10SC;
}
void binaryToASCII(unsigned int n, unsigned char * digits) {
__asm(" clr R14");
__asm(" rla R12");
__asm(" rla R12");
__asm(" rla R12");
__asm(" rla R12");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" rla R12");
__asm(" dadd R14, R14");
__asm(" mov.b R14, 3(R13)");
__asm(" swpb R14");
__asm(" mov.b R14, 1(R13)");
__asm(" rra R14");
__asm(" rra R14");
__asm(" rra R14");
__asm(" rra R14");
__asm(" mov.b R14, 0(R13)");
__asm(" swpb R14");
__asm(" mov.b R14, 2(R13)");
__asm(" and #0x0F0F, 0(R13)");
__asm(" and #0x0F0F, 2(R13)");
__asm(" add.b #0x30, 3(R13)");
__asm(" tst.b 0(R13)");
__asm(" jnz l1");
__asm(" mov.b #0x20, 0(R13)");
__asm(" tst.b 1(R13)");
__asm(" jnz l2");
__asm(" mov.b #0x20, 1(R13)");
__asm(" tst.b 2(R13)");
__asm(" jnz l3");
__asm(" mov.b #0x20, 2(R13)");
__asm(" jmp l4");
__asm("l1:");
__asm(" add.b #0x30, 0(R13)");
__asm("l2:");
__asm(" add.b #0x30, 1(R13)");
__asm("l3:");
__asm(" add.b #0x30, 2(R13)");
__asm("l4:");
return;
}
-
muzay reacted to RobG in ADC to UART problem
@@muzay, here are some examples of level shifters you can use (figure 6.11 and 6.12)
-
muzay reacted to RobG in ADC to UART problem
Yes, CCS doesn't have itoa, only ltoa
Convert 1024:
ltoa - 3,630 clock cycles
intToAscii (rr84) - 400 clock cycles (you may want to check your code, I didn't get expected results)
binaryToASCII (robg) - 100 clock cycles
Convert 15:
Itoa - 1,870
intToAscii - 380, no result
binaryToASCII - 110
-
muzay reacted to roadrunner84 in ADC to UART problem
From this slab of assembly language I understand that your compiler does not ship the standard function itoa? You could do this in C code as well, you know...
void intToAscii(unsigned short num, char* text) { int index = 0; const unsigned short decDigits[5] = {10000, 1000, 100, 10, 1}; if (num == 0) { text[0] = '0'; text[1] = 0; return; } for(int digits = 0; digits < 5; ++digits) { text[index] = '0'; while(num >= decDigits[digits]) { num -= decDigits[digits]; text[index]++; } if ((index != 0) || (text[index] != '0')) // comment this line to pad the string with zeroes index++; } text[index] = 0; } -
muzay reacted to roadrunner84 in ADC to UART problem
I think you're reading the ADC correctly, but have you set up the ADC to do the sampling?
UART_TX() seems to accept character arrays (ie: strings), but you pass it an integer value. First convert the integer to a character string before passing it to UART_TX()
unsigned short value=ADC10MEM; char text[6]; // Longest string is "65536", which takes 6 characters (including the null termination) itoa(value, text, 10); // convert the value to a text string in base 10 numbers UART_TX(text);