View previous topic :: View next topic |
Author |
Message |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
16F1936 PWM CCP2 Half bridge P2B not working |
Posted: Sat Apr 06, 2013 3:13 pm |
|
|
Hy guys can tell me if someone have this problem?
I try to put output "RC0" in high level and is OK.
When I setup CCP2 in half bridge "RC0" or P2B is not working, when P2A is okay.
P1A, P1B, P2A, I have wave on the scope.
P2B, output is 0V on scope.
I put my code to help understand where is the problem:
in C program:
Code: |
#include <16F1936_prog_v3.h>
#byte APFCON = 0x00
void main()
{
setup_adc(ADC_CLOCK_DIV_16);
setup_vref(VREF_ADC_4v096);
setup_timer_2(T2_DIV_BY_1,225,1);
setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L|CCP_TIMER2);
setup_ccp2(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L|CCP_TIMER2);
setup_comparator(NC_NC_NC_NC);
setup_lcd(LCD_DISABLED);
setup_oscillator(OSC_16MHZ|OSC_TIMER1|OSC_PLL_OFF,0);
port_E_pullups(0x08);
for(;;){
set_pwm1_duty(75);
set_pwm2_duty(151);
}
|
and in H program:
Code: |
#include <16F1936.h>
#device *=16
#device adc=10
#use delay(int=16M)
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES PROTECT //Code protected from reads
#FUSES CPD //Data EEPROM Code Protected
#FUSES WRT //Program Memory Write Protected
#FUSES PLL_SW //4X HW PLL disabled, 4X PLL enabled/disabled in software
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOMCLR //No MCLR
#FUSES NOPUT //No Power Up Timer
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,enable=PIN_A2)
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Apr 06, 2013 4:25 pm |
|
|
Quote: | setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L|CCP_TIMER2);
setup_ccp2(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L|CCP_TIMER2);
|
You are mixing together the constants for ordinary PWM and for
enhanced mode (Half Bridge). That is not correct.
Quote: | #byte APFCON = 0x00 |
That's not how the #byte statement is used. Look it up in the CCS manual. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Apr 06, 2013 4:28 pm |
|
|
also
you should add 'errors' to the use RS232(...options...).while you don't need it now....in future when you use serial communications, it keeps the hardware UART from 'locking up' due to errors.
hth
jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Mon Apr 08, 2013 12:03 pm |
|
|
Sorry for my late reply. I will back with update later.
Best regards. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Mon Apr 08, 2013 1:56 pm |
|
|
PCM programmer
Code: | setup_ccp2(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L|CCP_TIMER2); |
I let enable only this line CCP2 and problem persists.
So problem isn't from here.
temtronic
I don't know how to use hardware Uart.
so I make disabled this line.
I try to use APFCON like:
in the main.c, after void main
Code: | SET_APFCONS (0b00000000); |
and in header file I put:
Code: | #define SET_APFCONS(value) {#ASM \
MOVLW value \
APFCON \
#ENDASM} |
and error is:"Expecting an opcode mnemonic APFCON"
Why? someone can make life easier?
Thanks. |
|
|
notbad
Joined: 10 Jan 2013 Posts: 68
|
|
Posted: Mon Apr 08, 2013 9:22 pm |
|
|
I had a similar P2B problem with another chip. Try output_drive(pin_C0); after setup_ccp2. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Mon Apr 08, 2013 11:28 pm |
|
|
notbad
I will try this and I will come back with feedback.
Thank you. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Apr 09, 2013 12:20 am |
|
|
Critical thing though is that he is ignoring the glaring error pointed out by PCM programmer. Even if the drive mode is set right, it is never going to work right. Currently it is like a person trying to make a car go by pushing both pedals (automatic) at once....
Best Wishes |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Tue Apr 09, 2013 1:06 pm |
|
|
notbad
Feedback:
Your solution is good and works very well.
Thank you very much notbad.
Dear all how can I set this register APFCON?
I want to learn for the future.
Best regards. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Apr 09, 2013 2:37 pm |
|
|
The easiest way is:
Code: |
#byte APFCON=getenv("SFR:APFCON")
//Then just write it when you want
APFCON=0b00000000;
//Choosing the value as needed
|
|
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Wed Apr 10, 2013 12:24 pm |
|
|
Ttelmah
I'm sorry to respond, but does not work.
I'm begin to think it is a bug.
I think changing the subject with the word bug.
If you have any solution I'm happy to test your solution.
Thank you. |
|
|
|