My schematic, couple questions.

evanh

Senior Member
hah.. wouldn't happen.. Maybe in time.
:) Yep, the language details takes some practice. After that it's mostly a case of sitting down and thinking hard about the logic.

..Is it customary to use digital pots for ADC inputs? ..would that just solve the issue without bulking up the code? ..apparently it just has 256steps that click all the way through.
/me spits on such ideas. Code is your friend. That's why the Picaxe is in the circuit. The digital pot is prolly more expensive than the Picaxe anyway.

If you are happy to use pushbuttons then you can input them directly into the Picaxe and have an internal incremental value for each setpoint.

Another way that is popular now and brings best of both methods - attach a rotary encoder in place of the pot.


Evan
 

Shafto

Senior Member
You've got analogue!? I'd missed that. You plan on keeping them in the final circuit?
I must have misunderstood? it seemed like you were saying it was odd to use analogue pots for ADC input.


I tried to use the code you provided hippy, but I'm getting a syntax error I can't figure out, this line won't work:

if b2 < b6-1 or counter <= COUNT_NEEDED then

Here's how I have the code setup.. I suppose I need to make separate symbols for all the counters and such for the brake ADC input?

Code:
init:

pwmout 1,255,0                   'turn on PWM signal for brakes
pwmout 2,255,0                   'tuen on PWM signal for markers

main:
	
	readadc 0,b0		   'signal fade in time

	readadc 1,b1		   'signal fade out time






symbol GOING_UP = b8
symbol GOING_DOWN = b9
symbol direction = b10
symbol counter = b11
symbol COUNT_NEEDED = b12

	readadc 2,b2		   'PWM duty cycle for marker lights
	  b4 = 4
	  w3 = b4 * b2

If direction = GOING_UP Then
    If b2 >= b6 Then
      b6 = b2
      counter = 0
   Else
      if b2 < b6-1 or counter <= COUNT_NEEDED then
        b6 = b2
        direction = GOING_DOWN
        counter = 0
    Else
        counter = counter - 1
      End If
    End If
  Else
    If b2 <= b6 Then
      b6 = b2
      counter = 0
    Else
      If b2 > b6+1 Or counter >= COUNT_NEEDED Then
        b6 = b2
        direction = GOING_UP
        counter = 0
      Else
        counter = counter + 1
      End If
   End If
  End If


    






  readadc 3,b3               'PWM duty cycle for brake lights
      b5 = 4
      w4 = b5 * b3



	



	pwmduty 1,w4                    'update PWMduty for brakes


	if pin1 = 1 then pwmduty 2,w3   'if pin1 goes high turn on marker lights
	end if

	if pin1 = 0 then pwmduty 2,0    'if pin1 goes low turn off marker lights
	end if
	

	



	if pin3 = 1 and pin2 = 1 then flashhazard

	if pin3 = 1 then flashleft

	if pin2 = 1 then flashright

	if pin3 = 0 and pin2 = 0 then main



goto main

flashleft:

	high portc 6		     'turn v.regs on for left side  

	high 0			     'first bank of LEDs high
	  pause b0			     'pause for fade in time
	high 1			
	  pause b0
	high 2
	  pause b0
	high 3
	  pause b0
	high 4
	  pause b0
	high 5
	  pause b0
	high 6
	  pause b0
	high 7
	  pause b1			     'keep last bank high for fade out time
	  pause b1
	
	low 7				     'last bank to turn on now goes off
	  pause b1			     'pause for fade out time
	low 6
	  pause b1
	low 5
	  pause b1
	low 4
	  pause b1
	low 3
	  pause b1
	low 2
	  pause b1
	low 1
	  pause b1
	low 0
	  pause b1

	low portc 6			     'turn left side regs off

	goto main

flashright:

	high portc 5		     'turn v.regs on for right side  

	high 0			     'first bank of LEDs high
	  pause b0			     'pause for fade in time
	high 1			
	  pause b0
	high 2
	  pause b0
	high 3
	  pause b0
	high 4
	  pause b0
	high 5
	  pause b0
	high 6
	  pause b0
	high 7
	  pause b1			     'keep last bank high for fade out time
	  pause b1
	
	low 7				     'last bank to turn on now goes off
	  pause b1			     'pause for fade out time
	low 6
	  pause b1
	low 5
	  pause b1
	low 4
	  pause b1
	low 3
	  pause b1
	low 2
	  pause b1
	low 1
	  pause b1
	low 0
	  pause b1

	low portc 5			     'turn right side regs off

	goto main

flashhazard:

	high portc 6		     'turn v.regs on for left side
	high portc 5		     'turn v.regs on for right side  

	high 0			     'first bank of LEDs high
	  pause b0			     'pause for fade in time
	high 1			
	  pause b0
	high 2
	  pause b0
	high 3
	  pause b0
	high 4
	  pause b0
	high 5
	  pause b0
	high 6
	  pause b0
	high 7
	  pause b1			     'keep last bank high for fade out time
	  pause b1
	
	low 7				     'last bank to turn on now goes off
	  pause b1			     'pause for fade out time
	low 6
	  pause b1
	low 5
	  pause b1
	low 4
	  pause b1
	low 3
	  pause b1
	low 2
	  pause b1
	low 1
	  pause b1
	low 0
	  pause b1

	low portc 6			     'turn left side regs off
	low portc 5			     'tuen right side regs off

	goto main
