Distorted Signal Transmission RawCAN

8 years 3 months ago - 8 years 3 months ago #29530653 by Trainee
Hello,

I have a HBL1650. I am using RawCAN mode to send CAN frames to computer for data acquisition purpose. I first generated a sinusoidal signal of 2Hz, with 2V peak to peak amplitude and wired the signal into one of the analog input of the controller HBL1650. I then wrote a RawCAN microBasic script to read the sinusoidal signal and send the value in a CAN frame.

The problem is after I have acquired the CAN frame and done some calculation from the 8 bytes of the CAN frame to extract the value of the sinusoidal signal, I saw that the signal is distorted.

Below is my RawCAN script:
top:			
	
				pending = GetValue(_CF) 'check if any frames are present in the 16-trames FIFO buffer
				canID = GetValue(_CAN, 1)  'get the ID of the CAN frame received
				if pending <> 0 then  'if CAN frame present then
				'Read
				canDataLength = getValue(_CAN, 2) 'get the length of CAN frame (number of bytes)
				canData1 = getValue(_CAN, 3) 'get byte 1
				canData2 = getValue(_CAN, 4) 'get byte 2
				canData3 = getValue(_CAN, 5) 'get byte 3
				canData4 = getValue(_CAN, 6) 'get byte 4
				canData5 = getValue(_CAN, 7) 'get byte 5
				canData6 = getValue(_CAN, 8) 'get byte 6
				canData7 = getValue(_CAN, 9) 'get byte 7
				canData8 = getValue(_CAN, 10) 'get byte 8
	
				end if 
				
				setCommand(_CANSEND, 1, canID)
				
				time=getvalue(_TM,1)
				
				anain1=getvalue(_ANAIN,1)
				reste_anain1=anain1 mod 256  
				anain2=anain1/256
			
				setCommand(_CANSEND, 3, reste_anain1)
				setCommand(_CANSEND, 4, anain2)
				setCommand(_CANSEND, 5, time)
				setCommand(_CANSEND, 6, 0)
				setCommand(_CANSEND, 7, 0)
				setCommand(_CANSEND, 8, 0)
				setCommand(_CANSEND, 9, 0)
				setCommand(_CANSEND, 10, 0)
				setCommand(_CANSEND, 2, canDataLength)

				wait(1)	
		
goto top

I have attached an image of the signal that I got after being transmitted through CAN bus.






I have tried adding a "print(time,";",anain1,";",reste_anain1,";",anain2,"\n")" line into the code and copied the result from Roborun console page into the text to see if the signal is distorted. It wasn't. But when it was transmitted through CAN bus, the signal wasn't the same as the original. There is an offset on the signal.

The weird thing is when I change the line "anain1=getvalue(_ANAIN,1)" to "anain1=2536", which is a fixed value, I got a the same value of 2536 even after being transmitted through CAN bus. So I assume that the error doesn't come from the CAN bus. But I don't know where does the error come from.




CAN anyone explain to me where does the error come from please?
Attachments:

Please Log in or Create an account to join the conversation.

8 years 3 months ago #29530655 by TechSupport
If the connection is made at the analog input, can you verify that there is noise on the analog input line? Go to the run tab and look in the upper right hand corner.

What you would look for is fluctuations on the line; is the value of the signal bouncing around rather than having a smooth change?

You can try adding in some capacitance on that line to smoothen it out. 16V 1uF capacitor on ground and the analog input.

Please Log in or Create an account to join the conversation.

8 years 3 months ago #29530656 by roboteq
Replied by roboteq on topic Distorted Signal Transmission RawCAN
data that in _CANSEND is 8 bit.

Anain2 is 16 bit

data is truncated

you need to send the top 8 bis in _CANSEND, 4 and the lower 8 bit in _CANSEND, 5.

Like this

_CANSEND, 4, Anain2 >> 8
_CANSEND, 5, Anain2 and 0xff


you need to so the same with time if the value is higher than 255

when receiving, you need to reconstruct the 16-bit value from data receved in 2 _CAN

Please Log in or Create an account to join the conversation.

Moderators: tonysantoni
Time to create page: 0.063 seconds