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 1, 2  Next
Author Message
 Post subject: HPWM disables all Hservo
PostPosted: Fri Sep 02, 2011 8:18 am 
Offline
Citizen

Joined: Fri Sep 02, 2011 8:07 am
Posts: 6
Location: Illinois
Basic atom pro 28m, 2.0.0.14 studio

My test code to confirm the issue.

Code:
pause 500

main
hservo [p0\10000]
pause 1000
hservo [p0\-10000]
pause 1000
hservo [p0\0]
pause 1000

hpwm p10,10000,10000 ;full on
pause 500
hpwm p10,10000,5000 ;half
pause 500
hpwm p10,10000,0 ;full off
pause 500

hservo [p0\10000]
pause 1000
hservo [p0\-10000]
pause 1000
hservo [p0\0]
pause 1000


After the first servo movements, the LED I have attached to PWM using an LED driver composed of a 22k resistor and a 2n2222 transistor, the pwm driving the transistor on and off. After the first movements, the LED will come on and off, but that's it, the servos go limp, I can move them myself. The LED will still continue to cycle on and off afte I'm using this to make a variable LED which is working great, the HPWM works fantastic at driving the LED in this manner. EXCEPT after the hpwm command, any hservo commands, even if looped, cease to function.

I need to use this type of HPWM to drive a few LED's for a camera in a tunneling robot for work under houses. And the LED's I use are stong enough that at close range will wash out the video feed, but need to be turned up at further range.


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Fri Sep 02, 2011 8:29 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
This is an issue for Nathan (Acidtech),

This is what I would have expected. That is both of these sub-systems use the underlying H8/3694 processors TimerW to do this. So they will completely stomp on each other.

At a minimum, I think the manuals should be updated to warn the user about this. Alternatively the compiler could check for this and give the user an error...


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Fri Sep 02, 2011 10:25 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
As Kurt said, HSERVO and HPWM can't work with heach other. They both use TimerW(on the 3694) or TimerZ(on the 3687).

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Fri Sep 02, 2011 10:52 am 
Offline
Citizen

Joined: Fri Sep 02, 2011 8:07 am
Posts: 6
Location: Illinois
What are my alternatives?


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Mon Sep 05, 2011 8:15 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
What are you using the PWM for? Without some idea I can't make any suggestions.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Mon Sep 05, 2011 9:26 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Last thing in his original post:
Quote:
I need to use this type of HPWM to drive a few LED's for a camera in a tunneling robot for work under houses. And the LED's I use are stong enough that at close range will wash out the video feed, but need to be turned up at further range.


With a 28 pin device I'm thinking you should have plenty of I/O pins left. Consider this:
Attachment:
Multi_LEDs_Forums Post.JPG
Multi_LEDs_Forums Post.JPG [ 32.06 KiB | Viewed 619 times ]

Use multiple LEDs, one per Atom I/O pin. I don't show the transistors here, I simplified. You could recreate the LED circuit you're using now and just use different resistor values to arrive at the different outputs you need. I'd say your present circuit has enough output to satisfy the brightest light you need, so use higher-value resistors in the other LED circuits to create lesser outputs. Mix and match, however you see fit. Now you need only simly turn pins on and off. I show P0 thru P3 here, but these can be any P# pins.

If you have no pins left, you're in dutch. Some kind of PWM is all that's left to you.
Take care.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 4:20 am 
Offline
Citizen

Joined: Tue Sep 09, 2008 4:46 pm
Posts: 22
One thing you might consider is using a secondary processor to control your lighting. A Nano 8 with board from Basic Micro is ten bucks and should fit your needs. There are several options for interfacing with your primary processor.

Jim


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 7:01 am 
Offline
Citizen

Joined: Fri Sep 02, 2011 8:07 am
Posts: 6
Location: Illinois
The datasheet mentioned the pro series are unable to output higher currents, and these aren't weak LEDs. They can take up to 50mA at load, per LED. So i'm using an LED driver through a 2n2222 transistor and 22k resistor to drive the transistor. The PWM was being used to dim down the LED's, which works great, except it stops the servos from working.

muskyhuntr might be onto something with a secondary processor. Though I don't have a clue how to go about that.


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 8:08 am 
Offline
Citizen

Joined: Tue Sep 09, 2008 4:46 pm
Posts: 22
There are a couple of ways to do this. One is to use serial out on the main processor and serial in on the secondary. Run a lead between two approprate pins and another for ground between the two. Don't use hserial commands as you will run into the same problems you have now. Put the secondary processor into a continous loop with serial in and if / then statements between. Then using the if statements, check for what you want your lighting to do. For example send a 0 if you want the lights out, a 1 for low, a 2 for medium and a 3 for high. This works well and I have done a number of times.

