CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

16f876A and two PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

16f876A and two PWM
PostPosted: Tue Jul 16, 2013 1:53 pm     Reply with quote

Greetings.
The first time I write and I hope that someone answered.
I want to include both PWM, to make dead time between them, and that's one PWM inverted relative to the other PWM.
I read the forums and I'm not sure I can (have dead time).
If possible, explain to me how, but I know that I'm not an expert programmer - read beginner). I use the CCS C compiler.
Thank you in advance and I apologize for the grammar because I write through the translator. Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 2:09 pm     Reply with quote

Did you look at the PWM section in the 16F876A data sheet ?
http://ww1.microchip.com/downloads/en/DeviceDoc/39582C.pdf
Go to the PWM section and do a search for "dead" (without the quotes).
You won't find it. You need a PIC with an ECCP module.
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 2:20 pm     Reply with quote

Thank you for your response.
I assumed it was not possible in an easy way. How can I "ask" that it be done (do not ask much of him).
Thank you in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 2:44 pm     Reply with quote

It can't.
The only way you could generate this with this chip, would be at low frequency with a software PWM.
It is not something that can be bodged round.
Sometimes the whole 'point' of hardware is to do things that are otherwise almost or totally impossible....

Best Wishes
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 3:10 pm     Reply with quote

Thank you for your sincere answer.
Which is better PIC 18F4431 or PIC18F4550 ?
I hope I'm not boring you with questions? Smile

By the way.
This is what I wrote in a hurry. It's not ideal but if I put it to my routine stops might be able to add some other part (initialization of the display or processing of feedback) and we keep the same frequency and dead time. By changing the variables x I get a change signal - pause while the frequency remains the same as the dead time.
Code:

#include <16F876.h>
#use delay(clock=20000000)
int x=15,y=2,z;

void main()
{
z=30-x;

while(true)
  {
   output_bit( PIN_B0, 0);
   delay_us(x);
   output_bit( PIN_B0, 1);
   delay_us(y);
   output_bit( PIN_B1, 1);
   delay_us(z);
   output_bit( PIN_B1, 0);
   delay_us(y);
  }
}
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 9:47 pm     Reply with quote

Hi strsh,

Are you working with real hardware, or is this a Proteus simulation? I ask because your "written in a hurry" program is lacking a key detail. As a hint,
take a look at any other program posted here on the forum, and see if you can see anything missing between your PIC declaration, and your #use delay.....

John
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

PostPosted: Wed Jul 17, 2013 12:04 am     Reply with quote

You're right, I am writing in Proteus. This is just an idea, no detail in the code, which can be put into practice with the addition of the rest of the code. I'm interested in your opinion, to think about this approach or to take a pic with a ECCP module?
Greetings. Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Jul 17, 2013 8:40 am     Reply with quote

The approach won't work.

1) What is the shortest delay, that variable 'delay_us' calls can generate?.
2) As soon as you do anything at all 'else', the frequency will go wrong.

To keep constant frequency, you only hope is to use interrupts.

The fastest way, is to use a timer interrupt (polled, rather than calling a handler), to synchronise the loop. However even than the amount of other processing you can do, is very limited indeed. Think that a _single_ division will take dozens of times the loop time for any reasonable PWM rate.....

Generally all PIC's have good reasons to exist. 4550, gives you USB. The 4431, gives you QEI support , and power control PWM, rather than ECCP.
Each has distinct advantages, depending on what you want to actually 'do'.

That your code even remotely appeared to work, shows the dangers of Proteus.....
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

PostPosted: Wed Jul 17, 2013 4:24 pm     Reply with quote

Thanks for your opinion.
I give up on the idea that the project do with 16f876. I just do not understand why there are two PWM and can work independently and without dead time?
Greetings. Smile
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jul 17, 2013 6:15 pm     Reply with quote

..from the data sheet...
The PWMs will have the same frequency and update rate (TMR2 interrupt)
..
The two PWM modules are separate( aside from using Timer2 as the interrupt),consider them as two independent peripherals like a receive only UART and a transmit only UART that share the same baudrate generator.No one says a UART _must_ have both xmt and rcv functions.
This allows a programmer to use one for say LED brightness and the other for FAN speed. Both of these uses are independent of each other however when you get into SMPS or motor speed controls(esp. multiphase units) then the issue of 'deadband' and 'complimentary' outputs is required.
For this type of control a PIC with ECCP is required as PCM programmer pointed out is the 'hardware' solution, doing it in 'software' can be done but is 'tricky' to accomplish.

The hardest part of programming today is selecting the best PIC for the job. The better you detail what it is to do, the easier it is to choose the best PIC.

hth
jay
strsh



Joined: 16 Jul 2013
Posts: 37

View user's profile Send private message

PostPosted: Tue Jul 30, 2013 10:21 am     Reply with quote

I gave up on software solutions, but I'm going to try it with a PIC 18F4431.
Thanks again for the advice.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group