-2
\$\begingroup\$

Good day! I am a computer engineering student. We are currently creating our thesis project, wherein we use pic16 as our microcontroller. We are really having a hard time on how to receive data from c# to pic in order to activate a certain motor. Hoping if anyone can help us. It would be a great help. Thank you.


Edited to add circuit schematic:

enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Hello Sylvia, welcome to EE.SX. What have you tried so far? Please edit your question and tell us much more about: What motors? How are the motors wired to the PIC? How is the PIC connected to the PC? How is the PIC being programmed? \$\endgroup\$ – rdtsc Apr 4 '16 at 4:56
  • \$\begingroup\$ The motor that we are using is a Savox HV Standard Brushless Servo SB-2273SG-28 kg. We use a UART library in mikro c to program the pic. If its okay, i'll give a link on the circuit: dropbox.com/s/c6c2vadqtmr0fcb/… \$\endgroup\$ – Sylvia Espiña Apr 4 '16 at 5:49
  • \$\begingroup\$ This would entirely depend on what hardware interface you have. Is the communication done over something UART-based, or USB, or CAN, or what? \$\endgroup\$ – Lundin Apr 4 '16 at 8:43
  • \$\begingroup\$ You should provide a schematic or at least a rough sketch. This question is no specific enough. \$\endgroup\$ – Rev1.0 Apr 4 '16 at 10:01
  • \$\begingroup\$ We are using UART-based \$\endgroup\$ – Sylvia Espiña Apr 6 '16 at 2:31
1
\$\begingroup\$

If you don't already have the PIC16F877A datasheet, then get it, and print it. Several copies if there are several members of your team working on this part of the project.

  • On page 5, it shows this PIC as working from DC to 20MHz. The crystal is not labeled in the schematic. It must be between 0-20MHz. Note that the 22pF loading capacitors connected to it are generally more suitable for a lower frequency range crystal, such as 2MHz. This also depends on the exact crystal used - look at it's datasheet and see what it recommends. Any crystal will probably work, but if it is "too fragile", excessively large-value loading caps may damage it, or cause it to operate outside of the indicated frequency.

  • All PICs require a resistor from pin 1 MCLR to Vdd. 33k-10k should work. Reason why is, MCLR is the reset pin. It needs to be allowed to go to ground to reset the PIC. Often, a small capacitor is connected from this to ground also. Think about what this will accomplish when the circuit is first powered on. Research it if this does not make sense.

  • The PIC16F877A uses pins MCLR, PGD, and PGC for programming. Unless you are removing the chip to program it, it's best to not use these pins for anything else (MCLR still has to be wired as previous.)

  • Vdd power is listed as Vcc/Vdd. In a simulator like Proteus ISIS, there is a possibility it could interpret this label as a math function - literally the Vcc voltage divided by the Vdd voltage. It's best to rename it to just Vdd. Use Vcc for the battery or source voltage.

  • I cannot locate a datasheet for the Savox SB2273SG servo. The manufacturer only states it as a digital servo, with a resolution of 12 bits and frequency of 250-330Hz. Digital servos are not my forté (here and here are something to get you started), but it sounds like it needs a control signal of (at most) 12 bits, 300 times per second. 12*300 = 3,600 bits/s or 3.6kb/s or 3.6k/8 = 450 bytes/sec. This is do-able with a PIC clocked at 20MHz and manual coding, but timing will be "fun."

  • The Savox servo is rated for 7.4v and 6.0v supply. It may not work at all (or be unreliable) if powered from Vdd = 5.0v. Vdd can be a maximum of 5.5v per the PIC datasheet page 175. So you may have to use an additional supply only powering this servo.

  • The PWM output (pin RC2) of the PIC may be a better choice (page 67) than pin RB7 and manual coding, but it is more complex. PWM resolution is also 10-bit, meaning that some accuracy in servo position will be lost. For many applications this may not be an issue. This calculator is one of many on the web that will show you what bit rates are available for given crystal frequencies. Looking through a list of common crystal frequencies, I saw that a 18.432MHz crystal can produce a PWM data rate of exactly 3,600 10-bit sequences per second. "C" code is generated as well.

  • Once you get digital data being sent to the servo, you will want to view this signal on an oscilloscope. Make sure the levels are at the correct Vdd and Vss voltages, and no ringing or slow transitions are occurring. If it does not look very crisp and clean, then use a transistor to drive the servo data input. (Like shown in an above link.)

  • Not shown on the schematic, are local decoupling capacitors and power rails for both the PIC and MAX232. On a breadboard or PCB, 0.1uF ceramic capacitors must be connected right at the Vdd to Vss pins or as close as possible. Without these, the circuit can behave erratically or not at all. Since digital devices switch signals very quickly, these capacitors provide the instantaneous current required to keep the power rails from sagging, which prevents continuous resets or brown-out conditions.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This link is also our code the c#: dropbox.com/s/jzq6k5vt9bu7rdp/C%23%20code.txt?dl=0 \$\endgroup\$ – Sylvia Espiña Apr 6 '16 at 2:50
  • \$\begingroup\$ Thanks for the help, we tried all your suggestions and we are working it now. In our simulation, we already receive the expected results. We added a hex inverter between the pin 9 of max232 and pin 26 of the pic. And between pin7 of max232 and pin 3 of the serial port. Here's our new schematic diagram: dropbox.com/s/xnpai972ollzv0o/… Here's our C# code: dropbox.com/s/jzq6k5vt9bu7rdp/C%23%20code.txt?dl=0 MikroC code: dropbox.com/s/g9rct9bxojxpp0q/mikroC%20Code.txt?dl=0 \$\endgroup\$ – Sylvia Espiña Apr 6 '16 at 3:16
  • \$\begingroup\$ To test the data we receive, we make an LED blink base on the number we send from the C# app. Then send back that number to C#. We encounter a strange problem in our MikroC code. It will skip in a certain part of the code. I already put a comment on the part where the program will skip. Here's the video of the output we got so far: youtu.be/BPr8Uj7qqKQ As you can see, the LED blink only during the input of the first number. It skip the loop part to blink the LED. Is there a problem with MikroC Code? Thank you \$\endgroup\$ – Sylvia Espiña Apr 6 '16 at 4:13
0
\$\begingroup\$

You need your C# code to send data to PIC via uart. Here is a link on how to do that. Once your PIC code receives the data from the PC via uart, it can drive the motor as you wish. Youl'l need to work on how you plan on interfacing the motor and driving it(thats another part altogether).You'l need to make sure that all the baud settings exactly match.

| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.