⬆️ ⬇️

Win CAN bus. Part 1. Technology

image



Today I want to introduce you to the interesting CANNY microcontroller platform. This is a review article in which you will learn about technology, and in subsequent articles I will tell you about working with CAN messages, CANNY integration with the Arduino Mega Server, and about the possibilities offered by this bundle.



Why canny? From the name of the CAN bus, which is widely used in transport and, in particular, in all modern cars as an onboard network. So, what can be done with a specialized controller connected to the CAN bus of your car?



CAN bus



Figuratively speaking, the CAN bus is the nervous system of your car. It transmits all the information about the status of units and systems, as well as control commands, which largely determine the behavior of the car. Ignition headlights, opening and closing doors, controlling the playback of music in the car, the alarm is triggered, etc. - all this works and is controlled by this bus.

')

Physically, the CAN bus consists of two intertwined wires and is very easy to install and connect. Despite its simplicity, due to its differential nature, it is well protected from various interferences and interferences. High reliability and long network length, up to 1000 meters, helped CAN to gain wide popularity among manufacturers of various, not only automotive, equipment.



CANNY controllers



This is a whole family of specialized controllers with built-in native support for working with the CAN bus. This applies to both the “iron” part and the support at the “software” level.



image



The flagship of the line is the controller CANNY 7, the most powerful and having the most features. A large amount of memory, powerful outputs that allow you to directly control the car relay, intelligent protection system against short circuits, protection against inrush current and voltage in the vehicle’s on-board network - all this makes this controller a great solution for translating any of your ideas and projects.



image



In addition to CANNY 7, there are several more models in the line of controllers; we will conduct our experiments with the simpler embedded model CANNY 5 Nano. It also supports work with the CAN bus, but at the same time is similar to the Arduino Nano already familiar to us.



Visual programming





image



Developed support for the CAN bus is not the only feature of these controllers. Besides, CANNY has its own programming environment, CannyLab, but not “normal”, but a visual one, where the whole process of writing programs is reduced to manipulating ready-made structural blocks, setting their parameters and connecting inputs and outputs of these blocks in a certain sequence, in accordance with the algorithm of the problem being solved.



Not a single line of code!



Is it good or bad? In my opinion, this is a matter of habit. As an accustomed to “traditional” programming, it was unusual for me to manipulate blocks instead of writing lines of code. On the other hand, there are many adherents of just such an approach to the compilation of algorithms and it is believed that for engineers and non-programmers this is the simplest and most accessible method of programming microcontrollers.



At least it was “fun” for me to compose programs in this way and after a while I even began to like it. It is possible that if you continue to do this, then after a while writing code will seem inconvenient.



CannyLab is a free development environment and you can freely download it from the developers site, it also does not require a special installation procedure - just unzip the file with the archive - and you can start working.



Connection



Connecting CANNY 5 Nano to a computer is not much different from connecting Arduino controllers. If there is a Silicon Labs CP210x driver in the system, or after it is installed from the downloaded CannyLab distribution, Windows creates a virtual COM port and CANNY is ready for use. In my case, it took more to restart the computer, but perhaps this is a feature of my system.



Practical examples



Let's use simple examples to analyze how to perform actions in CannyLab, which are familiar to us in the Arduino IDE. Let's start with the traditional LED blinking.



At the CANNY 5 controller, at the C4 (Channel 4) pin, there is a test LED (similar to the LED located at pin 13 in the Arduino). And it can also be used for display and experiments, which we will use.



What do you need to blink the LED in the controller CANNY? All you need to do is do two things - configure the pin of the fourth channel as an output and send a PWM generator signal to this output. We have already done all these actions in the Arduino IDE, let's see how it looks in CannyLab.



So, we configure pin of the fourth channel as an output



image



We configure the PWM generator. We set a period of 500 milliseconds, the fill is 250 milliseconds (that is, 50%) and 1 (true) at the input of the “Start” generator and ... everything! There is no need to do anything else - the program is ready, it remains only to pour it into the controller.



image



Simulation mode



Here you need to say a few words about the process of simulation on the computer of the controller and pouring the developed program into the memory of the “iron” controller.



image



The CannyLab development environment allows you to run and debug a program without writing it to the controller’s memory. In the simulation mode, you can see the result of the program right in real time and even interfere with its work.



Filling controller



For the CANNY controllers to work, before filling the program (in the terminology of the "diagrams" developers), you must first fill in the operating system "Device / System Software / Write". This needs to be done only once, for this you need to select the file with the .ccx extension that matches your controller.



After the program is written and debugged, it can be downloaded to your controller. This is done simply - in the menu, select the item “Device / Diagram / Record” and after a few seconds the program is recorded in the controller.



Next, you need to disconnect the controller from the computer's USB port, remove the jumper on the board and you can turn on the programmed controller, which after switching on will work according to your program.



Analog inputs



In order to better understand the principle of programming CANNY controllers in the CannyLab development environment, let's take another look at an example of working with an analog input in this system.



We will monitor the voltage level on the 10 pin controller and if it is in the range of 2.5 V ± 20%, we will light the built-in LED.



As in the previous example, we configure the 4th pin as an output in order to be able to control the operation of the LED.



image



Turn on the ADC on the 10th channel.



image



Next, we use two logical blocks that give 1 to the output if the voltage is in the specified range. Full range from 0 to 4095.



image



The “Logic And” block completes the work and controls the operation of the LED on the board from its output.



That's all. What we used to do on the Arduino, we easily made in CannyLab. It remains only to get comfortable in this programming environment and you can easily and naturally create your projects on this platform.



These simple programming examples are provided so that you can understand the principle of visual programming of CANNY microcontrollers. In the future, you will be helped by excellent reference documentation and developer support on the site and the forum of the system.



Conclusion on the introductory article cycle



By connecting the CANNY controller to your car, you will be able to implement many interesting and unique ideas, for example, non-standard alarms that are not so easy to open (due to its non-standard) or add new features that you dreamed about but did not expect that it could be implemented on practice.



If you like visual programming in the style of CannyLab, then CANNY controllers can be an interesting alternative to Arduino for you or work in conjunction with Arduino controllers. We will discuss this in the second article of the cycle, in which I will tell you about the integration of CANNY controllers with the Arduino Mega Server system .



Let me remind you that AMS now works not only on Arduino boards, but also on ESP8266 wireless Wi-Fi modules, and this particular bundle will be discussed next time.



And as usual, stay with us, it will be interesting!

Source: https://habr.com/ru/post/369429/



All Articles