Another way is to connect a pin from 1 processor to a pin on the other. On the main processor set the pin high or low. On the secondary, check the state of the pin. Put this into a continous loop also. Note that the more you want to control the level of lighting, the more pins you will need. For example, one pin will give you the ability to switch between a high output and a low output. If you want to turn the lights off, you need another pin. I have not used this method.

There are other methods you may want to check into.

Jim


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 8:23 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
Actually HSerial should work fine. Yes it does create interrupts, which can screw up other non-hardware outputs, but in your case should work great.
If you use two Bap28s, you could simply hook up P14 to P15 and P15 to P14, between the two processors, than initialize HSERIAL to the same baud rate.

Like MuskyHuntr said than you have the secondary processor hooked up with your HPWM to the LEDS and you can send commands from the main processor, which this secondary processor could read at it's leasure...

Also depending on how many PWM channels you need you can probably also go with other processors, like smaller BAP or Nano or Arduino...

Kurt


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 11:36 am 
Offline
Citizen

Joined: Fri Sep 02, 2011 8:07 am
Posts: 6
Location: Illinois
Will 3 processors be a problem? We use 1 inside a wired controller linked to the hserial at least until we can switch to wireless of some sort. Software serial should work right? Also size is an issue, we can't have stuff sticking out that can get caught on nails or pipes. We have enough problems with that already.

So i can use the nano 8, with software serial in to recieve commands to change the lights with hpwm? I only need 1 hpwm line, since it uses a transistor driver for the LEDs, all the LED's pass through the same transistor. Which is 2 or 4 LEDs. We switch between 2 and 4 using a manual switch right now, which was our old way of dimming them. But a new higher resolution wide angle camera is having issues with the washout.
The board we're using is some off brand basic stamp board, and the stamp is used in the controller.


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 11:36 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
You shouldn't need a secondary processor. You are driving all LEDs at the same duty? If so then you can generate a software PWM signal using one of the other timers or even just run it in your main loop as long as it runs fairly consistently.

To generate a simple PWM do this:

acc var word
duty var byte

;in looping code or timer interrupt
acc=acc+duty
if(acc.bit8)then
high pwmpin
acc.byte1=0
else
low pwmpin
endif

so what does this code do? It adds a duty from 0 to 255 to acc and if acc overflows to the high byte it sets the pin high(and clears the overflow), otherwise it sets the pin low. This will output an average voltage of duty/256. You can do this in asm as well.

asm{
mov.b @DUTY:16,r0l
mov.b @ACC:16,r0h
add.b r0l,r0h
mov.b r0h,@ACC:16
bnc setlow:8
sethigh:
mov.b #PWMPIN,r0l
_@HIGHFUNCMAC
bra finished:8
setlow:
mov.b #PWMPIN,r0l
_@LOWFUNCMAC
finished:
}

Use an ONASMINTERRUPT for timerV or timerA and run the interrupt a couple thousand times a second. Make sure you push and pop the used registers if using ONASMINTERRUPTs.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 2:59 pm 
Offline
Citizen

Joined: Fri Sep 02, 2011 8:07 am
Posts: 6
Location: Illinois
I didn't understand any of that. I'm just using the studio i downloaded here on the site, and following the manual.


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 8:54 pm 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
Code:
ONINTERRUPT TIMERVINT_OVF, HandleTimerV_OVF
ONINTERRUPT TIMERVINT_CMEA, HandleTimerV_CMEA
enable
LOW P10

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



Main:
   gosub setPWMDuty[25]   
   pause 100
   gosub setPWMDuty[0]   
   pause 100
   gosub setPWMDuty[50]   
   pause 100
   gosub setPWMDuty[0]   
   pause 100
   gosub setPWMDuty[75]   
   pause 100
   gosub setPWMDuty[0]   
   pause 100
   gosub setPWMDuty[100]   
   pause 100
   goto main
   



Duty var   byte
SetPWMDuty[Duty]:
   if Duty = 100 then
      ; If duty is 100% just turn on pin, no need for interrupt
      disable TIMERVINT_OVF
      disable TIMERVINT_CMEA
      HIGH P10
   elseif Duty = 0 ; likewise for 0 except simply turn off
      disable TIMERVINT_OVF
      disable TIMERVINT_CMEA
      LOW P10
   else
      LOW P10
      TCORA = (256*Duty)/100
      enable TIMERVINT_OVF
      enable TIMERVINT_CMEA
   endif
   return
   
; Timer Interrupt   
HandleTimerV_CMEA:
   Low P10
   resume
   
HandleTimerV_OVF:   
   High P10
   resume         
   


Top
 Profile  
 
 Post subject: Re: HPWM disables all Hservo
PostPosted: Tue Sep 06, 2011 8:58 pm 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
The above program is a quick and dirty attempt to demonstrate how you could use TimerV and an interrupt done in basic. Note: I would normally do the interrupt handler in Asm, but hopefully this works well enough. you might try it with HSERVO and see...

Kurt


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

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