1 / 19

C Examples 4

C Examples 4. Download Links. MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference. http://www.robotroom.com/HBridge.html.

Download Presentation

C Examples 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C Examples 4

  2. Download Links • MPLAB IDE • dsPIC30F4011/4012 Data Sheet • dsPIC30F Family Reference Manual • MikroC • MikroC Manual • MikroC Quick Reference

  3. http://www.robotroom.com/HBridge.html This is just an example, we prefer to use the TC4422 in the T0-220 package which has higher Current capability but is single channel. You can order free samples from microchip

  4. Components: TC4421/TC4422 • Features • High Peak Output Current: 9A • Wide Input Supply Voltage Operating Range: 4.5V to 18V • High Continuous Output Current: 2A Max • Fast Rise and Fall Times: • 30 ns with 4,700 pF Load • 180 ns with 47,000 pF Load • Short Propagation Delays: 30 ns (typ) • Low Supply Current: • With Logic ‘1’ Input: 200 µA (typ) • With Logic ‘0’ Input: 55 µA (typ) • Low Output Impedance: 1.4 (typ) • Latch-Up Protected: Will Withstand 1.5A Output Reverse Current • Input Will Withstand Negative Inputs Up To 5V • Pin-Compatible with the TC4420/TC4429 6A MOSFET Driver • Space-saving 8-Pin 6x5 DFN Package • http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en010665

  5. Components: TC4421/TC4422

  6. Components: TC4421/TC4422

  7. H Bridge ST L298 http://www.st.com/stonline/products/literature/ds/1773.pdf

  8. m=Pwm_Mc_Init(40000,1,0xFF,0x00); m=Pwm_Mc_Init(5000,1, 0b00010001,0x00);

  9. UART1 • U1MODE = 0x8400;

  10. PWM1 • unsigned int i; • unsigned int duty_50; • void main(){ • ADPCFG = 0xFFFF; // initialize AN pins as digital • PORTB = 0xAAAA; • TRISB = 0; // initialize portb as output • Delay_ms(1000); • duty_50 = Pwm_Mc_Init(5000, 0, 0x01, 0); // Pwm_Mc_Init returns 50% of the duty • Pwm_Mc_Set_Duty(i = duty_50, 1); • Pwm_Mc_Start(); • do • { • i--; • Pwm_Mc_Set_Duty(i, 1); • Delay_ms(10); • if (i == 0) • i = duty_50 * 2 - 1; // Let us not allow the overflow • PORTB = i; • } • while(1); • }//~

  11. PWM2-1 • // Pressing RE5 will change directions but speed will be different • unsigned int i, start; • char dir = 1; • unsigned int duty_50; • void main(){ • ADPCFG = 0xFFFF; // initialize AN pins as digital • PORTB = 0xAAAA; • TRISB = 0; • TRISE = 0b100000; • PORTE = 0X00; // initialize port B as output • Delay_ms(1000); • duty_50 = Pwm_Mc_Init(5000, 0, 0x01, 0); // Pwm_Mc_Init returns 50% of the duty // Pwm_Mc_Init returns 50% of the duty • Pwm_Mc_Set_Duty(i = duty_50, 1); • Pwm_Mc_Start(); • do • { • i--; • Pwm_Mc_Set_Duty(i, dir); • Delay_ms(10); • if (i == 0) • i = duty_50 * 2 - 1; // Let us not allow the overflow • PORTB = i; • if (Button(&PORTE, 5, 1, 1)) // Switch at PORTE Bit 5 • start = 1; • if (start&&Button(&PORTE, 5, 1, 0)) // Switch at PORTE Bit 5 • { • start=0; • PORTE.F1 = PORTE.F1^1; • } • } • while(1); • }

  12. PWM-2 • OVDCON = 0b0000000100000000; • PWM1L is PWM signal PWM1H is set to 0 • OVDCON = OVDCON^0b0000001100000000; • PWM1L is set to 0 PWM1H is PWM signal

  13. PWM2-2 • // Pressing RE5 will change direction at same speed • unsigned int i, start; • char dir = 1; • unsigned int duty_50; • void main(){ • ADPCFG = 0xFFFF; // initialize AN pins as digital • PORTB = 0xAAAA; • TRISB = 0; • TRISE = 0b100000; • PORTE = 0X00; // initialize portb as output • Delay_ms(1000); • OVDCON = 0b0000000100000000; • duty_50 = Pwm_Mc_Init(5000, 1, 0b00010001, 0); // Pwm_Mc_Init returns 50% of the duty • Pwm_Mc_Set_Duty(i = duty_50, 1); • Pwm_Mc_Start(); • do • { • i--; • Pwm_Mc_Set_Duty(i, dir); • Delay_ms(10); • if (i == 0) • i = duty_50 * 2 - 1; // Let us not allow the overflow • PORTB = i; • if (Button(&PORTE, 5, 1, 1)) // Switch at PORTE Bit 5 • start = 1; • if (start&&Button(&PORTE, 5, 1, 0)) // Switch at PORTE Bit 5 • { • start=0; • OVDCON = OVDCON^0b0000001100000000; • PORTE.F4 = PORTE.F4^1; • } // Toggles PORTE Bit 1 • } • while(1); • }

  14. PWM-3 • // Computer keyboard 1, 2, 2, 4 sets speed. 7, 8, 9 sets direction • int m; • int p; • signed char n; • void main () • { • IEC0=0x0200; // Enable Interrupt for UART 1 Rx • Uart1_Init(19200); • Delay_ms(100); • TRISE=0; • PORTE=0; • TRISB=0b11111101; • PORTB.F1=0; • m=Pwm_Mc_Init(40000,1,0x01,0x00); • Pwm_MC_Set_Duty(m,1); • Pwm_Mc_Start(); • while(1) • { • Delay_ms(1000); • PORTB.F1=0; • } • } • void interrupt_UART1() org 0x000026 • { • PORTB.F1=1; • n = Uart1_Read_Char()&0x0F; • Uart1_Write_Char(n); • switch (n) { • case 1: p=-2; • goto FLAG; • case 2: p=-1; • goto FLAG; • case 3: p=1; • goto FLAG; • case 4: p=2; • goto FLAG; • case 7: PORTE.F2=1; PORTE.F3=0; • goto END; • case 8: PORTE.F2=0; PORTE.F3=0; • goto END; • case 9: PORTE.F2=0; PORTE.F3=1; • default : goto END; • FLAG: p= m + ((m-1)*p)/2; • Pwm_MC_Set_Duty(p,1); • END: IFS0=0x0000; • } • }

More Related