Hey Mark,
There's a great satisfaction in making your own device. One that suits your needs when what's available just won't cut it. And even when there is one out there, the cost can sometimes prohibit just playing around with for the sake of curiosity. Besides, how else will we learn to improve our craft if we are just consumers? Anyways...
I ran into the same problems on two different projects that I hope might help a little.
1. I needed to monitor and control a four cylinder which would have overlapping inputs at 14K RPM. Since this meant having to treat each input individually, I just used four PIC's and all programmed at the same time. I know there's a better way of doing it but I'm just learning and using Darrel's Instant Interrupt technique is just way over my head for now.
2. A simple PWM driver. Here's a small program I use to drive a 24V/24A relay bank. Just replace PAUSE with PAUSES for micro second increments instead. And PIC type of course.
Code:
'****************************************************************
'* Name : HEXFET PWM driver Rev2.BAS *
'* Date : 8/18/2008 *
'* Version : 2.0 *
'* Notes : This routine uses the PIC16F688 to monitor all of *
'" : PORTA inputs and will mirror PWM PORTC outputs by *
'" : a 5ms Power Pulse followed with a 500Hz, 50%dt *
'" : pulse train. This circuit was required to drive a *
'" : solenoid with 24V at 24A without over heating the *
'" : HEXFET device. *
'****************************************************************
@ DEVICE PIC16F688, INTRC_OSC_NOCLKOUT
@ DEVICE PIC16F688, WDT_ON
@ DEVICE PIC16F688, PROTECT_OFF
@ DEVICE PIC16F688, MCLR_OFF
define OSC 8
OSCCON = %01110000 ' Oscillator set to 8MHz, bits 6-4
CMCON0 = 7 ' Analog comparators off
TRISA = %00111111 ' Sets all PORTA pins as inputs
TRISC = %00000000 ' Sets first 4 PORTC as inputs and 2 as outputs
ADCON0 = 0 ' A/D turned OFF
ANSEL = %00000000 ' All inputs made digital I/O
PORTC = $0 ' Turn off all outputs
Pause 100 ' Let's wait 100ms before starting
' This part of the routine will output the beginning of the pulse train
' with a 5ms power pulse to be followed with the rest of the hold pulses.
loop:
IF PORTA = $0 then goto loop ' Stay here when all inputs OFF
PORTC = PORTA ' Mirror outputs (active HIGH inputs)
PAUSE 5 ' Pulse starts with 5ms Power Pulse
PORTC = $0 ' Turn OFF outputs
PAUSE 1 ' Wait 1ms then continue with pulse train
' The rest of the pulse train here is 500Hz at 50%dt as long as the input
' remains active. It also monitors for a change at the inputs so that it
' will start over to include the new input with a Power Pulse too.
While PORTA <> $0 ' Do routine as long as input active
PORTC = PORTA ' Mirror outputs (active HIGH inputs)
Pause 1 ' Keep outputs ON for 1ms
PORTC = $0 ' Turn OFF outputs
PAUSE 1 ' Keep outputs OFF for 1ms
WEND ' Input inactive, leave routine
GOTO loop ' Start from beginning
END
If you haven't already, look into International Rectifier's list of N-CH HEXFETs, found at DigiKey, such as the IRFP4321 as an example. Just don't let the big capability numbers fool you. Look at the Maximum Safe Operating Area of its data sheet. This looks like 10A at DC but nearly 40A at 1ms pulses.
Good luck...
Bookmarks