I put a 0.1uF on each pot, no noticeable effect.
 

lbenson

Senior Member
>if b2 < b6-1 or counter <= COUNT_NEEDED then

Can't do maths within conditional statements. Use

if b2 <= b6 or counter <= COUNT_NEEDED then
 

Shafto

Senior Member
Hmm..

That doesn't seem to work, the adjustment now still flickers and does not adjust in a linear way at all.. totally odd behaviour.

I tried to adapt the code you also supplied evanh, but I can't get it to take either.. the first line won't go:

if mSP_falling = TRUE then markers_dimming

.. if I replace TRUE with 1 (same kind of thing right?) it works.. but then i get a syntax on this line too...

if mSP - b2 <= 1 then return

for the same math in a conditional statement kind of thing.. that really seems like a big limit on what you can do?




hmm.. still stuck, I remember your solution KIWI didn't allow for a lot of adjustment, but it appears you've changed it now.. and are using a scratch pad value instead of a normal variable.. how come? ...I will try to use that again now and work my on off switch into the equation as well...
 
Last edited:

BCJKiwi

Senior Member
Hi Shafto,
Conditional statement issues
To work around the conditional statement issue you just need one more step like;
b0 = mSP - b2
if b0 <= 1 then return

PWMDUTY
Yes I did some more work refining that code.
The use of the scatch pad is simply to avoid the risk of overwriting the variable somewhere else on the program. For this routine to work you have to save the last value used while you go off and do all the other things in the program so when you come back next time around you have the value to compare.

There are only so many byte and word variables and the tendency is to re-use the same ones in different parts of the program so if you are not careful, one part of the program can overwrite a variable you want to use later.

So if you map out the range of scatch pad memory and store values you need to use later in specific addresses, then you can pick them up from there later knowing they won't be tampered with. This makes it much easier to keep using the same regular variables any where you like without concern (if you don't need them later).
 
Last edited:

Shafto

Senior Member
Well it appears I may have wrecked everything... somehow I ruined the 5v reg so it was putting out -1.6v and now my new 40x1 seems to be ruined aswell.. I can't download to it and it won't reset...

I think I may be ditching this project.. in it's current form anyway, so much money and time wasted.. my nerves can't take any more of this.

Having adjustable PWM is just too much of a pain on these picaxes.. I don't know why it needs to be, but it is.. there should be some pseudo hysteresis command or something.. I dunno.. I think I'll just use some 555 based PWMs.. They don't flicker.

Edit: Good news.. I took the 5v reg out of the breadboard and tested it, it's fine.. the picaxe is also fine as well I hope... for some reason now I have 7.5ohms between ground and +v.. trying to figure out why.. wonder what I fried.

more edit: bad news.. disconnecting the picaxe gets rid of the problem... hmm. I probably shorted something on the everlasting breadboarded circuit, 2 months or so now? ...in varying forms. Wish I could get it figured out and on a PCB so I could stop doing that.
 
Last edited:

kevrus

New Member
Shafto, i've been following this thread with interest and I for one hope you don't ditch this project as you have come so far. I would love to see a video on 'you tube' or somewhere of the lights in action on your car.
Just think of the satisfaction when you finish it!!
 

Shafto

Senior Member
No.. I wouldn't ditch it completely.. just maybe trying to use the PWM from the picaxe... I've made adjustable PWM controllers for LEDs before with a 555 and there aren't any flickering issues to try and deal with.. It's been an ongoing frustration with the picaxe.

I changed the design slightly.. I don't need to switch the markers on or off with code any more.. so that's out of the equation.. that switching will just be done outside the picaxe and the MarkerPWM can run all the time in the background.. that should simplify the coding slightly.. I'll clean up the breadboard here and then just put the 28X back in with a very simple layout to fuss around with the flickering issue.. I'll make another attempt on it before I just go to the 555 option.

I'm also working on the PCB design right now.. so after I figure out whether I'll go the 555 route or not I'll have the PCB pretty much ready so I can solder everything on.. I shouldn't have cheaped out on the breadboards I suppose.. things always seem to be popping loose and shorting onto something... the partial death of my 28X (one PWM channel gone) and now the total death of my 40X can both be attributed to such instances... So I'll keep it simple on the breadboard. Now I know everything works except for the flicker issue.. and I"ll just focus on that for a while.. without a huge nest of wires waiting to go wrong.

Something I just thought of while designing the PCB.. I should probably put a 0.1uF on each opto? to stop random triggers from noise? ..what about on transistor inputs? should I put a cap on those to?
 
Last edited:
Top