H-Bridge Microchip PIC Microcontroller PWM Motor Controller

H Bridge Microchip

One of the advantages using the Microchip PIC microcontroller Pulse Width Modulation or PWM for short is; this PWM peripheral circuit is designed to control the DC motor using the full bridge mode PWM feature. The PWM peripheral works by supplying the correct signal to the H-Bridge DC motor circuit such as speed controlling and changing the DC motor direction. Therefore on this tutorial we will learn to use this sophisticated feature offered by Microchip PIC PWM. For those with the AVR microcontroller background this is also a good chance to learn the beauty of the different between AVR and PIC microcontroller especially in the PWM peripheral features.H Bridge MicrochipFrom the PWM timing diagram above we could see that by changing the pulse width we could change the average voltage receipt by the DC motor; the wider the pulse width; the higher the average voltage receipt by the DC motor. The shorter the pulse width, the lower the average voltage receipt by the DC motor. Therefore by varying the pulse width we could vary the DC motor speed. The ratio between the pulse width and the total length of the pulse (time on plus time off) is called duty cycle, so by saying 100% duty cycle means the DC motor is in it’s full speed and 10% duty cycle the DC motor is in it’s 10% of speed. We are going to use this following H-Bridge circuit schema on our project:Schematic H Bridge Microchip

The circuit above basically is the H-Bridge transistor circuit which connected to the PIC 16F690 PWM pins through the PIC PWM output ports P1AP1BP1C and P1D. For more detail how the H-Bridge circuit works you could refer to the “Using Transistor as a Switch” posted on this blog.

The following is the list of hardware and software used in this tutorial:

1. PICJazz 16F690 learning board from ermicro (the PICJazz 16F690 schema)
2. One 5 to 6 volt DC Motor (in this project I’am using geared DC Motor)
3. Four 2K2 Ohm ¼ watt resistor for the H-Bridge circuit
4. Four BC639 transistors (or equivalent) for the H-Bridge circuit
5. Four 1N4148 diodes for the H-Bridge circuit
6. One 100nF (0.1uF) 16 volt for the H-Bridge circuit
7. JazzMate 2576-5V power board, the 5 volt switching power supply from ermicro for the H-Bridge circuit.
8. Microchip MPLAB IDE v8.0 or higher
9. HITEC PICC-Lite PICC-Lite Version 9.60PL1
10. Microchip PICKit2 Programmer

In this tutorial first we will learn how to use the basic single output PWM mode and later on we will use the full bridge PWM mode for controlling the H-Bridge motor circuit.

1. The PIC16F690 Microcontroller PWM peripheral

The heart of PIC16F690 PWM lays on the TIMER2 peripheral, this timer is used as the basic counter generator used by the PWM peripheral to generating the PWM pulse, the following is the PIC 16F690 simplify PWM peripheral diagram (for complete explanation please refer to the datasheet):

The TMR2 counter register clock is supplied by the prescale circuit which can be selected using the T2CKPS1 and T2CKPS0 bits in the T2CON register, the TMR2 register value is compared to the PR2 register which determine the TOP value of TMR2 counter register. When the TMR2 value is equal to the PR2 value, then the TMR2 counter register will be reset to 0.

At the same time the value of TMR2 counter register is compared to the CCPR1L register value (actually with the CCPR1H register value, but since the CCPR1H equal to the CCPR1L than we could just say CCPR1L), when the TMR2 value equal to the CCPR1L register value than the PWM peripheral circuit will reset the CCP1 output (logical “0“) and when the TMR2 counter register equal to the PR2 register value than it will set the CCP1 output (logical “1“). Therefore the PR2 register determine the PWM period, by changing the PR2 value we could change the PWM period and this mean changing the PWM frequency as well.

 

 

Read more: H-Bridge Microchip PIC Microcontroller PWM Motor Controller

Leave a Comment

Your email address will not be published. Required fields are marked *