HB-25 Motor Controller and photocell?
Bladerunner
Posts: 25
I am trying to control a 12v motor with the HB-25 and photocell. I am looking at the EXPERIMENT #18: A LIGHT CONTROLLED THEREMIN in StampWorks
as a sorce file and the HB-25 sample file...
I have them working independently but not together.
Any thoughts on how to get this to work?
I want the motor to go on and off depending in the light level.
Thanks
Kevin
as a sorce file and the HB-25 sample file...
I have them working independently but not together.
Any thoughts on how to get this to work?
I want the motor to go on and off depending in the light level.
Thanks
Kevin
Comments
·
·· The Theramin experiment is dealing with a proportional output, but it seems like you want an on/off output in relation to light level?· Is this correct?· If so that would also be pretty easy once you know the values coming back from the photocell and the motor speed pulses required.· If you can confirm I can try to demonstrate this for you with an example.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I had this set up working with a stepper motor but not with the HB-25.
I am new at this stuff so don't laugh at my code.
Stepper code that worked:
' I/O Definitions
'
Speaker CON 0 ' piezo speaker output
PitchCtrl CON 1 ' pitch control (RCTIME) input
PotCW CON 0 'clockwise pot input
Coils VAR OUTB 'output to stepper coils
'
' Variables
'
stpIdx VAR NIB ' step pointer
idx VAR BYTE
speed VAR WORD ' delay between steps
x VAR BYTE ' loop counter
sAddr VAR BYTE ' EE address of step data
rcLf VAR WORD ' rc reading - left
diff VAR WORD ' difference between readings
'
' EEPROM Data
'
' ABAB
'
Step1 DATA %1100 'A on B on A\ off B\ off
Step2 DATA %0110 'A off B on A\ on B\ off
Step3 DATA %0011 'A off B off A\ on B\ on
Step4 DATA %1001 'A on B off A\ off B\ on
'
' Initialization
'
Initialize:
DIRB = %1111 'make stepper pins outputs
speed = 5 'set starting speed
sAddr = 0
'
' Program Code
'
Main:
FOR x = 1 TO 40 ' 1 rev forward
GOSUB Step_Fwd
NEXT
PAUSE 200
FOR x = 1 TO 48 ' 1 rev back
GOSUB Step_Rev
NEXT
PAUSE 200
Step_Demo:
HIGH PitchCtrl
PAUSE 1
RCTIME PitchCtrl, 1, rcLf ' read potentiometer
rcLf = rcLf MIN 1 MAX 460
IF rcLf > 200 AND rcLf < 260 THEN Step_Demo 'range 201-259 = dead zone
IF rcLf > 260 THEN Step_CCW
Step_CW:
speed = 1'(rcLf ) + 5 MIN 5 MAX 200 'pot range 1 - 200 = CW motion
DEBUG "cw ",DEC speed,CR
GOSUB Step_Fwd ' do a step
GOTO Step_Demo
Step_CCW:
speed = 0 '200 - ((rcLf - 260) ) + 5 MIN 5 MAX 200 'pot range 260 - 460 = CCW motion
DEBUG "ccw ",DEC speed, CR
'GOSUB Step_Rev
GOTO Step_Demo
'
' Subroutines
'
Step_Fwd:
sAddr = sAddr + 1 // 4 ' point to next step
READ (Step1 + sAddr), Coils ' output step data
PAUSE speed ' pause between steps
'Step_Fwd:
'stpIdx = stpIdx + 1 // 4
RETURN
Step_Rev:
sAddr = sAddr + 3 // 4 ' point to previous step
READ (Step1 + sAddr), Coils
PAUSE speed
RETURN
**************************************************************
but with the HB25 no go????:
HB25 CON 0 ' piezo speaker output
PitchCtrl CON 1 ' pitch control (RCTIME) input
'
' Constants
'
'Scale CON $0100 ' divider for BS2/BS2e
'Threshold CON 200 ' cutoff frequency to play
'
' Variables
'
'tone VAR WORD ' frequency output
index VAR WORD
'
[noparse][[/noparse] Initialization ]
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750 ' Stop Motor 1
PAUSE 1 ' 1 mS Delay
'PULSOUT HB25, 750 ' Stop Motor 2 (If Connected)
' The Above 2 Lines May Be Removed
' If You Are Using Single Mode
'
' Program Code
'
Main:
PAUSE 20 ' Wait 20 mS Before Ramping
FOR index = 0 TO 250 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + index ' Motor 1 Forward
'PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
'PULSOUT HB25, 750 - index ' Motor 2 Reverse
'PAUSE 20 ' 20 mS Smoothing Delay
NEXT
PAUSE 3000 ' Wait 3 Seconds
FOR index = 250 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 + index ' Motor 1 Forward Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
'PULSOUT HB25, 750 - index ' Motor 2 Reverse Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
MOTOR:
HIGH PitchCtrl ' discharge cap
PAUSE 1 ' for 1 ms
RCTIME PitchCtrl, 1, index ' read the light sensor
index = index MIN 0 MAX 250 ' scale input
IF index > 1 THEN Main ' skip for ambient light
FREQOUT HB25 , 1, index
'NEXT
'PAUSE 20
FOR index = 0 TO 250 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + index
NEXT ' output the tone
GOTO MOTOR
END
HB25 CON 0 should be HB25 PIN 0
Without this change the line ---- DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
will loop forever as HB25 always equals 0 and will never become TRUE (1)
Charlie
thanks I think I almost have it!!!!!!!
Thanks
Kevin
''
' I/O Definitions
'
HB25 PIN 0
PitchCtrl CON 1
'
' Variables
'
'tone VAR WORD ' frequency output
index VAR WORD
'
[noparse][[/noparse] Initialization ]
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750 ' Stop Motor 1
PAUSE 1 ' 1 mS Delay
'
' Program Code
'
Main:
HIGH PitchCtrl ' discharge cap
PAUSE 1 ' for 1 ms
RCTIME PitchCtrl, 1, index ' read the light sensor
index = index MIN 1 MAX 250 ' scale input
IF index > 200 AND index < 260 THEN Main: ' skip for ambient light
IF index >260 THEN GOOD:
GOOD:
FOR index = 0 TO 250 ' Ramp Up To Full Speed
PULSOUT HB25, 500 + index
NEXT
GOTO Main:
END
Never mind, you can use CON in this case.
Post Edited (Charlie Johnson) : 11/30/2006 10:54:02 PM GMT
What is happening is the motor is recving pluses as long as it has light, then is off when the photocell is covered/dark.
I want the motor when it gets light to run smoothly not pulse or rev up and down. Just ON/OFF
Thanks
Kevin
Thanks for your help with this.
Its seems to be working but when I put in any code related to having the motor switch direction nothing works.
Basicly I want the photocell when triggered to make the motor go foward then reverse each time it is triggered.
Thanks
Kevin
' I/O Definitions
'
HB25 PIN 0 ' piezo speaker output
PitchCtrl PIN 1 ' pitch control (RCTIME) input
' Variables
'
index VAR WORD
'
[noparse][[/noparse] Initialization ]
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750 ' Stop Motor 1
PAUSE 1 ' 1 mS Delay
'PULSOUT HB25, 750 ' Stop Motor 2 (If Connected)
' The Above 2 Lines May Be Removed
' If You Are Using Single Mode
'
' Program Code
'
Main:
HIGH PitchCtrl ' discharge cap
PAUSE 1 ' for 1 ms
RCTIME PitchCtrl, 1, index ' read the light sensor
index = index MIN 1 MAX 250 ' scale input
IF index > 200 AND index < 260 THEN Main: ' skip for ambient light
IF index > 260 THEN GOOD:
GOOD:
FOR index = 0 TO 150 ' Ramp Up To Full Speed
PULSOUT HB25, 500 - index
NEXT ' output the tone
GOTO Main:
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
any idea on how to make this work I am stumped
Thanks
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' ==============================================================================
'
'
' I/O Definitions
'
HB25 PIN 0
PitchCtrl PIN 1
'
' Variables
'
index VAR WORD
'
[noparse][[/noparse] Initialization ]
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750 ' Stop Motor 1
PAUSE 1 ' 1 mS Delay
'PULSOUT HB25, 750 ' Stop Motor 2 (If Connected)
' The Above 2 Lines May Be Removed
' If You Are Using Single Mode
'
' Program Code
'
Main:
HIGH PitchCtrl
PAUSE 1
RCTIME PitchCtrl, 1, index
index = index MIN 1 MAX 150
IF index > 2 AND index < 100 THEN Main:
IF index > 100 THEN GOOD:
GOOD:
FOR index = 0 TO 150 ' Ramp Up To Full Speed
PULSOUT HB25, 500 + index
PAUSE 9
NEXT
FOR index = 150 TO 0 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + index ' Motor 2 Reverse
PAUSE 20
NEXT
FOR index = 0 TO 150 ' Ramp Up To Full Speed
PULSOUT HB25, 500 + index
PAUSE 1
NEXT
FOR index = 150 TO 0 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + index ' Motor 2 Reverse
PAUSE 20
NEXT
FOR index = 0 TO 150 ' Ramp Up To Full Speed
PULSOUT HB25, 500 + index
PAUSE 10
NEXT
FOR index = 150 TO 0 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + index ' Motor 2 Reverse
PAUSE 1
NEXT '
GOTO Main:
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support