PDA

View Full Version : pwm no workee



queenidog
- 4th June 2013, 00:47
I had pwm working fine with my LabX1 and PIC 16F887. In my circuit, the 16F88 does not work. I have a scope on the output and I see nothing. Here's relevant code: (I took out some code to do with other operations to make it easier to read). By the time the program hits the HPWM command, I should see wigglies on the scope. I see nothing. I started ONLY with that command (and TRISB) and added the other config fuses and defines later in attempt to make it work. BTW, the other part of the program (timer, interrupts, A/D for voltage measurement) WORKS, so I know the MCU and oscillator and stuff is okay. I want to use RB3 (CCP1). I've reduced frequency to 8000 Hz for testing.
Any ideas?

#config
__config _CONFIG1, _LVP_OFF & _CP_OFF &_MCLR_ON & _PWRTE_OFF & _WDT_OFF & _CCP1_RB3 & _INTRC_IO & _CCPMX_RB3

#endconfig
duty var byte
freq var word

'Initialize
OSCCON= %01110000 'Internal oscillator, 8 MHz
TRISA= %11111111 'Set PORTA <D7-D0> to input
TrisB= %00000000 'set portb <D7-D0> to output
ANSEL= %00000011 'set portA analog on PortA <0-1>
ADCON0= %01001111 'enable ADC channel 0 and 1
ADCON1= %10000000 'right justify result
temp=0 'variable for Button command

Pause 100 'Wait for LCD to start up
define ccp1_reg PortB
define ccp1_bit 1
duty=127 '50% duty cycle
freq=8000 'test frequency
hpwm 1,duty,freq 'Start PWM 38000 khz signal from RB3 of 16F88

Demon
- 4th June 2013, 02:45
Lower case defines?

Robert

queenidog
- 4th June 2013, 14:29
My PBP3.0 client (MicroCode Studio) automatically turns the defines into lower case.

In any case (no pun intended), I have a number of other defines used for A/D conversion and LCD prep that work fine.

Since I posted the code above, I changed "duty" and "Freq" from Var to Con (constant), not that it made any difference.

I'm pulling the chip and will see if it's a hardware problem. I could also check if RB0 works instead of RB3, because I cannot see where there's a problem in software.

queenidog
- 4th June 2013, 14:41
Believe it or not, I replaced the chip and now the pwm is working. (see attached screenshot of scope trace). Yet, all the other sections were working fine, A/D conversion, LCD display, interrupts and timer.
7001

Now, I will go back and make it not work to see what codes I don't need and/or do need.

I was going to say that I "wasted" a lot of time trying to make the software work, but in a way I didn't waste anything because I was forced to read the data sheet with a little more care, and investigate other programs for solutions.