-1
\$\begingroup\$

I have made a line follower and the issue I'm facing right now is its speed adjustment. The motors run too fast and make my robot go off track. Luckily my motor driver supports speed control through PWM signals, so I was just wondering if it's possible to generate 4 separate PWM signals using a single PIC16F84A IC.

Concerning my project, it is centered around the PIC16F84A microcontroller and a miniature chinese clone of L298A. For controlling the motor speed, two in my case, the motor driver requires 2 signals for each motor, therefore 4 in total. Hence I somehow need to be able to generate 4 PWM signals from my PIC16F84A to implement speed control for my motors. Is it possible to do so with my microcontroller?

It would be great if the provided solution were more code-oriented or just a minimal circuit.

\$\endgroup\$

closed as unclear what you're asking by brhans, RoyC, Michel Keijzers, Finbarr, Dmitry Grigoryev Mar 13 '18 at 10:40

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ Have you ever considered reading the datasheet of the controller? \$\endgroup\$ – ercegovac Mar 11 '18 at 11:01
  • \$\begingroup\$ I have read the datasheet of the controller and it has the info I need for speed control, but my question aims at outputting pwm signals via PIC16F84A. \$\endgroup\$ – Utkarsh Verma Mar 11 '18 at 11:03
  • 2
    \$\begingroup\$ @UtkarshVerma you know, ercegovac has a point there: the datasheet clearly says how many PWM units you have and how they can be connected to outputs; so what's your exact question? I honestly think you've got one, but "4 PWMs" isn't really an exact requirement (independent? linked? one inverting the other?) \$\endgroup\$ – Marcus Müller Mar 11 '18 at 11:32
  • \$\begingroup\$ We are talking here about Microchip, not some obscure, no-name controller without proper documentation. If you did not find it on the internet, that can only mean that you did not even bother to search. \$\endgroup\$ – ercegovac Mar 11 '18 at 11:59
  • \$\begingroup\$ @MarcusMüller I require independent linked 4 PWMs. I thought ercegovac was referring to the motor controller. My question is "Whether PIC16F84A can generate 4 PWM outputs simultaneously for motor controlling". I was unable to find PWM section in the datasheet. Could you please help me with it. \$\endgroup\$ – Utkarsh Verma Mar 11 '18 at 12:31
2
\$\begingroup\$

As you discovered from reading the datasheet, the PIC16F84A does not have any PWM hardware. You can still generate PWM, but you will have to do it by 'bit-banging' the I/O pins in software.

Maximum PWM frequency, resolution, and accuracy will be limited by code execution time, and the more PWM outputs you produce the slower it will get (for two motors you should only need two PWM outputs, with the other outputs held high or low). For best results the code would be written in assembler, with careful attention paid to the execution time of each instruction.

If the MCU needs to do other stuff (eg. reading photo-sensors) at the same time then it gets tricky - but still possible provided the other stuff can be done between PWM transitions. One solution is to use Timer0 to generate the PWM timing, with PWM pin updates done in the timer ISR. This will introduce some jitter and reduce the maximum PWM frequency, but allows other code to run in the background without worrying about upsetting the PWM timing.

If the MCU must also run other code with critical timing requirements (eg. software UART) then it gets even more tricky - perhaps even impossible. In that case you might want to consider changing to a more modern PIC with hardware PWMs.

\$\endgroup\$
  • \$\begingroup\$ I had successfully generated soft PWM using my IC without any changes to the circuit(only had to add code). Here's the link to my code: PWM generation. \$\endgroup\$ – Utkarsh Verma Jan 16 at 7:49

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