PDA

View Full Version : PIC16F616 HWPM Problem



Tobias
- 3rd April 2009, 22:31
I am using a PIC16F616. I can't get the HWPM to work. I threw in the Toggle command for a channel to check if the processor is operating. PortC.5 is going hi/lo.
Any ideas?



'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 4/3/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
INCLUDE "modedefs.bas"

OPTION_REG.7 = 0 'Pull Ups enabled

TRISA.2=1
TRISC.0 = 1
TRISC.1 = 0
TRISC.2 = 0
TRISC.3 = 1
TRISC.4 = 0
TRISC.5 = 0
'0 Digital 1 Analogue
ANSEL.7=0
ANSEL.6=0
ANSEL.5=0
ANSEL.4=1
ANSEL.3=0
ANSEL.2=0
ANSEL.1=0
ANSEL.0=0

ADCON0.7=1 'Right Justified
ADCON0.6=0 ''Voltage reference is VDD
ADCON0.5=0 'Turns on AN4 to analogue
ADCON0.4=1
ADCON0.3=0
ADCON0.2=0


'HPWM DEFINES
DEFINE CCP1_REG PORTC
DEFINE CCP1_BIT 1 'Hpwm 2 --> portc.1
DEFINE CCP2_REG PORTC
DEFINE CCP2_BIT 2 'Hpwm 1--> portc.2

Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uSec

Switch var PortA.2 '
FF var PortC.0
FrontOut var PortC.1
RearOut var PortC.2
GS var PortC.3
Watch var PortC.5

HPWM 1,127,400
HPWM 2,127,400

Loop:
If Switch = 1 then
Toggle Watch
pause 100
endif
goto Loop

Darrel Taylor
- 3rd April 2009, 23:05
Are you sure it's a PIC16F616?

The 616 only has 1 CCP module.
It's on RC5 and can't be changed with a DEFINE.
<br>

Tobias
- 4th April 2009, 04:18
Come on isn't that just a minor technical difficulty??? I thought I was doing good reading the spec sheet. Table 2 has RC5 as CCP1, I thought that I could get away using RC2,3, and 4 because there was P1B, P1C, and P1D. What would I use RC2, 3, and 4 as if they are labeled as P1B, P1C, and P1D? Does that mean I can use them as HPWM's yet they will share the same pulse width as the CCP1? For my project I need two different PWM's so I would need a chip that has two CCP's?
Thanks
Toby

Darrel Taylor
- 4th April 2009, 09:20
Come on isn't that just a minor technical difficulty???
Insignificant, in the scope of world events. :)<hr>
The CCP module on that chip is an ECCP.
The P1A thru P1D outputs can be used to run "half-bridge" or "full-bridge" motor drivers and a few other tricky things. All the outputs would have the same PWM freq/duty, but uses complimentary signals with programmable delays when switching states.

But the way the HPWM command uses the CCP module, it's a single output on the CCP pin.

You can only get 1 PWM signal out of it.


For my project I need two different PWM's so I would need a chip that has two CCP's?
Depends on what you need. There are alternatives to HPWM.
<br>