|
|
View previous topic :: View next topic |
Author |
Message |
eminsahin
Joined: 17 Mar 2013 Posts: 5
|
How can I use ECCP in PIC18F4620 |
Posted: Tue Mar 19, 2013 4:31 pm |
|
|
Hi,
I need to generate 40kHz HALF BRIDGE PWM signal with 18F4620. I use compiler of 4.78 and proteus 7.7 . I get output from RC2 (P1A), but I could not get from RD5(P1B). and I must arrange 'dead-time' between P1A and P1B. How can I do that, I find some information by searching but none of them is not useful. can you help me ,
Thanks
Code: | void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_c(0x00);
set_tris_d(0x00);
setup_timer_2(T2_DIV_BY_1, 149, 1);
setup_ccp1(CCP_PWM | CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H);
set_pwm1_duty(80);
|
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Mar 19, 2013 4:35 pm |
|
|
Might this be related numerically somehow to the master clock frequency ... Fosc ??
School or for REAL ??
I need to ask politely, have you read the applicable section of the datasheet for the part ?
Is there not an equation there that points toward mathematical relationship between master clock and PWM frequencies and resolution ?? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Mar 19, 2013 4:54 pm |
|
|
Unfortunately you're trying to use Proteus which is full of bugs,errors,faulty DRCs.
Odds are real good it'll never 'work'..er.simulate.
rule #1 .proteus doesn't work
rule #2 . re-read rule #1
Your program is not complete( can't run as posted ) and the schematic is missing several very,very importnt details.
However, if you re-read the help files of the compiler(press F11),examine the examples that CCS supplies as wellread the 'timer' chapter of the datasheet for your PIC, the answers are there.
Several of us have already done what you describe,maybe with other PICs using different parameters, but no the less, the PIC will do as it's told.
hth
jay |
|
|
eminsahin
Joined: 17 Mar 2013 Posts: 5
|
|
Posted: Tue Mar 19, 2013 4:58 pm |
|
|
yes of course, I read the datasheet, Fosc is equal to 24MHz . I calculated the number of 149 for timer2, to get 40kHz PWM frequency according to mathematical relationship in datasheet, and it provides that.
what is the difference between school or real version for proteus ? |
|
|
eminsahin
Joined: 17 Mar 2013 Posts: 5
|
|
Posted: Tue Mar 19, 2013 5:05 pm |
|
|
I am so sorry, I make a mistake, my proteus is 7.10
what do you think about that ? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Mar 19, 2013 5:22 pm |
|
|
Quote: | what is the difference between school or real version for proteus ? |
You were asked school or real job.
ALL versions of Proteus have similar value.
Follow this link.
http://www.ccsinfo.com/forum/viewtopic.php?t=47549&start=0
Please wait to ask questions when you have problems with REAL hardware.
Mike |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Mar 19, 2013 5:33 pm |
|
|
Quote: |
Fosc is equal to 24MHz
|
w/ or without HSPLL?
so that implies a
#use delay(96000000);
i'm betting your DELAY is 24mhz and Fosc is 6mhz
and no x4 PLL ??? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Mar 19, 2013 5:46 pm |
|
|
eminsahin wrote: | I am so sorry, I make a mistake, my proteus is 7.10
what do you think about that ? | The same as we did before.
You're wasting your time and ours by persisting with Proteus.
Sorry, but it's a basic fact of life, that should be taught in school.
Bye.
Mike
EDIT
(This is not intended as comprehensive, but you should get the idea)
Real life goes roughly something like this; you use real hardware, and have a problem, then:-
1) It's your code. Someone here may help you fix it.
2) The compiler produces wrong code. It's a CCS problem, CCS fixes it.
3) Correct code does not load as it should. Programmer problem.
4) Correct code loads, but does not run as it should. Microchip problem.
You're using Proteus, and it's not working as you want it to.
There's a high probability it's a Proteus problem.
Nobody here can tell for certain where the problem lies.
Three of us are already telling you to throw it (Proteus/ISIS) away. |
|
|
eminsahin
Joined: 17 Mar 2013 Posts: 5
|
|
Posted: Wed Mar 20, 2013 5:10 am |
|
|
Quote: | You were asked school or real job. |
it is for my school project, Mike Walne
Quote: | i'm betting your DELAY is 24mhz and Fosc is 6mhz
and no x4 PLL ??? |
you are right asmboy, delay is 24MHz,
PWM Period=[(PR2)+1]*4*Tosc*(TMR2 Prescale Value)
For 40kHz PWM, PR2 must be 149.
should I use another 18Fxx family of PIC ? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Mar 20, 2013 5:49 am |
|
|
Quote: | should I use another 18Fxx family of PIC ? | Probably not necessary.
Your serious problem is Proteus.
At the risk of antagonising the moderator again.
I'm asking you as politely as I can:-
1) Throw away Proteus.
2) Read the forum guidelines, and follow the instructions there.
3) Take note of the hints you've already been given.
4) Use REAL hardware.
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Mar 20, 2013 6:16 am |
|
|
Seems you have only two options.
Door #1) Get a real PIC,cut code, burn PIC and see what happens, stay here and others will guide you.
Door #2) Find a Proteus forum and stay in faulty,'simulator' land.
If you choose #2, you'll never really learn about PICs, programmming or what happens in the real world.
If you choose #1, you'll find out fast that what Proteus says doesn't work,even though it says it's fine.
For example...if you build your project according to the schematic..
1) no VDD applied to PIC
without power PIC can't run
2) no VSS applied to PIC
without ground PIC can't run
3) no crystal attached to PIC
All PICs need a crystal(or some other oscillator)
4) no crystal caps attached to PIC
All PICs with crystals need caps
5) no power source shown
All PICs need a power supply
6) no on/off switch shown
All power supplies need an on/off switch
7) 'scope' shows signals on C and D without input
Odd as NO source is shown
8) 'scope' shows signal on B but counter is 0
This implies the PIC is sending a triangular signal
9) top counter has a reading
odd, CE(Chip Enable) isn't tied high(enabling counter)
10) PIC is not labelled
major problem !
11) *MCLR pullup goes to 'horizontal' +5V
convention dictates vertical resistor to +5 label
12) 'counters' never reset,just increment pulses
so this is a 'tally' counter
13) 'counters' count what ms,sec,sheep,hours??
well it never is reset, so just counts pulses
Several other 'issues' though I trust my point has been made.
There is NO way this circuit will function in the real world!
If you gave this schematic to a fellow tech,'as is', it will NOT work.
As a teacher, I'd have to give you 0 for your schematic as too much is wrong with it. I never let any tech graduate who didn't deserve to.
As an employer, if you handed it in during the job interview (I give 1 hour tests), you would not be hired. Simply put,my company shouldn't have to teach you the 'basics'.
Sigh,I haven't even got to your code. Frankly without properly configured hardware there is no sense looking at the code (which isn't complete BTW).
You( and others) seem to have blind faith in a simulator that is known to be faulty, buggy, incomplete and the list goes on. Perhaps it's a 'generation' thing, but 'old school' guys like me, use real PICs on test boards,cut code, burn the PICs, see what happens, and try again.
This board has a lot of very talented guys, some light years ahead of me, all willing to help, but NONE of us can fix Proteus.
So you'll have to decide will it be 'door #1' or 'door #2' ?
Hopefully Darrin will leave my post up, I'm not trying to be mean or cruel, just show WHY several of us are frustrated with the 'it doen't work and I'm using Proteus' posts that keep coming here !
hth
jay |
|
|
eminsahin
Joined: 17 Mar 2013 Posts: 5
|
|
Posted: Wed Mar 20, 2013 7:44 am |
|
|
thanks |
|
|
|
|
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
|