AXE033 Pulse Out

Xarren

Member
Heyah,
Im having a slight problem, with the pulse out on the axe033 clock. I have only just realised its a 50/50 mark to space ratio, meaning a 500ms high 500ms low output, and im using an interrupt to increment a time counter up each second.

I was at first hoping that this would mean the interrupt would fire once a second, yet after breadboarding my model tends to increment the timer by 5 or so each time pulse out goes high. To avoid that I have tried putting a 500ms pause in the interrupt, and that works fine, the timer increments by 1 each second, however the rest of my code is unable to run with a pause that big in my interrupt. A solution I have come up with is to connect the pulse out to a picaxe 08M, have the interrupt run on that, with that 500ms delay, and feed a much shorter pulse out to the main picaxe (18x). I would however like to avoid that, as using another picaxe just for such a simple thing seems ridiculous.

Is there an easy way to solve this, hopefully not using any extra chips?

My current code (Well this is an older version, I have the newer one at school, but none of the changes affect anything to do with the interrupt):

Code:
#picaxe 18X
symbol write.debounce=1000					'Debounce when writing to EEPROM
symbol switch.debounce=100					'Debounce when accepting input from a switch
symbol display.debounce=10					'Debounce when communicating with AXE033


init.LCD:								'Save prewritten messages on AXE033 EEPROM

	pause 500
	
	serout 1,N2400,(253,3,"Enter Password: ")
	pause write.debounce
	
	serout 1,N2400,(253,1,"T  C LL         ")
	pause write.debounce
	
	serout 1,N2400,(253,2,"Timer=   s      ")
	pause write.debounce
	
	serout 1,N2400,(253,4,"   INCORRECT    ")
	pause write.debounce
	
	serout 1,N2400,(253,5,"    PASSWORD    ")
	pause write.debounce
	
	serout 1,N2400,(254,1)
	pause display.debounce

security:								

	b0=0								'Initialize variables
	b1=0
	b2=0
	b3=197
	b4=0
	
	serout 1,N2400,(253,3)					'Display "Enter Password: " on the LCD
	pause display.debounce
	
	for b2=1 to 4						'Initialize the password entry loop
	
security.underscore:

	b3=b3+1
	serout 1,N2400,(254,b3,"_")				'Display an entry prompt "_" accounting for LCD cursor position
	b3=b3-1
	bit5=0							'Reset bit5 (bit 5 adjusts "_" position)
	
security.entry:							'Entry of password

		do
									
			if input6=1 then				'If backspace pressed delete last character
				gosub security.back
			endif
			
			readadc 2,b1				'Check password input switches
			
		loop while b1<20					'Loop until there is an input

security.selectcase:

	select case b2						'Compares input against the correct input, bit marked if input is correct
	
		case 1
		
			if b1>60 AND b1<80 then 		'Range provided for relability
				bit0=1
			endif
			
		case 2
		
			if b1>80 AND b1<100 then
				bit1=1
			endif
			
		case 3
		
			if b1>100 AND b1<120 then
				bit2=1
			endif
			
		case 4
		
			if b1>120 AND b1<140 then
				bit3=1
			endif
			
	endselect

	pause switch.debounce
	b3=b3+1							'Move the cursor forward by one
	serout 1,N2400,(254,b3,"X")				'Display "X" at current cursor position to mark entered character
	pause display.debounce
	
	next b2							'End password entry process
	
	do								'Loop waiting for password confirmation using enter
	
		if input6=1 then					'If backspace is pressed mark bit5 to adjust cursor position
			bit5=1					'and go back to the password entry phase, from which the user
			goto security.entry			'will go straight to the backspace function, as backspace is
		endif							'still down
		
	loop while input7=0					'Exit loop when enter is pressed, confirming the password to be checked
	
	if b0=%00001111 then 					'Check password against a constant, if all 4 bits were marked password is correct			
					
		setint %00000010,%00000010
		
		serout 1,N2400,(254,1)				'Clear the LCD of old now irrelevant text
		pause display.debounce
		
		serout 1,N2400,(253,1)				'Display "T  C LL         " on line one of the LCD 
		pause display.debounce
		
		serout 1,N2400,(253,2)				'Display "Timer=   s      " on line two of the LCD 
		pause display.debounce
		
		goto main
	else								'If password is incorrect
		high 0						'turn on a red LED
		serout 1,N2400,(253,4)				'and display "   INCORRECT    " on line one of the LCD
		pause display.debounce
		serout 1,N2400,(253,5)				'with "    PASSWORD    " on the second line of the LCD
		wait 5						'Display this message and keep the red LED on for 5 sec
		serout 1,N2400,(254,1)				'After 5 sec clear the LCD
		low 0							'and turn the red LED off
		goto security					'Reset the character entry process
	endif
	
