2388 views|3 replies

3

Posts

0

Resources
The OP
 

422 The receiving light is unstable, affected by the running time of the main function [Copy link]

This post was last edited by Suoyuedudu on 2019-12-14 13:58

I would be very grateful if a great god passing by could help me solve the problem that has troubled me for a long time.

The chip used is AT90CAN128. The function is to turn on the light after the serial port receives a complete frame of 422 data, and then send it out through serial port 1. The oscilloscope has measured the waveform of the 422 received data. The reception is complete and the data is correct . But the light is unstable. The light program is placed in the serial port interrupt reception and the main function, and it will be disturbed. The same is true for other MCU pins. So I measured the waveform of the light pin and the running time of the main function;

(Main function running time test: use the free pins of MCU in the main function and flip the level every time the main loop comes in)

Due to special reasons, the timer is set to 8.139ms. The main function running cycle is measured to be about 400ms, 422 receives once every 230ms, and the light is on after receiving the complete signal.

In the figure, the first one is the 422 receiving waveform (at the MCU pin), the second one is the 422 light waveform, which is on at a low level, and the fourth one is the main function execution cycle waveform.

This post is from Microchip MCU

Latest reply

The so-called "unstable lighting" is caused by your programming error, not "interference" problem. If your "lighting logic" is just to change a certain IO state after receiving a complete frame of serial port data, then you can put an assignment instruction of the IO in the serial port interrupt, and then just pay attention to the "lighting off logic".   Details Published on 2019-12-14 14:22
 

1w

Posts

142

Resources
2
 

The so-called "unstable lighting" is caused by your programming error, not "interference" problem. If your "lighting logic" is just to change a certain IO state after receiving a complete frame of serial port data, then you can put an assignment instruction of the IO in the serial port interrupt, and then just pay attention to the "lighting off logic".

This post is from Microchip MCU
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

3

Posts

0

Resources
3
 
This post was last edited by Suoyuedudu on 2019-12-16 09:11
chunyang posted on 2019-12-14 14:22 The so-called "unstable lighting" is caused by your programming error, not "interference" problem. If your "lighting...

Thank you for your reply ~~~ Please help me look at the program logic. I really can't analyze it. The light-on program is unstable when I put it in the serial port interrupt and the main function.

1. This is the 422 serial port interrupt receiving program

/***************Serial port 1 axle counting device interrupt reception*******************/
#pragma interrupt_handler Rx1_isr:33
void Rx1_isr(void)
{
unsigned char temp, i;
unsigned int tempii;
temp = UDR1;
if ((temp == 0xFE) && (Rx1BFlag == Start))
{
Rx1Flag = Start;
receive1_no = 2;
Rx1BFlag = 0;
}
else
{
if (temp == 0xFB) /*Frame header detection*/ //Receive 18 bytes, the frame header is FB FE
{
Rx1BFlag = Start;
}
else
Rx1BFlag = 0;
if (Rx1Flag == Start) /*Receive data*/
{
JzStatA[receive1_no] = temp;
receive1_no++;
if (receive1_no >= 18)
{
receive1_no = 0;
JzStopCount = 0;
Rx1Flag = Finish;
JZLedCount = 0; //Turn on the communication light
PORTD &= ~(1 << PD4); //Turn on the communication light PD4
for (i = 0; i < 16; i++)
{
JZ_crc_buffer = JzStatA[i + 2];
}
}
}
}
}

2. Procedure for lighting and counting in the timer:

/*********T/C1 compare interrupt**********/
#pragma interrupt_handler timer1_comp_isr:13
void timer1_comp_isr(void) //8.139ms
{

if (JZLedCount++ >= LEDTime)
{
JZLedCount = LEDTime;
PORTD |= (1 << PD4); //422 LED turns off PD4
}
}

3. Timer initialization and interrupt procedure

/***************** Initialize timer 1 *****************/
void init_Timer1(void)
{
TCCR1B = 0x00; //Turn off timer 1
OCR1AH = 0x1D;
OCR1AL = 0x4C; //8.139ms 7.3728M
TCNT1H = 0x00;
TCNT1L = 0x00; //The initial value of the count is set to zero
TCCR1A = 0x00; //Compare match A output
TCCR1C = 0x00; //Trigger OC3A when compare match, OC3X is the original OC3X inverted
TCCR1B = 0x0A; //Start timer 1, 8 division, CTC mode
TIMSK1 = 0x02; //Timer1 compare match interrupt enable

/***************Timer 1 interrupt register configuration**************/
void InitIER(void)//2015.4.7
{
SMCR = 0x00;
EICRA = 0x00;
EICRB = 0x00;//INT4 low level edge trigger 0x00//rising edge 0x03//falling edge 0x02
EIMSK = 0x10;//External interrupt 4 enable 1CAN-INT or 2CAN-INT
EIFR = 0xFF;
}

4. Initialization of serial port 1
void ini_USART1(void)
{ // desired baud rate:9600
UBRR1L = 47; //7.3728M:47
UBRR1H = 0x00;
UCSR1A = 0x00;
UCSR1B = 0x98;
UCSR1C = 0x06;
PORTD &= ~(1 << PD1); // turn on sending

}

This post is from Microchip MCU
 
 
 

3

Posts

0

Resources
4
 
chunyang posted on 2019-12-14 14:22 The so-called "unstable lighting" is caused by your programming error, not "interference" problem. If your "lighting...

Can you help me check the logic of the code?

This post is from Microchip MCU
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list