PDA

View Full Version : help hpwm in pic 16F88



selim
- 25th March 2010, 10:32
I c'ant switching hpwm between RB.0 AND RB.3 please can any one help me

pic is 16f88:


INCLUDE "modedefs.bas" ' Include serial modes


@ DEVICE MCLR_ON, HS_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF ,CCPMX_ON

define OSC 20


OPTION_REG = $7f ' Enable PORTB pullups= %01111111
ANSEL = %10000001 ' 'Set PORTA.0 analog rest digital
ADCON1 = %10000000 'Right justify result
ADvalue VAR WORD
DutyCycle VAR WORD $22
Frequency VAR WORD
TRISA = %10000001
TRISB = %10000000
PORTB = 0


'LOW PORTB.0
'LOW PORTB.3 ; Set CCP1 pin to output low

Frequency = 50
DutyCycle = 50
PAUSE 500
loop:



if portb.7 = 0 then
goto left
else
goto right
endif
'=============================

left:

if portb.7 = 1 then right

LOW PORTB.3

@ DEVICE pic16F88, HS_OSC , CCPMX_ON
PAUSE 100 ' start-up delay
TRISB=0
DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 3


HPWM 1, DutyCycle, Frequency
GOTO left

'=============================
right:
if portb.7 = 0 then left

LOW PORTB.0
@ DEVICE pic16F88, HS_OSC , CCPMX_OFF

PAUSE 100 ' start-up delay
TRISB=0
DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 1

HPWM 1, DutyCycle, Frequency

GOTO right
'============================

goto loop


END

aratti
- 25th March 2010, 10:50
Bear in mind that the minimum PWM frequency you can achieve with an osc @ 20 MHz is 1221 Hz. (see page 74 of PBP manual)

In your code the PWM frequency is set to 50 Hz.

Al.

selim
- 25th March 2010, 11:09
I change to 4 mhz AND The Frequency TO 100 ,but the hpwm still on rb.0


INCLUDE "modedefs.bas" ' Include serial modes


@ DEVICE MCLR_ON, XT_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF ,CCPMX_ON

define OSC 4

OPTION_REG = $7f ' Enable PORTB pullups= %01111111
ANSEL = %10000001 ' 'Set PORTA.0 analog rest digital
ADCON1 = %10000000 'Right justify result
ADvalue VAR WORD
DutyCycle VAR WORD $22
Frequency VAR WORD
TRISA = %10000001
TRISB = %10000000
PORTB = 0


'LOW PORTB.0
'LOW PORTB.3 ; Set CCP1 pin to output low

Frequency = 100
DutyCycle = 50
PAUSE 500
loop:



if portb.7 = 0 then
goto left
else
goto right
endif
'=============================

left:

if portb.7 = 1 then right

LOW PORTB.3

@ DEVICE pic16F88, XT_OSC , CCPMX_ON
PAUSE 100 ' start-up delay
TRISB=0
DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 3


HPWM 1, DutyCycle, Frequency
GOTO left

'=============================
right:
if portb.7 = 0 then left

LOW PORTB.0
@ DEVICE pic16F88, XT_OSC , CCPMX_OFF

PAUSE 100 ' start-up delay
TRISB=0
DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 1

HPWM 1, DutyCycle, Frequency

GOTO right
'============================

goto loop


END

mtripoli
- 25th March 2010, 14:08
You just can't not read the datasheets. You will get nowhere.

In the data sheet: http://ww1.microchip.com/downloads/en/DeviceDoc/30487c.pdf

It says:"The CCP module’s input/output pin (CCP1) can beconfigured as RB0 or RB3. This selection is set in bit 12 (CCPMX) of the Configuration Word".

So we read the whole document so that we have a small idea where to find this register, or, we do a search in the document for this register.

On page 130 we find register 15-1. Here we find bit 12 - the CCPMX bit.

No escaping it - for real - truths - RTFDS.

You were also told by Aratti about minimum frequencies: You still set it for what you wanted; not what it can do. In the table regarding 14-bit core it says @4MHz the minimum frequency is 245Hz. 245 is more than 100.

RTFM...

Bruce
- 25th March 2010, 14:09
You can't change config settings with @ DEVICE at runtime.

ScaleRobotics
- 25th March 2010, 14:19
I change to 4 mhz AND The Frequency TO 100 ,but the hpwm still on rb.0

4 mhz doesn't do 100 hertz either, but Arrati's page reference shows you that. You will need to run the chip at 0.5mhz for 50 hertz, or you can run at 1 mhz for 100 hertz.

mtripoli
- 25th March 2010, 14:49
You can't change config settings with @ DEVICE at runtime.

I've never had to do it so it didn't occur to me that you couldn't change this during runtime; I could think of situations when you might want to switch between running PWM to different devices at run time. I had to go back and look:

"15.1 Configuration Bits
The configuration bits can be programmed (read as ‘0’), or left unprogrammed (read as ‘1’), to select various device configurations. These bits are mapped
in program memory locations 2007h and 2008h. The user will note that address 2007h is beyond the user program memory space which can be accessed only during programming."

I don't have an application for this, but I would have thought you could(switch between RB.0 and RB.3) at run-time. Hmmm... learn something new...

selim
- 25th March 2010, 16:16
The Frequency it not my probl ok for this point ,but my probl is the switching betwen rb.0 and rb.3

thank you for help

mackrackit
- 25th March 2010, 17:51
Being you want to change pins why not use the software PWM.