View previous topic :: View next topic |
Author |
Message |
strsh
Joined: 16 Jul 2013 Posts: 37
|
16f876A and two PWM |
Posted: Tue Jul 16, 2013 1:53 pm |
|
|
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. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
strsh
Joined: 16 Jul 2013 Posts: 37
|
|
Posted: Tue Jul 16, 2013 2:20 pm |
|
|
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: 19509
|
|
Posted: Tue Jul 16, 2013 2:44 pm |
|
|
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
|
|
Posted: Tue Jul 16, 2013 3:10 pm |
|
|
Thank you for your sincere answer.
Which is better PIC 18F4431 or PIC18F4550 ?
I hope I'm not boring you with questions?
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
|
|
Posted: Tue Jul 16, 2013 9:47 pm |
|
|
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
|
|
Posted: Wed Jul 17, 2013 12:04 am |
|
|
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. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Wed Jul 17, 2013 8:40 am |
|
|
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
|
|
Posted: Wed Jul 17, 2013 4:24 pm |
|
|
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. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Jul 17, 2013 6:15 pm |
|
|
..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
|
|
Posted: Tue Jul 30, 2013 10:21 am |
|
|
I gave up on software solutions, but I'm going to try it with a PIC 18F4431.
Thanks again for the advice. |
|
|
|