AHHHHHHH!! What am i missing

sketchy

New Member
You guys must think i am well thick. I just dont get it. I think i am getting the hang of it so i read up and try somthing and it dose not work. BooHoo.

I Now have a problem with button code.

BUTTON pin,downstate,delay,rate,bytevariable,targetstate,address
- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
- Downstate is a variable/constant (0 or 1) which specifies what logical state is
read when the button is pressed.
- Delay is a variable/constant (0-255) which specifies time before a repeat if
BUTTON is used within a loop.
- Rate is a variable/constant (0-255) which specifies the auto-repeat rate in
BUTTON cycles.
- Bytevariable is the workspace. It must be cleared to 0 before being used by
BUTTON for the first time.
- Targetstate is a variable/constant (0 or 1) which specifies what state (0=not
pressed, 1=pressed) the button should be in for a branch to occur.
- Address is a label which specifies where to go if the button is in the target
state.
If understand what the manuel above says downstate should be 1 when the button is pressed and targetstate should be 1 when the button is pressed.

So why does the example code work when it is all set to 0
Code:
main: button 0,0,200,100,b2,0,cont
‘ jump to cont unless pin0 = 0
toggle 1 ‘ else toggle input
goto main
cont:

b1=b1+1
goto main
What is the relevance of B2 as it dose not change in the simulator.

I have written this code
Code:
main: button 0,1,50,50,b0,1,cont

goto main

cont:

b1=b1+1
goto main
and it works mor or less the same but both codes only work once.
If the button is pressed a second time the cycle stops on the button code line instead of jumping to cont.

What i want to do is make b1 cycle 0,1,2,3,0,1,2,3,etc every time the button is pressed so i can write a code that says somthing like if b1 = 1 then or if b1 = 2 then and so on

What am i missing or am i to thick to realise i am thick :)

Thanks again

Joe
 

sketchy

New Member
I think so. i am going to get an lm317 chip and a 3.9ohm resistor tommorw from rs cos i have one just down the road so fingers crossed it will work ok at 320ma.

i have not found out what a buck regulator is but i will look in to it .

thanks for the kspek link that was very good.
 

eclectic

Moderator
Joe.

Just out of interest.

LM317 and a 3.9 ohm resistor? Is that all?

Can you show us what circuit you are planning to use?

Or, the datasheet page?

e
 

BCJKiwi

Senior Member
This code from the last post (#7) in this thread
http://www.picaxeforum.co.uk/showthread.php?t=10139 (08M controlled Adjustable Voltage Regulator).
It may help? This was the first working Button command code I achieved. Had a couple of quick dabbles previously without success and this solution took more time than I would have expected to sort out so you are not alone in finding this command tricky to comprehend.

Code:
#PICAXE 08M
setfreq M8
SYMBOL Up_PB     = 4            'Input4 PB Up
SYMBOL Dn_PB     = 3            'Input3 PB Dn
SYMBOL FeedBk    = 1            'ADC1   FeedBack
SYMBOL Gate      = 2            'In/Out2
High Gate                       'Drive Vout to minimum for safety!
SYMBOL Dn_Var    = b8           'Button Command Repeat storage variable
SYMBOL Up_Var    = b9           'Button Command Repeat storage variable
SYMBOL Set_Var   = w5
SYMBOL FeedBk_Var= w6
Set_Var = 1                     'Preset Program to Minimum Vout for safety
 
main:
' These Button Command explanatory notes courstesy of BeanieBots.
' "Delay" is how many times the command must be passed before it does the first repeat.
' "Rate" is how many times the command must be passed before it subsequent repeats.
' "Var" must be set to zero before the command is used (as explained in the manual) but 
'  that must be a once only setting. It must be done before you enter the loop which scans your button.
' Delay = 255 == No repeat
 
 
'BUTTON pin   ,downstate,delay,rate,bytevariable,targetstate,address
Button  Dn_PB ,1        ,200  ,4   ,Dn_Var      ,1          ,Vout_Dn  'Delay ~ Max = 254 = Longest 
Button  Up_PB ,1        ,200  ,4   ,Up_Var      ,1          ,Vout_Up  'Rate  ~ Min = 1   = Fastest

goto adjust      'If no button pressed, goto Adjust:
Vout_Dn:
   Set_Var = Set_Var - 1 Min 1  'If min not set at 1, 0-1=65535 ~ underflows Set_Var to 65535!
   goto Adjust
Vout_Up:
   Set_Var = Set_Var + 1 Max 1023
adjust:
   readadc10 FeedBk,FeedBk_Var  'get voltage data from output via 240R and Vout
   if Set_Var = FeedBk_Var then
      input Gate                'hold Gate charge
      goto  main                'return, output matches target
   EndIf
increase:
   if Set_Var > FeedBk_Var then 'Out put is too low so raise output
      low Gate                  'lower Gate V = Lower MOSFET R = Higher Current through Adj circuit = higher Vout
      goto main
   EndIf
decrease:
   'if Target < FeedBk_Var then ~ falls through to decrease if not increase! If...Endif not required
      high Gate                 'Higher Gate V = Higher MOSFET R = Lower Current through Adj circuit = Lower Vout
      goto main
end
 
Last edited:

BeanieBots

Moderator
Joe.

Just out of interest.

LM317 and a 3.9 ohm resistor? Is that all?

Can you show us what circuit you are planning to use?

Or, the datasheet page?

e
Yep, that's all you need.
Can be done with any regulator to create a constant current but the LM317 is the best because the voltage across the resistor is only 1.25v.
It can be done with a 7805 but that would require 5v across the resistor.
Keep an eye on the power dissipation though.
 

sketchy

New Member
when you say.

Keep an eye on the power dissipation though. do you mean heat?

Why is 1.25v better. I thought this way was just to limit the current so the output voltage is the same as the supply voltage?

joe
 
Top