Presentation is loading. Please wait.

Presentation is loading. Please wait.

C Examples 4.

Similar presentations


Presentation on theme: "C Examples 4."— 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

4 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

5 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

6 Components: TC4421/TC4422

7 Components: TC4421/TC4422

8 H Bridge ST L298

9 m=Pwm_Mc_Init(40000,1,0xFF,0x00);
m=Pwm_Mc_Init(5000,1, 0b ,0x00);

10 UART1 U1MODE = 0x8400;

11 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); }//~

12 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);

13 PWM-2 OVDCON = 0b ; PWM1L is PWM signal PWM1H is set to 0 OVDCON = OVDCON^0b ; PWM1L is set to 0 PWM1H is PWM signal

14 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 = 0b ; duty_50 = Pwm_Mc_Init(5000, 1, 0b , 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^0b ; PORTE.F4 = PORTE.F4^1; } // Toggles PORTE Bit 1 } while(1);

15

16

17

18

19 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=0b ; 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); } 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; case 3: p=1; case 4: p=2; case 7: PORTE.F2=1; PORTE.F3=0; goto END; case 8: PORTE.F2=0; PORTE.F3=0; 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;


Download ppt "C Examples 4."

Similar presentations


Ads by Google