Getting the pwm in pic

Thread Starter

adriano08

Joined Apr 25, 2010
33
How do we write a c code for generating pwm in pic 18f4520?

And perhaps some explanation?

#include<pic.h>
#include<delays.h>

void main()
{
...
...
}

I'm still learning. Thanks.:)
 
This is the Code I used on a PIC24FJ128GA010
It's about the most striped down version I can find.
Rich (BB code):
#include <p24FJ128GA010.h> 
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & FWDTEN_OFF & ICS_PGx2) 
_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI) 
void __attribute__((interrupt, no_auto_psv)) _T3Interrupt(void);
void _ISRFAST _T3Interrupt( void){_T3IF = 0;} 
int main() 
{ 
	T3CON = 0x8010;		// This is about 1.25KHz with the Debugger board running at 8MHz 
	PR3 = 400-1;
	_T3IF = 0;
	_T3IE = 1;
	OC1R =OC1RS=200;
	OC1CON = 0x000E;
	while(1);
}
This would produce (on that chip with an 8MHZ Crystal) a 1.25Khz Square Wave (50% modulation)
 

retched

Joined Dec 5, 2009
5,207
Check my topic may be help you but in Arabic language and compiler here MikroC Pro

http://www.dbaasco.com/vb/t5028.html
Here is an english translated version of the link.

It is a very good tutorial.

http://translate.google.com/transla...&tl=en&u=http://www.dbaasco.com/vb/t5028.html

The only thing that confuses me, is the part where you talk about the two men born to you.. I have yet to figure that out. ;)

There are many types of Bey support this property Take the example is No. 16f877 Bey and the Bey Note that this contains the two men born to me
 

Eng_Bandar

Joined Feb 27, 2010
46
Hi retched,​

hahahaha
I think translation of google not perfect. And also Arabic langauge not like English big difference between them. problem where here ? In Arabic langauge find rules to pronounce any word let's take example​

رَجُل

This word mean man

رِجْل


This word mean leg

both words have same letters not same in its shapes

if I wrote this word for you
رجل
and I ask you what is mean this word?
realy you can't know it without its shapes
same problem with google
google don't distingishes shapes of the word​

I hope every thing clear for you​
 

Eng_Bandar

Joined Feb 27, 2010
46
very fun translation.
legs here mean pins of microcontroller

and man word there mean legs in electronic mean pins of microcontroller

Be aware.

:D

Check also my youtube channel
http://www.youtube.com/user/EngBandar1

I hope that will help you

In future I will put English tutorials in my channel
In Matlab, MikroC Pro, Orcad, Proteus and others

:D
 

retched

Joined Dec 5, 2009
5,207
Good. I think you have a lot to offer. And you explain things in a very easy to understand way, with examples and theory.

Ill check out your work.
 
Top