View previous topic :: View next topic |
Author |
Message |
chrismdube
Joined: 30 Dec 2011 Posts: 20 Location: UK
|
Full bridge code |
Posted: Sun Jan 22, 2012 3:10 pm |
|
|
Can someone please tell me if I should expect full bridge operation just by running this code. Or am I supposed to add more code like forward and reverse?
I tried it and my scope shows a very low voltage sine wave like trace.
Code: |
#include "16f690.h"
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES PUT //Power Up Timer ON
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal switch over mode ON
#FUSES FCMEN //Fail safe clock monitor enabled
#FUSES NOCPD //No code protection from EE
#FUSES NOPROTECT //No code read protection
#use delay(int=31000)
void main()
{
setup_timer_2(T2_DIV_BY_1,154,1); //20.0 ms overflow, 20.0 ms interrupt
setup_ccp1(CCP_PWM|CCP_SHUTDOWN_AC_L);//|CCP_SHUTDOWN_BD_L);
set_pwm1_duty((int16)500);
setup_comparator(NC_NC_NC_NC);
while(TRUE)
{
//TODO: User Code
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 22, 2012 3:50 pm |
|
|
Your basic code framework (PIC, Fosc, etc.) seems remarkably similar to
the one in malaika7's post. Clearly, you are students from the same
class. You should read the other classmates posts because some of your
questions may be answered there.
With respect to your current question, I need to know:
1. Is this a Proteus project ? Are you using the Proteus scope ?
Is that where you're seeing the sine wave ?
2. Why are you using such as low frequency as 31 KHz for the PIC ?
3. What is your CCS compiler version ? It's given at the top of the .LST
file. It's just a simple 4-digit number, such as 4.128, or 3.249. Look in
your Project directory after you (successfully) compile a file, and the .LST
file will be there. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Jan 22, 2012 3:57 pm |
|
|
it all depends on what you want to accomplish -
but i can say this
the 32khz internal Oscillator is awfully low frequency for any kind of useful
PWM - let alone bridge operation IMHO.
whats your schematic and what are you trying to DO ? |
|
|
chrismdube
Joined: 30 Dec 2011 Posts: 20 Location: UK
|
Full bridge code |
Posted: Sun Jan 22, 2012 3:58 pm |
|
|
Hi. I copied this off the forum. I'm using the PIC C compiler, version 4.128. The trace I got on my oscilloscope when I plugged the Pic in my board. I am trying to drive an H bridge for power supply. _________________ trojan07 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sun Jan 22, 2012 4:25 pm |
|
|
Obvious point, is that the code is not setup to use full bridge, or half bridge mode, but only single output PWM on P1A. The other pins will be set as inputs, and floating, so the since wave is probably mains pickup.....
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 22, 2012 5:35 pm |
|
|
I ran this program just now, using vs. 4.128, and it outputs the exact
waveforms shown in this diagram in the 16F690 data sheet:
Quote: |
FIGURE 11-11: EXAMPLE OF FULL-BRIDGE PWM OUTPUT
|
Code: |
#include <16F690.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, MCLR
#use delay(clock=4M)
//==========================
void main()
{
setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H);
setup_timer_2(T2_DIV_BY_1, 255, 1);
set_pwm1_duty(100);
while(1);
}
|
This code assumes that your board has a 10K pull-up resistor on the
MCLR pin of the PIC. |
|
|
chrismdube
Joined: 30 Dec 2011 Posts: 20 Location: UK
|
code freeze |
Posted: Mon Jan 23, 2012 4:48 am |
|
|
Hello everyone. I have two configured outputs on my pic. My problem is that they seem to stop function when I include the PMW code. Any ideas. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Jan 23, 2012 4:56 am |
|
|
What pins are they on?.
Best Wishes |
|
|
chrismdube
Joined: 30 Dec 2011 Posts: 20 Location: UK
|
code freeze |
Posted: Mon Jan 23, 2012 10:32 am |
|
|
My apologies for the late response when I need help. The output pins are RB5 and RB6 of PIC16F690. If I disable PWM, they work ok. I thought maybe the PWM is using up power. I also read somewhere of the need for pull up resistors but I'm not sure if this could be the problem. _________________ trojan07 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Jan 23, 2012 10:49 am |
|
|
Post a drawing of the circuit you are connecting to the PWM pins, and details of what this drives.
My 'guess' is that your drive circuit, is actually shorting out the output of the PIC, and hence nothing works when you enable the PWM, or that you are not trapping any flyback energy from what you are driving, and this is going through the PIC and sending it haywire.
'Pull up resistors'. No. I think you are reading something completely unconnected with this. |
|
|
chrismdube
Joined: 30 Dec 2011 Posts: 20 Location: UK
|
code freeze |
Posted: Mon Jan 23, 2012 11:35 am |
|
|
Thank you Ttelmah, I will post my circuit once I get home. It is one output to control the battery charger and another to to turn on or off the output of the bridge, basically a UPS. I have mosgate drivers controlling the bridge transistors. As far as I can tell the PWM works except the other circuits stop working. I think it also depends on how high my modulation frequency is because I noticed that at low frequencies my output pins work albeit with very bad bridge output. My clock speed now is 125KHz. Will post. |
|
|
|