strange wireless problem (433MHz)

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I`ve a strange problem with my wireless communication. I`m using the AT90CAN32 to communicate wireless with my PC. The purpose of the pcb i`ve developed, is to drive two motors with PWM. Each time there is communication the 2 PWM registers will be updated.

The problem is that sometimes the motor disturbs... I think that updating the OCR registers with a high frequency is a problem? You will find my code below:

SIGNAL

SIGNAL(SIG_UART1_RECV)
{
//DATA FORMAT:  | <00> |  | <00> |  | <80> | 8 x  |  |

	ontvangen = UDR1;

	if(data_detected == 1)
	{	
		if( read_count < (DATABYTES + 1) )
		{	
			data[read_count] = ontvangen;
			
			if(read_count < 8)
				crc_byte = crc_byte + data[read_count];
			
			read_count++;
		}
		else
		{
			//CRC check
			while (crc_byte > 255)
			{
				crc_byte = crc_byte - 255;
			}

			if( (crc_byte == data[8]) && (ontvangen == 80) )
			{
				//Juiste data
				data_received = 8;
				reset_vars();
			}
			else
			{
				reset_vars();
				crc_byte = 0;
			}
		}
	}
	else
	{
		if(ontvangen == 80 && vorige_waarde == 255)
		{
			data_detected = 1;
			read_count = 0;
		}
		vorige_waarde = ontvangen;
	}

}

MOTOR FUNCTION

void motor_control(void)
{

	pwm_value1 = (data[0] * 256) + data[1];
	pwm_value2 = (data[2] * 256) + data[3];

	//bepalen of het 'gas' los is of niet

	if(pwm_value2 == 255)
		PORTE = (1<<PE2);
	else
		PORTE &= ~(1 << PE2);

	if(pwm_value1 == 255)
		PORTB = (1<<PB7);
	else
		PORTB &= ~(1 << PB7);

	OCR1A = pwm_value1;
	OCR1B = pwm_value1;

	OCR3A = pwm_value2;
	OCR3B = pwm_value2;


}

MAIN

	do{

		if(data_received == 8)
		{
			no_signal_counter = 0;
			
			motor_control();

			if(data[4] == 20)
				PORTA = (1<<PA4);
			else
				PORTA &= ~(1 << PA4);

			data_received = 2;
		}



	}while(1);

edit: when i send a pwm value for one time, it seems that the motor run smoothly. It goes wrong when updating the OCR registers frequently.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Shouldn't you need to wait for the serial data to receive completely before doing this

ontvangen = UDR1; 

What PWM mode do you set? for driving motor usually i use Phase Correct PWM mode. So when the OCR register receives new value the remaining pulse are keep unchanged until the timer register reaches top. The result is PWM pulse still kept synchronized .

KISS - Keep It Simple Stupid!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the serial data is completely received when entering the SIGNAL ?

/* USART1, Rx Complete */
#define USART1_RX_vect			_VECTOR(32)
#define SIG_UART1_RECV			_VECTOR(32)

the init:

void uart_init(void)
{
	UBRR1H = 0x00;	/* 19200 bps */
	UBRR1L = 0x33;
	/* 8-databit, no parity & 2 stop bits */
	UCSR1C = (1<<USBS1) | (0<<UCSZ12) | (1<<UCSZ11) | (1<<UCSZ10);
	/* Enable receiver and transmitter and interrupt */
	UCSR1B = (1<<RXCIE1) | (1<<RXEN1) | (1<<TXEN1);
}

void timer0_init(void)
{	
	//prescaler = 64 = 1.024ms
	TCCR0A = (0<<CS02) | (1<<CS01) | (1<<CS00);
	TIMSK0 = (1<<TOIE0);

}

void timer1_init(void)
{	
	TCCR1A = (1<<COM1A1) | (1<<COM1B1) | (1<<COM1B0) | (1<<WGM11) | (0<<WGM10);
	TCCR1B = (0<<WGM13) | (1<<WGM12) | (0<<CS12) | (0<<CS11) | (1<<CS10);
	/* prescaler = 1 => 31.25 KHz */
	OCR1A = 255;	/* max = 512 (9-bits) */
	OCR1B = 255;	/* max = 512 (9-bits) */
}

void timer3_init(void)
{	
	TCCR3A = (1<<COM3A1) | (1<<COM3B1) | (1<<COM3B0) | (1<<WGM31) | (0<<WGM30);
	TCCR3B = (0<<WGM33) | (1<<WGM32) | (0<<CS32) | (0<<CS31) | (1<<CS30);
	/* prescaler = 1 => 31.25 KHz */
	OCR3A = 255;	/* max = 512 (9-bits) */
	OCR3B = 255;	/* max = 512 (9-bits) */
}

void port_init(void)
{
	DDRB |= (1<<PB5) | (1<<PB6) | (1<<PB7);		/* PWM output 31.25 KHz + inverted */ 
	DDRE |= (1<<PE3) | (1<<PE4) | (1<<PE2);		/* PWM output 31.25 KHz + inverted */ 
	DDRA |= (1<<PA3) | (1<<PA4);
	DDRD |= (1<<PD0) | (1<<PD1);
}