View previous topic :: View next topic |
Author |
Message |
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
CAN-SPI Board with MCP2515 |
Posted: Tue Feb 09, 2016 3:57 pm |
|
|
Hi all,
This is my first post here, I am new to Microcontrollers.. almost a month old I should say.
I was able to connect multiple PIC16F and my raspberry pi using I2c however i2c has the limitation of real estate hence I am trying CANBUS now
I would like to keep the cost down hence planning to use PIC16F73 and a canspi board. just like the one here
Has anybody done anything like this here before? I have been searching this forum for quite sometime now and could not find any posts related to this.
Can Somebody share some sample code so that I can understand what needs to be done.
Thanks in Advance. _________________ Regards,
Devil |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Tue Feb 09, 2016 5:41 pm |
|
|
well the picture is nice BUT you should post a link to the product as well as any mfr/make/model numbers to help us help you.
the CAN bus has a huge overhead in terms of SW and some major pitfalls. Need to know how many sensors and distance you are thinking of having. RS-485 is quite easy,cheap, fast and good for distance.
There are other 'busses' or 'networks' that may work for you. Knowing more about your project will help.
Jay |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Tue Feb 09, 2016 6:05 pm |
|
|
CAN has a huge learning curve, particularly if you're a microcontroller virgin. A simple serial link would probably get you going quicker with less effort than CAN. |
|
|
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Wed Feb 10, 2016 4:01 am |
|
|
In all honesty, just use standard RS485 serial.
You are unlikely to be able to fit the code to operate a Can controller into a small PIC like the 16F73. There is a lot of work involved in this (probably more than a basic Modbus configuration). The advantage of Can, is that once configured, the controller does a lot of the work for you, so automatically identifying messages for you etc.. However this is complex to use, and I'd not want to try to fit this into such a small PIC.
Now if this is for your own project, then 'KISS', and just design your own simple protocol. Think about what you want, and what has to be sent. So you need to read three temperature sensors. Just have each with a simple RS485 interface, and have them all sit 'listening' on this. Then have a simple communication like:
T1<LF>
T2<LF>
etc..
Have the replies be equally simple. So something like
txnnnc<LF.
Using 't' lowercase for the reply, with 'x' being the sensor that is replying, then 'nnn' being the temperature in some suitable integer unit, and 'c' being a simple XOR checksum of all the bytes up to this point.
Your master can then just send a request and get a reply. If it doesn't get a reply in (say) a few seconds, it can ask again. If the checksum is wrong, it can again ask again. After say 10 failures it can alert that it is not getting the required data.
With standard RS485 transceivers, at low rates this can send miles. Reliable, and the code is relatively simple (most of the 'old hands' here could probably have this running in a couple of hours).
CCS has serial code for you, including the option of controlling a transceiver (so allowing a 2wire bus).
Something like this is hundreds of times simpler than either trying to push I2C for longer distances (I suspect this is what you are referring to by 'real estate'?), or use a complex bus/protocol like Can or Modbus.
The reason for more complex busses, is where there are a much larger number of devices, and much more complex commands/responses needed. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Wed Feb 10, 2016 7:05 am |
|
|
I agree with second Mr T ! Use RS485 BUT use ethernet cable for the connections. That way you can suppy power and data on the wires. Use 2 conductors for each though( +pwr,+dta,-dta,gnd) that way you'll get good power and data to all the remote boards.
These days premade CAT cables are cheap AND you can color them to designate their location.
Be sure to run say +12 for the power and have local regulator to power the individual remotes. I used +24 and could go around noisey building for 1/4 mile.
Jay |
|
|
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
Thank you!! |
Posted: Mon Feb 15, 2016 4:38 am |
|
|
Thanks for responding Mr T and Temtronic..
I am sorry for the late response as I was on vacation
@Temtronic,
Ethernet cables would be useful, but it would be really bulky to fit into the existing wiring panels. One of the reason I was planning to use CAN or MODBus was to reduce the wires required for communication.
I was planning to send 12V with a 4 coil wire and then use a regulator to get 5 Volt.
I would then use an SSR to activate the blower. KISS like Mr T _________________ Regards,
Devil |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Mon Feb 15, 2016 4:48 am |
|
|
The suggestion from Temtronic was to _reduce_ the wiring....
Don't get confused and think of Ethernet wiring as being Ethernet plugs etc..
He was talking about using T568 / 568AA cables to supply both signal and power.
All of the busses being talked about need cables. Canbus uses a twisted pair cable by default. Typically something like 3600X. Modbus RS485, normally uses a 6 core cable, and commonly uses T568A cable when power is included. You are going to need a known impedance twisted cable for the data, for any of these connections, and T568 is about the cheapest cable you can get, with enough pairs to include the power in the same wire. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Feb 15, 2016 6:46 am |
|
|
Actually using Ethernet will be less bulky, cheaper and easier. Consider that in addition to neding twisted pair to every 'slave' you also need power(another pair of wires) at each slave. Usually there isn't easy access to power where the air duct dampeners are. By using 'ethernet' cables and connections you get 4 pair and factory made connections. Now you could go 'analog' as I did for in my house with buffered LM34 as the slave sensors and a PIC as the host controller. It's been reliable for 2 decades. If you go 'digital' with PICs as slaves and host you must ensure clean signalling and RS485 through ethernet is proven technology.
Using 'off the shelf' cabling and connectors also allows you to color code remotes and quick replacing of faulty slaves. Pop off one connector, done! NO screw terminals, miswiring, lost screws, etc.
Supplying power in the same cable (aka POE or Power Over the Ethernet) allows for a common power supply (at the host location) which reduces wiring and fault finding.
In my remote energy systems I'd pull up to 1000 meters of cable through a plant and feed all the slaves from one 'host' power supply. Needed 24 volts due to line loss but system has been 100% reliable for 30 years.
RS485 with enet cable is probably the best way to go though I should point out that it all can be done on a single conductor if you want to be different than the rest of the crowd.
I tend to look at projects from a reliabilty aspect. What is needed to be done to NOT get phone calls at 3AM complaining about 'no heat'!
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Mon Feb 15, 2016 8:03 am |
|
|
I think he is talking about having quite a heavy power wire, which might be why he is 'anti' the Ethernet wiring solution?. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Feb 15, 2016 8:46 am |
|
|
hmm we need more information that's for sure! Especially the servos that will control air flow. I've seen 4by10 register 'timer - control' units for $5 that are powered by 4AA cells. They could be PICked/ Blutoothed fairly easily.
I prefer the hardwired approach for reliablilty though.
Jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Feb 15, 2016 12:04 pm |
|
|
Hi,
Call me a cynic, but I'm highly dubious that this project/issue has anything at all to do with CCS 'C'!
I think the OP needs to find a general purpose electronics forum!
John _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
Thank you gurus |
Posted: Wed Jun 01, 2016 10:07 am |
|
|
Thank you all for helping out and YES! now i think this thread that I started never contained anything about CCS C!
You guys and this forum helped me learn a lot of things about microcontrollers and CCS C.
Ttelmah -
temtronic - Jay
ezflyr - John
You guys are really great!!! and helped me a lot!!!
I started studying more on Microcontrollers, I am trying to implement what I mentioned in this thread with UART over RS485 in CCS C
There are a lot of helpful threads here that helped me out.
Again I understand that this post is really really late, but I would like to thank you all for helping me out.. this is a really great place. _________________ Regards,
Devil |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
Re: Thank you gurus |
Posted: Thu Jun 02, 2016 3:58 am |
|
|
devilfrmheaven wrote: | YES! now i think this thread that I started never contained anything about CCS C!
|
Dude, I can smell a 'forum miscreant' a mile away!
But, nice try anyway! _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
|