PDA

View Full Version : signal integrity



Srigopal007
- 21st January 2005, 17:23
Hi, I was wondering if anyone cna help me with this piece of code that I am trying to generate, I am trying to do this in software but not getting the output that I really want. I am using the PIC16F777 as the pic of choice. and trying to generate a constant 120Hz PWM but it seems to not work. any help with this would be greatly appreciated. Thank you....

'========================'
here is the code that I have :

LOOP1:
duty = duty + 1
A = duty * 79
PortC.5 = 0
Pauseus 10033 - A
PortC.5 = 1
Pauseus A
if(duty < 127) then goto LOOP1
if(duty >= 127) then return
'======================='

Srigopal007
- 21st January 2005, 17:24
Ohh I forgot.. the code that I have above only lasts for like 1 or 2 seconds. how do I make it so that it will lasts for like 4-5 seconds. thankss

mister_e
- 21st January 2005, 17:35
PAUSEUS 10033 is an invalid task IMO

As i understand you want to generate a constant PWM and change duty while it's running?!? Like a 5 sec fade-in or fade-out ??

There's certainely more than one method to do it. Can you provide the crystal frequency you're using ???

Srigopal007
- 21st January 2005, 17:58
I am using 20 MHz ... for the crystal.


I have included
DEFINE OSC 20 on top of my code.

Srigopal007
- 21st January 2005, 18:03
the PwM should go from 0 to 100% duty with 120Hz constant frequency ... in lets say it takes 5 seconds to ramp up ...

mister_e
- 21st January 2005, 18:14
O.K., for now i've to go out for few hours, but as soon i return, i'll figure out something. IMO using some TIMER interrupts will be more efficient and easier. I'll let you know.

All we need it's an interrupt every 8.3333333 msec. Once we have it, we just have to play with HIGH and LOW timing to the outputs.

And then loop it 600 time will gives you 5 secondes.

mister_e
- 21st January 2005, 18:45
Before i really left my home,

Is 60Hz is your AC line frequency? In this case, use this frequency to generate interrupt and then play with timing.

One another thought, i don't know if your PIC have a PWM module. Case yes, Use this pin an let it run @ 120 HZ at whatever duty cycle. Connect this PWM pin to another pin who can give you interrupt. When you jump to the interrupt routine, play with the duty cycle you need. This is the easyest i can figure now.

Now i really go :)

mister_e
- 24th January 2005, 09:52
The attached code is based on the TIMER1 interrupt. For an 16F877 but the theory is there.

Have fun!

Srigopal007
- 24th January 2005, 19:58
I was wondering how do I control the pwm for this. lets say I have a button .. and while I pressed the button the PWM will increase.. but when the button is not pressed the pwm pauses. and when the button is pressed again the pwm resumes where it was paused.

I can think of it like this

for i = 0 to 100
if(i < PwmIncSTEP) PortD.1 = 1
if(i >= PwmINCStep) PortD.1 = 0

Next i

There is one questionable thing about this, when I have a led at the output to test the pwm. i see like a flickering. the reason why I think this is the case. is because the correct pause sequence is not there. Can you please help with a better solution
thanks.

Srig

mister_e
- 25th January 2005, 01:20
There is one questionable thing about this, when I have a led at the output to test the pwm. i see like a flickering. the reason why I think this is the case. is because the correct pause sequence is not there. Can you please help with a better solution


remove the capacitor around your 20MHZ crystal an post the answer.



I was wondering how do I control the pwm for this. lets say I have a button .. and while I pressed the button the PWM will increase

refer to this section


' Let's see how many time we have come here
' -----------------------------------------
'
if PWMIncStep<600 then
PWMIncStep=PWMIncStep + 1 ' not enough, come again and do
' one more PWM increment step.
else
pwmincstep = 0 ' enough is enough, pass go and claim 200$
' Also, since you're there redo the ramp-up
'
toggle timerled ' toggle status LED
endif


the easyest solution is to add a simple IF THEN statement



' Let's see how many time we have come here
' -----------------------------------------
'
if PWMIncStep<600 then
If PushButton then ' If pushbutton is pressed
PWMIncStep=PWMIncStep + 1 ' do the PWM
endif
else
pwmincstep = 0 ' enough is enough, pass go and claim 200$
' Also, since you're there redo the ramp-up
'
toggle timerled ' toggle status LED
endif