My bad
Once again Thanks Henrik
My bad
Once again Thanks Henrik
Last two questions (I hope so )
in Bruce's Example he's multiplying pdcx by (Lowbyte,Highbyte) Low and high byte of what and what is the purpose of doing that ?
also
anyway I'm going to post the Code since I can't find the problem yet .. what I'm Trying to do is to generate a sinewave from pwm0 with an offset to use that later in a three phase inverter.. so I made this test which gives unexpected results
what I'm trying to do is using entries from a lookup table to generate pulses with duty cycles starting from 1000 to 2000 then back to 1000 (Positive half Cycle) after that going from 1000 to 0 and going back again to 1000 (Negative half Cycle) which isn't happening ..
I'm using 10MHz osc 18f4431, and a lookup table of 25 Entries (Which isn't enough for a smooth wave but this is for testing)
ThanksCode:PORTB = 0 TRISB = %11000000 ' pwm0-5 output PTCON0 = %00000000 ' (1:1) prescale , Free-Running mode PTCON1 = %10000000 'time base is on, Counting is up PWMCON0 = %01000000 'Pwm0-5 enbbled for pwm output, pwm0-5 complementary mode PWMCON1 = %00000001 OVDCOND = %11111111 PTPERL = $D0 PTPERH = $07 'PTPER = 2000 Main: PDC0L = 00 PDC0H = 10 PDC0L = 59 PDC0H = 12 PDC0L = 00 PDC0H = 15 PDC0L = 07 PDC0H = 17 PDC0L = 66 PDC0H = 18 PDC0L = 66 PDC0H = 19 PDC0L = 00 PDC0H = 20 PDC0L = 66 PDC0H = 19 PDC0L = 66 PDC0H = 18 PDC0L = 07 PDC0H = 17 PDC0L = 00 PDC0H = 15 PDC0L = 59 PDC0H = 12 PDC0L = 00 PDC0H = 10 PDC0L = 41 PDC0H = 07 PDC0L = 00 PDC0H = 05 PDC0L = 93 PDC0H = 02 PDC0L = 34 PDC0H = 01 PDC0L = 34 PDC0H = 00 PDC0L = 00 PDC0H = 00 PDC0L = 34 PDC0H = 00 PDC0L = 34 PDC0H = 01 PDC0L = 93 PDC0H = 02 PDC0L = 00 PDC0H = 05 PDC0L = 41 PDC0H = 07 PDC0L = 00 PDC0H = 10 GoTo Main
Last edited by Kloney; - 4th July 2013 at 08:19.
Hi,
You are currently updating the dutycycle register at a very fast rate, much much faster than the PWM frequency. Try insterting a short delay ( PAUSE 5 or whatever) between each duty cycle update. If that doesn't help try explaining what it does and what the problem is.
I'll have to look at Bruce's example to see if I can answer the other (first) question.
/Henrik.
EDIT: OK, looked at Bruce's example but I don't see where he's multiplying the pdcx with anything....could you clarify?
Last edited by HenrikOlsson; - 4th July 2013 at 11:12.
I added a "1 us" delay and it worked quite well but the wave took longer duration time, the output frequency is 16.6hz instead of 50hz becaus of the delay
I'm using 25 entry and the output should be 50hz (Fpwm = 50 * 25 = 1250 I guess ?) how can I fix that ?
Also for the DTCON I can't get this part I need a 5us dead-time and I'm using (Fosc/4) settings what are the calculations needed for "5-0" bits in DTCON to set such a dead-time ?
For Bruce's Example this is the part I'm talking about :
Duty = 800 ' ~50% PDC2L = Duty.LowByte ' maintain a fixed 50% duty cycle on PWM4,5 PDC2H = Duty.HighByte
But i don't think that I'm going to need that in my case I just was wondering to understand the whole thing what are the LowByte and HighByte ?
Thanks Henrick , I can't find words to describe how much you helped me
Hi,
I suspect you added 1ms delay, not 1us.
Correct, if the table is 25 entries for a full cycle and you want 50Hz output you need to index the table at 1250Hz. The delay between each update of the dutycycle should then be 1/1250=800us (so use PauseUs 800 and see what happens). Then, of course, the actual updating of the dutycycle registers takes some small amount of time so if it's critical you'll need to tweak the delay.
The first and last entry in your "lookup table" are one and the same ($1000) - you'll get a "flat spot" in the cycle.
Ah, OK, now I see what you're asking....Bruce is not multiplying anything.
He has a WORD-sized (two bytes) variable, called Duty. He's then assigning the high byte of Duty to PDC0H ( PDC0H=Duty.HighByte ) and the low byte of Duty to PDC0L ( PDC0L = Duty.LowByte ).
I'll have to read the datasheet for the deadtime thing and I don't have time for that at the moment, I'll try to get back to it later.
/Henrik.
Hello again,
If Fosc=10MHz then Tosc=100ns. If you select the source for the Dead Time unit to be Fosc/2 then one "unit" of dead time equals 200ns. You want 5us deadtime which equals 25 "units" of 200ns each so the lower 6 bits of DTCON should be set to 25. If you're using the Fosc/4 setting then one "unit" of deadtime is 400ns and the lower 6 bits would have to be to set to 12.5 to get exactly 5us which obviously isn't possible - use 12 or 13.
/Henrik.
Oh .. I didn't notice this comment when did it show up? thanks Henrick
but still the only left problem is the delay thing which is leading to a lower output frequency.
Also I made an array to lookup up entries and I'm not sure i I'm doing it the right way..
I had to declare each entry in the array one by one .. also compiler refuse using .Lowbyte and .Highbyte (ex : pdc0l=duty[i].lowbyte) with arrays so I made two arrays one for pdcxL and another for pdcxH
is there any other way to declare an array ? or other other function for this case ?
Hi
-Yes it was 1ms not 1us ,and yeah 800us was just fine for dutycycle update you are right.
Tweaking delay, hmmmm .. should I try Higher frequency ?? then (Fpwm= 25 * 50) won't be correct.
that's going to be a problem since I'm going to use 100 entries for a smoother wave.
-Right , I'm going to edit this part
-oops .. I thought he was multiplying, got it now thanks.
-For the DTCON, it's ok I figured it out after re-reading Bruce's example.
Bookmarks