teachop / FlexCAN_Library

Arduino library for CAN on Teensy 3.1
The Unlicense
154 stars 122 forks source link

Added 33333 bps #14

Open Mike4U opened 8 years ago

Mike4U commented 8 years ago

Added the General Motors SWCAN (Single Wire CAN) bus speed. Added the part used to test on a Chevy SparkEV

Mike4U commented 8 years ago

Closed issue #10 prematurely accidentally but will leave as is for now.

Mike4U commented 8 years ago

Added some info on this to the Teensy and Chevy SparkEV forums. https://forum.pjrc.com/threads/33306-SWCAN-bus-hack-allows-backup-camera-display?p=98031&viewfull=1#post98031

xboxpro1 commented 8 years ago

Hello Mike, how did you calculate the values for 33333 bps?

Thanks..

Mike4U commented 8 years ago

Sorry, back when I was working this I could have told you in painstaking detail but apparently did not properly document my procedure. (My early alzheimer's doesn't help)

I started with fnOptimalCAN_clock() which gave me bad results: FLEXCAN0_CTRL1 = (FLEXCAN_CTRL_PROPSEG(7) | FLEXCAN_CTRL_RJW(2) | FLEXCAN_CTRL_PSEG1(6) | FLEXCAN_CTRL_PSEG2(0) | FLEXCAN_CTRL_PRESDIV(19)); I think that violated some details in the kinetis CAN documentation.

I had previously been successful with an ArduinoDue using Collin Kidders DueCan library. It's a different chip with different registers and operation but the timing details should work out the same. So I iterated around somehow with part of fnOptimalCAN_clock() with the speeds that worked vs DueCan speeds to figure out a way that would solve for the difference and then for the 33333. Kind of a four equations four unknows where some of the unknowns were easily guessed from spec documents. I don't know if it's optimal but has worked without a glitch for 3 months on a Checy SparkEV single wire bus.

Mike4U commented 8 years ago

Sorry didn't want to close (again)

xboxpro1 commented 8 years ago

Thanks for the reply, teachop calculate with Number of Time Quanta per Bit-time ->16.

clockspeed/(baud*Time Quanta per Bit-time) - FLEXCAN_CTRL_RJW = FLEXCAN_CTRL_PRESDIV

16Mhz / (250k*16) -1 = 3

I found an excel file on this page ... https://community.nxp.com/thread/118136 and calculations on this page... https://community.nxp.com/thread/109010

Maybe anyone have an excel file to calculate the values for the MK20DX256 Flexcan. I dont want to guess..

Thanks .... CAN_setup1.zip