TroubleshootingBluno

How to use SEN0240 in ATmega128

userHead Duminuss 2022-05-15 03:16:30 1251 Views2 Replies

I bought SEN0240 EMG sensor, and I try to get signal through AVR ATmega128 MCU.

But it doesn't work well.

I visualize data by uart communication by using terminal.

It shows to me data value is 0 or several hundred.

 

ADC works normally as I tested by variable resistor.

Power for sensor is 5v and ADC reference voltage is also 5v.

 

By using sample code, the sensor would be work in arduino uno.

I think problem is if the emg signal can be detected with ADC of ATmega128.

 

Can anyone give me a solution for this problem?

 

Thanks.

2022-05-16 00:28:08

By using sample code, the sensor would be work in Arduino UNO. → So did you test the EMG sensor with Arduino UNO and work fine? 

The ADC of ATmega128 is also 10bit, the same as Arduino UNO, so it can detect the sensor signal.

BTW, could you share your codes on ATmega128?

 

userHeadPic Youyou
Duminuss wrote:

I don't have Arduion UNO but I see it works by sample code in youtube.

 

The code is simple that receiving analog signal using ADC and check it with LED flashing, UART.

Here is my code written at avr studio 4.19.

 

#include <avr/io.h>#include <stdio.h>#include <avr/interrupt.h>#include <util/delay.h>#include <math.h>

int ADC_Read, ADC_RMS_VALUE;static int Putchar(char, FILE *);void UartTx(char);unsigned int read_adc(unsigned char);

 

int main(){UCSR0A=0x00;UCSR0B=0x18;UCSR0C=0x06;UBRR0H=0x00;UBRR0L=0x67;

DDRA = 0xFF;  ;

ADMUX=0b01000000;ADCSRA=0b11001111;

fdevopen(Putchar, 0);asm("sei");

 

while(1){ ADC_RMS_VALUE = ADC_Read;

 printf("EMG_Sensor : %d\r\n", ADC_RMS_VALUE);  if(ADC_RMS_VALUE < 80) {  PORTA = 0b11111110; } else if(ADC_RMS_VALUE < 160 && ADC_RMS_VALUE >= 80) {  PORTA = 0b11111100; } else if(ADC_RMS_VALUE < 240 && ADC_RMS_VALUE >= 160) {  PORTA = 0b11111000; } else if(ADC_RMS_VALUE < 320 && ADC_RMS_VALUE >= 240) {  PORTA = 0b11110000; } else if(ADC_RMS_VALUE < 400 && ADC_RMS_VALUE >= 320) {  PORTA = 0b11100000; } else if(ADC_RMS_VALUE < 480 && ADC_RMS_VALUE >= 400) {  PORTA = 0b11000000; } else if(ADC_RMS_VALUE < 560 && ADC_RMS_VALUE >= 480) {  PORTA = 0b10000000; } else if(ADC_RMS_VALUE < 640 && ADC_RMS_VALUE >= 560) {  PORTA = 0b00000000; } _delay_ms(100);  }return 0;}

 

SIGNAL(ADC_vect){ADCSRA = ADCSRA|0x40;ADC_Read = ADCL + (ADCH << 8);}

 

void UartTx(char message) {    while((UCSR0A & 0x20) == 0);    UDR0 = message;    UCSR0A |= 0x20; }    static int Putchar(char c, FILE *stream) {UartTx(c);return 0;}

 

unsigned int read_adc(unsigned char adc_input){ADMUX=adc_input | (0x40 & 0xff);_delay_us(10);ADCSRA|=0x40;while ((ADCSRA & 0x10)==0);ADCSRA|=0x10;return ADCW;}

2022-05-16 16:01:03
1 Replies