PDA

View Full Version : HPWM on 16F88



Mugelpower
- 21st April 2011, 21:05
Hi folks, long time no see!

Maybe someone is in the mood to help.
Thanks in Advance.
try to make an engine water pump driver and Iīm frustrated about my inability to get the HPWM working.
the °C reading works and the speed change works too but I canīt
get the RB0 to make it right....I know its in the config thingy..


Heres my code:
'************************************************* ***************
'* Name : Thermometer-LCD1 + HPWM (only for range 70-90°C) *
'* Test with 20-23 °C RB0 = HPWM out *
'* Author : M.David *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 31.03.2011 *
'* Version : 1.0 for NTC Probe AB 94 098 000.D1 M12 x 1.5 *
'* Notes : 16F88 LCD 1X16 connected as usual *
'* : Portb.7 analog IN 0-2V *
'************************************************* ***************


Include "modedefs.bas"


Define OSC 4
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 100 ' Set sampling time in uSec

define CCP1_REG PORTB
DEFINE CCP1_bit 0



CMCON = 7 ' Disable analog comparator
ANSEL = %01000000 ' set AN6 (RB7) as analog, others to digital
ADCON1.7 = 1 ' Right justified results... duh... really needed in 8 bits???

Uhilf var word

Uin VAR Word
Fac var Word
Multi Var Word
Uresult var Word
Temp Var word
speed var word
Speed = 0

pause 100

LCDOUT $FE,1

PAUSE 1
LCDOUT $FE,1,"Pumpensteuerung"
pause 2000
LCDOUT $FE,$C0,"Wassertemperatur"
pause 3000


main:
HPWM 1,speed,1000

ADCIN 6, Uin ' Read channel 6 (RB7)
pause 10
Uhilf = Uin * 7
Uresult = Uhilf / 48
Temp = Uresult / 100

pause 10
if Uresult = 21 then
speed = 0
endif

if Uresult = 22 then
speed = 127
endif

if Uresult = 23 then
speed = 255
endif

LCDOUT $FE,1,"Temp=",DEC2 Uresult
pause 2000
LCDOUT $FE,1,"Speed",DEC3 speed
pause 2000


goto main



END ' End of program

HenrikOlsson
- 22nd April 2011, 07:59
Hi,
I think that CCP1 defaults to RB3 and that you, as you say, has to reconfig it to have it on RB0 instead.

Open 16F88.inc file located in the PBP folder and change the CONFIG line to:

__config _CONFIG1, _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF & _CCP1_RB0

Note that there are two lines, one (the one I showed above) if you use MPASM and another if you use PM and they differ slightly in the format used but you'll get the idea.

Just remember that once you've edited the file it stays that way and if you forget about it you'll scratch your head the next time you're using the F88 and the CCP module doesn't work on RB3.... ;-)

/Henrik.

Mugelpower
- 22nd April 2011, 12:54
Hi Henrik,

tried your suggestion, didnīt work.
thought it was already in the defines, but tried that too.

Any more ideas?

thanks

HenrikOlsson
- 22nd April 2011, 14:56
Hi,
Now I'm a bit confused, it seems like it IS defaulting to PortB.0 and not PortB.3 as I said earlier, so you shouldn't have to change anything. Either way I've tried it here and it works.... I can switch the PWM output between RB0 and RB3 by changing the CONFIG like shown in the previous message.

However, I don't see you setting the TRIS register anywhere and I don't know if HPWM does that for you, always best to do that your self.

/Henrik.

Darrel Taylor
- 22nd April 2011, 18:18
If you are using MPASM for the assembler, defines need to be all uppercase.


define CCP1_REG PORTB
DEFINE CCP1_bit 0

Mugelpower
- 22nd April 2011, 20:51
Hello Darrel,

nice you took a look at my childish problem.

The config files you mentioned were in the upper part of the program
do I have to put them in the .inc file? Iīm confused.

And i was so frustrated I wrote code that used Portb.0 as switch
inside my simple program because I feared the chip was blown but it works.

it is just: I canīt get portb.0 as HPWM output AND the normal LCDout application at once. The LCD is the reason I canīt switch the port. got the boards already.

sream, howl, and so on

flotulopex
- 25th April 2011, 19:48
Try to set your fuse like this:

@ DEVICE PIC16F88, CCPMX_OFFwhere:
0 = "ON" CCP1 on RB3
1 = "OFF" CCP1 on RB0



You also need to set a register:
CCP1CON = %00001100 'Select PWM ModeHTH

flotulopex
- 26th April 2011, 10:40
Instead of using HPWM, try this:
PWM PORTB.0,speed,1000You won't need to declare/define T2CON, CCP1CON, PR2 and CCPR1L.

PS: I'm using MCS