Hello Everyone. I have a 16F818 and am using it's PWM on Rb2 to generate tones, coupling it through a FET (N channel). The drain on the FET goes to a speaker terminal. The other speaker terminal goes to B+. It works perfectly except, a couple of seconds after playing the tone, Rb2 goes HIGH causing the FET to turn on and the speaker consumes a lot of power. If you look at the START of my program you will see that I attempted to convert Rb2 as output low. It does NOT. I only included NOTE1 to shorten this post. Any suggestions? Thank you.
OSCCON = $60 '4mhz 'set int osc to 4mhz
adcon1 = 7 ' set inputs to digital
DEFINE CCP1_BIT 2 'PWM OUTPUT ON Rb2
TRISA = %11111111 'INPUT SWITCHES
TRISB = 0 'PORTB OUTPUT
PORTB = 0 'ALL LOW
@ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON
Pause 500
START:
PORTB = 0 'ALL LEDS OFF
Output PORTB.2 'ATTEMPT TO REDEFINE RB2 AS OUTPUT LOW DOESN'T WORK
Low PORTB.2
NAP 2
IF PORTA.1 = 1 Then NOTE1
IF PORTA.0 = 1 Then NOTE2
IF PORTA.7 = 1 Then NOTE3
IF PORTA.6 = 1 Then NOTE4
IF PORTA.2 = 1 Then NOTE5
IF PORTA.3 = 1 Then NOTE6
IF PORTA.4 = 1 Then NOTE7
GoTo START
NOTE1:
HPwm 1,127,522 "PLAY SOUND
High PORTB.7 "ON LED
IF PORTA.1 = 1 Then NOTE1 'IF SWITCH ON KEEP PLAYING
HPwm 1,127,0 'TURN OFF SOUND
GoTo START
Bookmarks