Thank you. I tried to understand from the PBP manual but i couldnt succeed. could you pls give some code Example.
Regards.
Thank you. I tried to understand from the PBP manual but i couldnt succeed. could you pls give some code Example.
Regards.
Hi this program is great that Mel has writen can we use the same program but soon as the button is pressed led go high for 500 / 1/2 second then PWM 50 duty and 5KHz and then then pwm stop when button is released?
i have the program working but the PWM hangs on after the button is off
PushButton var PortA.1 ' Low when Pressed
DIPSwitch var PortA.1 ' Low when ON
LED var PortB.0
TRISA=%1111
TRISA=%0000
Low LED ' Start with LED OFF
Loop: If PushButton=0 then ' Check for Button Press
If DIPSwitch=0 then ' Check for Options
High LED ' Turn ON LED with Button Press...
PAUSE 500
PWM 0,50,500
While PushButton=0:Wend
' Wait here as long as Button pressed
Low LED ' then turn OFF LED
else
Toggle LED ' Toggle LED at each Button Press
While PushButton=0:Wend
' Wait here until fingerreleased from Button
endif
endif
Goto Loop
End
Straight out of the manual:
PWM is a software, bit-banged, command.5.61. PWM
PWM Pin,Duty,Cycle
Outputs a pulse width modulated pulse train on Pin. Each cycle of PWM consists of 256 steps. The Duty cycle for each PWM cycle ranges from 0 (0%) to 255 (100%). This PWM cycle is repeated Cycle times. Pin may be a constant, 0 - 15, or a variable that contains a number 0 - 15 (e.g. B0) or a pin name (e.g. PORTA.0).
The Cycle time of PWM is dependent upon the oscillator frequency. If a 4MHz oscillator is used, each Cycle is about 5ms long. If a 20MHz oscillator is used, each Cycle is about 1ms in length. Defining an OSC value has no effect on PWM. The Cycle time always changes with the actual oscillator speed.
If you want continuous PWM output and the PICmicro MCU has PWM hardware, HPWM may be used instead of PWM. Pin is made an output just prior to pulse generation and reverts to an input after generation stops. The PWM output on a pin looks like so much
garbage, not a beautiful series of square waves. A filter of some sort is necessary to turn the signal into something useful. An RC circuit can be used as a simple D/A converter
HPWM is a hardware driving command. The PIC's internal PWM module is used.
As the book says, PWM will complete X cycles, then it will move on. You can press buttons all you want, the PIC isn't going to respond to anything (unless you've got some assembly interrupts going) until the PWM command is done.
Hi Thanks for that yeah that all makes sense now why it hangs on and yeah thats PWM is not what we want. what we want it to do is the LED go high for 500 micro seconds and then PWM at 50% duty 5KHZ - 10KHZ any ideas for can't a pic do this?
halo...i i'm beginer in PIC use....so i need somebody to give me a PIC coding to controll bidirectional DC motor for my project...i relly2 need help....for those who can help me...i need a that coding just to simulate in proteus 7...i will represent that dc motor to LED as the outpu...
Bookmarks