Samplecode for Software PWM

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
corado
Posts: 401
Joined: 28 Mar 2009 11:03

Samplecode for Software PWM

#1 Post by corado » 17 Mar 2013 21:20

Hallo,
have anyone samplecode how I can make a Software PWM?
I have used the wrong Pins from Attiny 45 and now I have 200!! of wrong Boards :-(

stefkpl
Posts: 26
Joined: 21 Jan 2009 15:57

Re: Samplecode for Software PWM

#2 Post by stefkpl » 11 Sep 2013 16:20

Hi, I don't have any code sorry but I think you must use timer interrupt with 2 variables, "_up" et "_down"

duty cycle is equal to 50% when "_up" = "_down".

Code: Select all

procedure on_Interrupt
begin
   inc(global_counter)

   if (global_counter > _up) then
   Begin
       global_counter = 0
       portx.x = 0 
   end

   if (global_counter > _down) then
   Begin
       global_counter = 0
       portx.x = 1 
   end
end
It's just little algorithm

Regards

Stéf

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: Samplecode for Software PWM

#3 Post by jpc » 12 Sep 2013 06:56

corado, what frequency and resolution do you need?
Au royaume des aveugles, les borgnes sont rois.

corado
Posts: 401
Joined: 28 Mar 2009 11:03

Re: Samplecode for Software PWM

#4 Post by corado » 12 Sep 2013 08:14

first, I only want the rpinziple of an PWM Routinge..
I want it to use like Softpwm:=50;
Or nearly this was..

I want to use it to generate negative Voltage with coil, Diode, and Resistor at any Portpin from AVR

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: Samplecode for Software PWM

#5 Post by jpc » 12 Sep 2013 09:35

for that purpose you would want a rather high frequency , the highest frequency you could get would be a fixed 50% dutycyle driven by timerinterrupt. The interrupt_frequency in that case is only twice the pulse frequency, probably limited to a few kHz.
All you have to do in the interrupt is toggle the pin. ( keep in mind this is NOT pwm)
Au royaume des aveugles, les borgnes sont rois.

Post Reply

Return to “mikroPascal PRO for AVR General”