PDA

View Full Version : Pic12f615 pwm output w/ analog a/d control input



Nhilar
- 6th January 2014, 23:16
I am a total PIC newbie, so far my experience is limited to modifying a few example .asm files. But I have a very real practical application. I need to control a pwm (4-wire) fan away from the standard motherboard headers. So I know the PIC12F615 is on the lower end of pics, but it is what I have on hand. (I have some PIC12F683 on order). So here is my idea:

put voltage into the A/d converter 5-10k pot controlling 0-5V scaling the 0-255 pwm.

output the pwm signal directly to the control line (pulled up with a 1k resistor)

Is this possible with a 615, I would think it would be simple code with low memory requirements - could someone hold my hand with this and walk me through the code - I know its newb, but it would help a lot..thanks!

-Nhilar

peterdeco1
- 7th January 2014, 18:05
Hi Nhilar. I'm not familiar with the 12F615 but we use this simple program to control the speed of a small motor. The Hpwm output goes to the gate of an N channel FET. The drain feeds the motor. Other side of motor to B+. Maybe this will help you to get it going.

'COMPILED FOR 12F683

CMCON0 = 7 'comparators off
ANSEL = 0 'all inputs digital. adcin command will convert it to analog.
DEFINE OSCCON_1K 1 ' Set OSCCON for 1K device
@ DEVICE MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON
TRISIO = %00010001 'GPIO.0 GPIO.4 (ANA3) INPUTS
GPIO = 0 'ALL OUTPUTS LOW
SPEEDPOT VAR BYTE

START:
CCP1CON = 0 'TURN OFF PWM
NAP 0 'REDUCE BATTERY DRAIN
IF GPIO.0 = 1 Then VIBRATE 'has pulldown 47K resistor
GoTo START

VIBRATE:
ADCIN 3,SPEEDPOT 'USING 1M POT ACROSS SUPPLY
HPwm 1,SPEEDPOT,15000 'THIS MOTOR WORKED BEST @ 15KHZ
IF GPIO.0 = 1 Then VIBRATE
GoTo START

peterdeco1
- 9th January 2014, 17:59
Actually, the DEFINE OSCCON_1K 1 ' Set OSCCON for 1K device, should be DEFINE OSCCON_2K 1 ' Set OSCCON for 2K device. Compiles and works properly either way though.