PDA

View Full Version : CAN-BUS at wit's end and job on the line. PLEASE HELP!



canadianaidan
- 20th October 2010, 19:53
Hi there.

I'm hoping someone with experience with the CAN-BUS system is able to help me out. I've been researching CAN-BUS for about three months now. It still seems like I'm learning new things daily. I have a problem however, my boss is becoming concerned with the fact I have no "working" hardware. I have made protoboards based on Michael Wolf's USB-to-CANBUS and had only lights blinking with no actual messages being acknowledged by the program. I've tried the chep "simple" CAN node that futurelec.com offers and had no luck with it and no support from the sellers. Now I'm trying to make some simple nodes using the PIC18F6585 and a MCP2551 tranceiver OR a PIC18F2480 with an MCP2551 tranceiver.

There are a few issues I'm having with my code.
I struggling even to just get a proper CAN message to transmit.
I see what looks like a valid CAN message go out on the line but then I can't see it received on my PC program window.

I'm using the dev kit MCP2515DM-BM from Microchip. It comes with software called MCP2515 Bus Monitor 1.0.

The documentation states that this node is configured for 125 kb/s and the receive buffers are wide open.

The Bus Statistics on the progrm are as follows:
Bus Speed: 125.000 kbit/s
Bit Timing: Q=10, S1=3, S2=3, SP=70.0%, SJW=1

So here is my problem.
I put power to my node and it kicks out a "can" message from the tranceiver on the can H and can L BUT the PC program does not show that it has received a valid can message. The weird thing is.... The RXCAN light of the dev board is solid (on) and I can change the state of the TXCAN light by changing my input switch data on the pic portD. The TXCAN light will go from solid to not-on to partially light with dirrerent switch data from portD. When I scope this TXCAN pin I see a one blip message (single shot) at a fixed rate when it is either solid or partially lit. I am wondering is this is an acknowledge message that the node is trying to send out? If it is, why would the interface program not register this transmit? Also strange is that a separate TX light that comes on in loop back mode does not light in response to the TXCAN light near the bus. I.E. There is one TX light and one TXCAN light but they are not lighting at the same time when lighting in response to my “can” message, only in loopback mode.

So now I've looked more thoroughly at the timing requirements for the bus and what I have programmed into the PIC. I know that the timing values in my code as not the match for the bus I am connecting to but let me explain my reasoning:

Code Timings:
movlw 0x41 ; Set RJW to 2, prescaler set to 2
movwf BRGCON1,A ;"
movlw 0x89 ; Take one sample, set phase_seg1 and
movwf BRGCON2,A ; Set Porp_seg 5
movlw 0x41 ; Enable wakeup feature, set phase_seg2 to 2
movwf BRGCON3,A ; "

Timings given to me by MBTime from Microchip:

Setup Criteria
Oscilator Frequency 20.000 MHz
Target CAN Bus Baud Rate 125.000 kbps

Selected Options
BRP-1 (Baud Rate Prescaler) 7
Tq (Time Quanta) 800.000 ns
Number of Time Quanta 10
% Error of Target Baud Rate 0.0 %

Bit Timing Setup in Tq
Propagation Delay 1
Phase Segment 1 5
Phase Segment 2 3
Syncronization Jump Width (SJW) 1
Configuration Register Setup (PIC18/MCP251X) (neoVI blue/green, ValueCAN 2)
Register Binary Hexadecimal
CNF1/BRGCON1 b'00000111' 0x07
CNF2/BRGCON2 b'10100000' 0xA0
CNF3/BRGCON3 b'00000010' 0x02

I got these hex values from MBTime, Microchips, CAN-BUS Timing Calculator.
I believe these timings are generated for the MCP2510 but I am unsure. Like I said I'm using an MCP2551 so I don't know if that is where my trouble is coming from.

So the reason I did not stick with the "correct" timings I collected from MBTime is that it changes how the dev board reacts to my "CAN message". I can't get the TXCAN light to come on at all when I have programmed with these "correct" timings. So that leads me to believe that the original timings on my included code are closer to what the bus expects because I can get the TXCAN to light up using those.

Another problem with my code is that the switch data from portD is not being updated "on-the-fly". I.E. - I have to power down the pic, adjust the switches, then power it back up and the message changes. Please any suggestions on how to have this data update in real time?

If someone can help me get the switch data to appear as a valid CAN message on my monitor window, I would be forever indebted.

I've got a few other parts, MCP2515, MCP25050, MCP25020, as well as a PIC2480. I am willing to try these parts as well to get a simple node working. I really just need some working hardware or ANY kind sending ANY can message, so long as it will register on my CAN PC monitor program.

Perhaps someone has some C code or knows how to use the CAN libraries? I only know assembly so I haven’t really been able to play around with many example programs.

If you can reply sooner than later, that would be appreciated. Honestly my job depends if on if I have working hardware within the next few days. If I can't get this working they will be cancelling the CANBUS project and the shop is to slow to keep me for production.

PLEASE PLEASE PLEASE!!! SOMEONE HELP ME!!!

I have attached my current code as well as a picture of the setup and a picture of the "single shot" the TXCAN pin is showing.

Thank you kindly guys and gals!!!

canadianaidan
- 20th October 2010, 22:31
I have looked into/over 4 gigs of notes, papers, CAN logging programs. This is the closest I've got to working hardware. If you take a second to look at the picture I took of the setup, you will see that there are three nodes on the system, but I have taken off one of the microchip nodes and the system reacts identical to how I previously described, but with the lamps only lighting on the other node.

I have also read,
The Quintessential Microcontroller
An Introduction to Software and Hardware Interfacing
A Comprehensible Guide to Controller Area Network
Embeded Networking with CAN and CANopen
Bosch 2.0 IS0 Part 1,2,3,4
All application notes from microchip
All datasheets on PIC CAN family
All forums.
Even Errata on the PIC18F6585

Like the subject line said, I am at wit's end!!!!

I have no idea why my code or hardware is not producing a VERIFIED CANbus message.

Jerson
- 21st October 2010, 02:31
I'd like to help, but, I have absolutely no experience with CANbus.

I've looked over your code, and it seems you are doing the initializations over and over again in the MainLoop. Maybe you need to? I don't know. I feel the mainloop tag should ideally be at this line
; SAVE PORTD DATA: READ INPUTS ON PORT D AND STORE VALUES INTO MYDATABYTE0
Perhaps that could be the issue.

Another point is to calculate the baud rate by hand for your particular setup to be sure you got everything right. Once the hand calculation checks out with the Microchip tool, you could use the tool blindly; but, for now, you need to be sure. No point in guessing if it is right or wrong.

Hope this helps

canadianaidan
- 21st October 2010, 16:10
Thanks for your suggestion. I believe I have tried without looping to the config part of the code and it didn't seem to help. I beleive my issue may be one of timing. I've looked at the formulas but I get lost so quickly. It's not that I have no math skills, I just havent worked with any of these values before.

I'm going to hook up the scope and put both waveforms over one another from the working dev kit and then what my unit is outputting. If the rise and fall times do not change state on the same vertical lines, does that mean my timing is off in one system?