Microchip Hitech C Compiler
H Bridge Microchip PIC Microcontroller PWM Motor Controller. 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. A beginners guide to PIC interrupts and their handling in C. We explain what are interrupt, how they are setup and used in PIC MCUs. A simple program is also provided. Introduction This little project will demonstrate how you can use your old NEC IR protocol based TV,DVD or VCR remote control to control you home. These instructions will use XC8 compiler and MPLAB X IDE by Microchip. This step will explain how to get these tools and ensure they have been installed correctly. MPLAB XC Compilers are general solutions for all PIC Microcontrollers for any Project. Blinking an LED with PIC Microcontroller using MPLAB XC8 Compiler. Microchip provides a free USBBootloader in their USB framework which is part of Microchips Applications Library. You can get it here httpwww. No more missed important software updates UpdateStar 11 lets you stay up to date and secure with the software on your computer. Freeware, software y firmware de libre copia y distribucin, guas, manuales y documentacin disponibles. HITECH C PRO for the PIC101216 MCU Family Lite mode 2012327HITECH C Compiler for PIC101216 MCUs 9. Multifunction RGB LED controller using low cost PIC12F675 microcontroller. Blog Entry HBridge Microchip PIC Microcontroller PWM Motor Controller January 26, 2009 by rwb, under Microcontroller. One of the advantages using the Microchip PIC. VNMzUN_CUA/TClCkKnwrDI/AAAAAAAAm-E/DZY84204JXE/s1600/BuildSuccess.png' alt='Microchip Hitech C Compiler' title='Microchip Hitech C Compiler' />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. PWM is used in many industrial mostly for controlling the motor speed. How this PWM signal could change the DC motor speed is showed on this following PWM signal timing diagram From 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 1. DC motor is in its full speed and 1. Microchip Hitech C Compiler' title='Microchip Hitech C Compiler' />DC motor is in its 1. We are going to use this following H Bridge circuit schema on our project The circuit above basically is the H Bridge transistor circuit which connected to the PIC 1. F6. 90 PWM pins through the PIC PWM output ports P1. A, P1. B, P1. C and P1. D. 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 1. 6F6. 90 learning board from ermicro the PICJazz 1. F6. 90 schema2. One 5 to 6 volt DC Motor in this project Iam using geared DC Motor3. Four 2. K2 Ohm watt resistor for the H Bridge circuit. Four BC6. 39 transistors or equivalent for the H Bridge circuit. Four 1. N4. 14. 8 diodes for the H Bridge circuit. One 1. 00n. F 0. F 1. H Bridge circuit. Jazz. Mate 2. 57. V power board, the 5 volt switching power supply from ermicro for the H Bridge circuit. Microchip MPLAB IDE v. HITEC PICC Lite PICC Lite Version 9. PL1. 10. Microchip PICKit. 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. The PIC1. 6F6. 90 Microcontroller PWM peripheral. The heart of PIC1. F6. 90 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 1. F6. 90 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 T2. CKPS1 and T2. CKPS0 bits in the T2. CON 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 CCPR1. L register value actually with the CCPR1. H register value, but since the CCPR1. H equal to the CCPR1. L than we could just say CCPR1. L, when the TMR2 value equal to the CCPR1. L 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. The PWM period could be calculated using this following formula PWM period PR2 1 x 4 x Tosc x TMR2 prescale value second. Where Tosc is the system clock period in second. City Lounge 1.1 on this page. PWM frequency 1 PWM Period Hz. While the PWM pulse width is depend on the CCPR1. L register value, therefore by varying the CCPR1. L register value, we could change the PWM pulse width. The PWM width can be calculated using this following formula PWM width CCPR1. L CCP1. CONlt 5 4 x Tosc x TMR2 prescale value second. This following table shows the PWM frequency and resolution with the 8 MHz clock The PWM output behavior is controlled by the CCP1. CON, PWM1. CON and PSTRCON registers, we will talk about these three registers shortly, but the important think to remember that all the TRIS three states inputoutput register for each of the PWM output ports P1. A, P1. B, P1. C and P1. D should be set to the output mode. Single Output Mode PWMWith single output PWM mode we could sent the same PWM signal to each of available PWM pins i. P1. A, P1. B, P1. C and P1. D or to all of them at the same time. Our first C program example will show you how this single output PWM mode works. Ok lets pasting this following code into your Microchip MPLAB IDE. File Name pwm. Version 1. Description Pulse Width Modulation PWM. Single Output, Steering Mode. Authors RWB. Targets PICJazz 1. F6. 90 Board. Compiler HITECT PICC Lite Version 9. PL1. IDE Microchip MPLAB IDE v. Programmer PICKit. Last Updated 0. Jan 2. PIC Configuration Bit. INTIO Using Internal RC No Clock. WDTDIS Wacthdog Timer Disable. PWRTEN Power Up Timer Enable. MCLREN Master Clear Enable. UNPROTECT Code Un Protect. UNPROTECT Data EEPROM Read Un Protect. BORDIS Borwn Out Detect Disable. IESODIS Internal External Switch Over Mode Disable. FCMDIS Monitor Clock Fail Safe Disable. CONFIGINTIO WDTDIS PWRTEN MCLREN UNPROTECT. UNPROTECT BORDIS IESODIS FCMDIS Using Internal Clock of 8 MHz. FOSC 8. 00. 00. 00. L Delay Function. FOSC1. while us 0 continue void delaymsunsigned int ms. OSCCON0x. 70 Select 8 MHz internal clock TRISC 0x. Set All on PORTC as Output. ANSEL 0x. 00 Set PORT AN0 to AN7 digital IO. ANSELH 0x. 00 Set PORT AN8 to AN1. Digital IO. PORTC 0x. Turn Off all PORTC Init PWM for Single Output. CCP1. CON0b. 00. Single PWM mode P1. A, P1. C active high P1. B, P1. D active high. CCPR1. L0 Start with zero Duty Cycle T2. CON0b. 00. 00. 01. Postscale 1 1, Timer. On, Prescale 1 4. PR20x. 65 Frequency 4. Hz. TMR20 Start with zero Counter. PSTRCON0b. 00. 00. Enable Pulse Steering on P1. C RC3. state0 Start with state 1 for. CCPR1. Lipwm. delayms5 Delay 5 millisecond. CCPR1. L ipwm. Delay 5 millisecond. Delay 1. 00 millisecond if state 0. PSTRCON0b. 00. 00. Enable Pulse Steering on P1. D RC2. else if state 1. PSTRCON0b. 00. 00. Enable Pulse Steering on P1. C and P1. D RC3 and RC2. PSTRCON0b. 00. 00. Enable Pulse Steering on P1. C RC3. EOF pwm. This C program basically will use only P1. C and P1. D PWM output ports, since these ports are attached to the LEDs on the PICJazz 1.