security.back:							'The backspace password entry character deletion function

	if b2>=2 then						'If we are not already at position 1 of the LCD 
		pause switch.debounce
		serout 1,N2400,(254,b3,"    ")		'Delete everything after the cursor
		b3=b3-1						'Move cursor and password entry variables back to accustom
		b2=b2-1						'for the character deletion
	else
		return
	endif
	
	if bit5=1 then
		goto security.underscore
	else
		b3=b3+1
		serout 1,N2400,(254,b3,"_")
		b3=b3-1
		goto security.entry
	endif
	
main:

	if pin2=1 then
		w6=0
	endif
	
	readtemp 1,b1
	
	if b1<10 then
		serout 1,N2400,(254,131,"00",#b1)
	else if b1<100 then
		serout 1,N2400,(254,131,"0",#b1)
	else
		serout 1,N2400,(254,131,#b1)
	endif
		
	pause display.debounce
	
	readadc 1,b2 
	b2=b2*100/255
	
		if b2<10 then
	serout 1,N2400,(254,137,"00",#b2)
	else if b2<100 then
		serout 1,N2400,(254,137,"0",#b2)
	else
		serout 1,N2400,(254,137,#b2)
	endif
	
	pause display.debounce
	goto main

interrupt:

	inc w6
	
	if w6<10 then
		serout 1,N2400,(254,198,"00",#w6)
	else if w6<100 then
		serout 1,N2400,(254,198,"0",#w6)
	else
		serout 1,N2400,(254,198,#w6)
	endif
	
	pause display.debounce
	setint %00000010,%00000010
	return
Cheers in advance... :) x
 

hippy

Ex-Staff (retired)
Best solution is to interrupt on both high and low going edges ...

Code:
SetInt %00000010,%00000010     ' Interrupt on pin 1 high
Do
  '
  ' Your code
  '
Loop

Interrupt:
  If pin1 = 1 Then
    '
    ' Update time etc
    ' 
    SetInt %00000000,%00000010 ' Interrupt on pin 1 low
  Else
    SetInt %00000010,%00000010 ' Interrupt on pin 1 high
  End If
  Return
I can see a problem though ...

You use READTEMP which takes around 750ms, so you may miss interrupts.
 
Last edited:

Andrew Cowan

Senior Member
Overclocking does not reduce the readtemp time - there is no way to reduce it.

In my robot I use an 08M with 3 DS18B20s - they then send the data to the serial in port of the main processor.

As I use the serial in pin, no additional pins are needed. The 08M sends data as often as it can, and the serial in pin uses the serrx command with a short timeout. About 1 in five reads from the 08M are sucessful - the other four timeout as the 08M is busy and not sending data.

The alternative is using my idea of a calibrated pause - one of my timing projects uses this and has a 1 second in 1 hour accuracy.

A
 

fernando_g

Senior Member
This problem is similar to one encountered on a 555 used in monostable mode; if the triggering pulse is excessively long, it will not allow the IC to complete the timeout.

The solution has been to use a differentiator circuit, whereas you couple the output from the AXE033 to the 18X via a 0.1uf capacitor in series and a 10k to ground. If you use a Schmit Trigger input on the 18X (either In6 or 7), you get an aprox 1 millisecond positive pulse which will trigger your interrupt nicely.
Some would also recommend adding a diode in parallel with the resistor -preferably a schottky- to clamp the negative spike and prevent overstrstessing the Picaxe input.
 

Xarren

Member
Cheers guys,
Im going to try breadboarding fernando's idea tomorow :).
And 750ms for a readtemp? Didnt realise that... In that case I might indeed put that on an extra 08m.

Sorry but which way does the diode has to go on? *turns slightly red*
 

inglewoodpete

Senior Member
If you're thinking of reading a DS18B20 every second and getting useful data, think again. The device is in a plastic package with a temperature coefficient of ?? (Ie slow)

One read every 10 seconds will be more than often enough.

So reenable your interrupts in the main loop after the input state restores.
 

Andrew Cowan

Senior Member
That is one techninque you can use to improve the chance of a sucessful read if sending the data from an 08M. On the 08M, read the DS18B20 then send the data for two seconds. Repeat.

A
 

Andrew Cowan

Senior Member
Code:
For b1 = 1 to 100
serout 5,N2400,(51,#b1)
next b1
I don't know how long that would take.

The 51 is a qualifier so the receiving PICAXE knows when the beginning is.

A
 

Xarren

Member
My teacher didnt have any of them diodes mentioned in stock, so instead i got a speed diode, is that going to be fine instead? Wouldnt want to damage the picaxe :) x
 

Andrew Cowan

Senior Member
Schottky diodes have a very low forward voltage - I assume you have a 1N4148?

The voltage of that is about 0.7V - not really low enough.

You're trying to clamp the negative spike - -0.3V is the highest a PICAXE can take. You want a diode with a Vf as low as that. I'll see if I have one I can give to you.

A
 
Last edited:
Top