BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 7:57 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: HPWM disables all Hservo
PostPosted: Wed Sep 07, 2011 4:56 pm 
Offline
Citizen

Joined: Fri Sep 02, 2011 8:07 am
Posts: 6
Location: Illinois
Thank you.
I will try tomorrow when I'm back at the shop. I don't understand all of it, but I'm confident I can still use it.


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Thu Sep 08, 2011 12:19 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Here is a modified version of Kurts code that only requires one interrupt(using my method described above).

Code:
ONINTERRUPT TIMERVINT_OVF, HandleTimerV_OVF
enable
LOW P10

; Initialize the timer
TCRV0 = 2
TCRV1 = 1  ; clock / 32



Main:
   gosub setPWMDuty[64]   
   pause 100
   gosub setPWMDuty[0]   
   pause 100
   gosub setPWMDuty[128]   
   pause 100
   gosub setPWMDuty[0]   
   pause 100
   gosub setPWMDuty[192]   
   pause 100
   gosub setPWMDuty[0]   
   pause 100
   gosub setPWMDuty[256]   
   pause 100
   goto main
   


Acc var word
Duty var   word
SetPWMDuty[Duty]:
   if Duty >= 256 then
      ; If duty is 100% just turn on pin, no need for interrupt
      disable TIMERVINT_OVF
      HIGH P10
   elseif Duty = 0 ; likewise for 0 except simply turn off
      disable TIMERVINT_OVF
      LOW P10
   else
      enable TIMERVINT_OVF
   endif
   return
   
HandleTimerV_OVF:
   Acc = Acc + Duty
   if(Acc.bit8)then
      High P10
      Acc.bit8=0
   else
      Low P10
   endif
   resume         


This produces a dirty PWM. Eg it doesn't produce clean high side/low side PWM pulses. This will produce a varying Period as the duty changes. But for dirving LEDs(no filtering required) or producing a variable voltage output(with added filtering) this works very well assuming my code doesn't have any typos.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO