three level pwm using pic

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
nur3
Posts: 7
Joined: Wed Feb 11, 2009 4:48 am
Contact:

three level pwm using pic

Post by nur3 »

hi...
can anybbody pls help me...
how to generate three level pwm using pic 16f628...
how to actually create triangular and sine lookup table...
i'm new to pic...and trying so hard to learn how to program it!!!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: three level pwm using pic

Post by Benj »

Hello

Here are some examples of look up tables using Flowcode.

http://www.matrixmultimedia.com/mmforum ... =LUT#p5509

Hope this helps.

nur3
Posts: 7
Joined: Wed Feb 11, 2009 4:48 am
Contact:

Re: three level pwm using pic

Post by nur3 »

Yeah..thanks a lot...
does the triangle lookup table also use the same method as sine table.
how to program it using assembly language?
and one more thing..what is actually flowcode... :?: :!:

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: three level pwm using pic

Post by Benj »

Hello

Yes any look up table can be performed using the method shown. Good luck in assembler!

Flowcode is a high level graphical language for PICs, AVR and ARM. You can download a demo from here.

http://www.matrixmultimedia.com/Flowcode3a-X.php

nur3
Posts: 7
Joined: Wed Feb 11, 2009 4:48 am
Contact:

Re: three level pwm using pic

Post by nur3 »

hi..
if we use the comparator to generate pwm,it is possible that we use external source rite...for instant if we use sine voltage,then we dont need sine lookup table anymore rite??
:roll:

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: three level pwm using pic

Post by Benj »

Hello

This search may prove useful to you.
http://www.google.co.uk/search?hl=en&q= ... arch&meta=

Example of assembler look up table.
http://web.hazmat.com/~mjb/projects/rswg/

The comparitors compare two analogue signals to provide greater then, less then or equal. Not quite sure how this would help the PWM operation. You could use analogue readings to take in your external signal but you will then have the problem of synching the readings with a full period of the wave.

nur3
Posts: 7
Joined: Wed Feb 11, 2009 4:48 am
Contact:

Re: three level pwm using pic

Post by nur3 »

hi..
thanks a lot for the link...
the project that im doing rite now requires me to use the pic for the switching scheme for my inverter...
so..in order to 'on' or 'off' the switches, i need to use the pwm method...i need to generate 3 level pwm by using sine wave and two triangular wave...
currently im using pic16f628...but i dont know whether to use timer1 or timer2...
sorry...im a bit slow in programming.. :cry:

nur3
Posts: 7
Joined: Wed Feb 11, 2009 4:48 am
Contact:

Re: three level pwm using pic

Post by nur3 »

hi..
if i want the output to be analog, what pic that i should use?
anybody knows???

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: three level pwm using pic

Post by Benj »

Hello

There are a couple of ways of outputting analogue using the PICmicro devices.

1) A 8-bit R2R ladder network.

2) PWM with a stabilizing cap.

The PWM method seems to be less noisy and also less costly as you only need a capacitor instead of around 24 resistors.

nur3
Posts: 7
Joined: Wed Feb 11, 2009 4:48 am
Contact:

Re: three level pwm using pic

Post by nur3 »

hi....
what is stabalizing cap means??
and one more thing, how does the output of the p16f628 is like,i.e is it in 8 bit output or its output in serial bit....
im doing the lookup table....does each of the data occupy one memory add???or the memory location is replaced from one data to another;
this is the sample of my lookup table:

sinetable equ 0x20
lookup1 movf sinetable,w
addwf PCL
retlw 1
retlw 3
retlw 4
retlw 6
retlw 7
retlw 8
and many more data following this...approximately there are 180 data....
so...how does the output of this data will come out...i mean after it goes through comparator...

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: three level pwm using pic

Post by Benj »

Hello

A capacitor can be placed between the PWM output and ground. This will act to smooth out the PWM and give you a nice analogue output signal. The Time constant of the capacitor should be approximatly 3 periods of the PWM to allow for nice smoothing without missing too much information.
how does the output of the p16f628 is like
Depends if your using digital outputs, the UART hardware or the PWM hardware onboard the device.

Yes each data chunk in your lookup table will consume one byte of memory.
how does the output of this data will come out...i mean after it goes through comparator
Depends if your using digital outputs, the UART hardware or the PWM hardware onboard the device.

KeithSloan
Posts: 114
Joined: Fri Jul 27, 2007 10:50 am
Been thanked: 1 time
Contact:

Re: three level pwm using pic

Post by KeithSloan »

Maybe speaking out of turn here. My understanding of PWM is that you need to pass it through a low pass filter i.e. A resistor in series and Capacitor in parallel. The cut off frequency for the low pass filter is given by 1/(2 * pi * R * C ). The cut off frequency being the frequency that the signal starts to be attenuated. If you want faster attenuation you add another low pass filter in series i.e. you end up with 2 resistors in series and 2 capacitors in parallel. Being naive about such things I would have expected to have the cut-off frequency the same as the PWM frequency to get a sine wave ( Fourier analysis etc ) But for some reason all of the circuits I have seen seem to cut in earlier.

nur3
Posts: 7
Joined: Wed Feb 11, 2009 4:48 am
Contact:

Re: three level pwm using pic

Post by nur3 »

Hi...
thanks for all your guides....
after read the datasheet, i found out that the pic allows analog input, for the comparator mode...
so this means that i can directly supply analog input to the pic and the comparator will do it works...rite??...
and i just need to do some delay to the pic...the question is...what the purpose of the delay if i use the analog input...

Post Reply