PDA

View Full Version : PWM=on...DEBUG=off



ruijc
- 25th April 2010, 22:11
Hi guys,

i'm building a project to test piezos and check what is the best working frequency.

I'm using a 12F615 and the code is very simple:
send frequency out using HPWM and when the sound from the piezo sounds about right and pressing a switch the frequency value will output via RS232.

The problem i'm having is that when activating HPWM the debug function does not work.
If i remove the bold definitions ( see below ) the debug works.

[code]
'************************************************* ***************

DEFINE OSC 8
OSCTUNE=%0000000

'************************************************* *****************

@ DEVICE PIC12F615, INTRC_OSC_NOCLKOUT
@ DEVICE PIC12F615, WDT_OFF
@ DEVICE PIC12F615, PWRT_OFF
@ DEVICE PIC12F615, MCLR_OFF
@ DEVICE PIC12F615, BOD_OFF
@ DEVICE PIC12F615, PROTECT_ON
@ DEVICE PIC12F615, IOSCFS_8MHZ

'************************************************* *****************ADCON0=0
ANSEL=0
WPU=0 ' Disable pull-ups
CMCON0.7=0 ' Turn off comparator
INTCON=0 ' Interrupt control register
OPTION_REG.7=1 ' Disable Pull-Ups
OPTION_REG.3=1 ' Disable Pull-Ups

CCP1CON=%10001100 ' PWM mode; P1A active-high; P1B active-high
PWM1CON=%10000001 ' min dead-band time
T2CON.2=0
T1CON.3=0

VRCON=0 ' Internal Vref disabled

TRISIO=%011001
GPIO=0

'************************************************* *****************

'PINS

sw1 var GPIO.0 'stop switch
out var GPIO.1 'OUT PIN for debug
piezo var GPIO.2 'output pwm
in var GPIO.3 'Input
sw2 var GPIO.4 'spare switch
Led var GPIO.5 'Led

'************************************************* *****************

PI1 var word
na var word
duty VAR WORD
freq var word

'************************************************* *****************

Include "modedefs.bas" ' Include serial modes

DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 1
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 1

'************************************************* *****************
'PWM

DEFINE CCP1_REG GPIO 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit

'************************************************* ***************
INIT:
high out
debug $0D, $0A
PAUSE 50
debug "Starting...",13,10
debug 13,10
low led
Duty = 127 '50% duty

'************************************************* ***************
debug "started frequency loop",13,10

start:
debug 13,10
debug 13,10
low led
for freq=2000 to 4000 step 10
HPWM 1,duty,freq
debug dec freq,13,10
debug 13,10
pause 50
if sw1=1 then
while sw1=1
wend
goto play
endif
next
high led
pause 300
goto start

play:
debug "freq=",dec freq,13,10
end
[code\]

Any help would be appreciated

ruijc
- 27th April 2010, 08:35
Hi there,

anyone has any idea that can help me ?

Thanks

Jerson
- 27th April 2010, 11:30
Just a suggestion. Can you not send the frequency after SW1 is hit? Or does that not work as well?

ruijc
- 28th April 2010, 17:39
Greetings Jerson,

thank you for your reply

One question:

When needed to stop the HPWM we just place a zero duty value but internally the module is still active and on standby.

Is it possible to really shutdown the HPWM module, like for example placing the "CCP1CON=0" in the code's last loop ?

Thanks

Jerson
- 29th April 2010, 02:18
Greetings ruijc

Setting HPWM value to 0 should be sufficient to keep the output off, but, it should be ok to put it off as you suggested.