08 interchangable with 08m

bluejets

Senior Member
I have small program that was written for an 08 chip but it doesn't seem to want to work the same in an 08m.
Hardware still uses the same input and out put pins.
Are there differences apart from the memory size..??
 

bluejets

Senior Member
The code came from Silicon Chip web site so is it ok to display here..??
It is freely accessable but I thought I should ask.

Also, I am having a problem with debug.
I put it in a program such like debug,b0 and when run, the debug screen comes up "waiting" with no info.
 

manuka

Senior Member
Although handy,DEBUG slows down the program operation considerably & is considered inferior to SERTXD. Suggest you also show your layout circuitry or supply a digital photo. Stan.
 

hippy

Ex-Staff (retired)
The code came from Silicon Chip web site so is it ok to display here..??
It is freely accessable but I thought I should ask.
Hard to say. Perhaps post a link to the code or the page where the code can be obtained from.

Also, I am having a problem with debug.
I put it in a program such like debug,b0 and when run, the debug screen comes up "waiting" with no info.
It should work but if the DEBUG isn't being executed nothing will display. If different code to the above post it and we can have a look at it.
 

manuka

Senior Member
Code:
 ' Simple Diesel engine sound 
' G. Hunter, Feb 05

' * 6 different steps of rate of sound between stopped and max speed.
' * Constant "fast idle" when decelerating until speed falls below '60' or 40% of max.
' * Double Horn blast on starting.
' * Random single horn when running - every 2 mins at max speed, longer times at slower speeds.
' * Brake exhaust sound on stopping.

' Analogue input voltage is on pin1 - arrange resistor divider to give 3.3V at max speed (3.3V = 160).

' Uses 5-stage shift register with bits 4 & 5 XORd and fed back to input bit.

' pin1 (adc1) is speed volts input
' pin2 (out2) is amplifier output.

' b0 is the shift register
' b2 is ADC voltage representing speed
' b3 is timer to determine rate of sound (pause).
' b4 is intermediate value for speed/10 
' w4 (b8 & b9) is random number used to sound horn 'randomly'

symbol seed = b0
symbol speed = b2
symbol oldspeed = b5				'last speed reading, used to determine if changing
symbol decel = b7					'1 = speed is falling, 0 = accelerating or constant


	seed=56 					'initialize - can be any number except 0 and 255
							'53 is slow, 36 is fast, 56 is pulsy fast
							'4,9 are fast, 5 is pulsy

start:
	seed = seed * 2				'shift left 1 bit. R/H bit 0 is set to zero automatically
	if bit4 <> bit5 then xored		'do an XOR on bits 4 & 5 of seed (b0)
	low 2						'speaker output
	bit0 = 1					'feedback to R/H bit
	goto motspeed

xored:
	high 2					'speaker output

motspeed:
	random w4					'for horn
	readadc 1,speed				'read speed into b2 - 15 steps of 'speed'
	if oldspeed = 0 and speed > 0 then Horn2

horn0:
	if w4 > 65500 and speed > 11 then horn1 '65500 works every 2mins or so at max speed
							 'sometimes get 2 or 3 blasts together - just depends 
							 'on random number generator.
	if oldspeed > speed then slowing
	if oldspeed = speed and decel = 1 then slowing

' So must be accelerating or at steady speed but was last accelerating
	
accel:
	decel = 0

loop:
	oldspeed = speed
	b4=speed + 30/31				'integer result converts 16 steps of speed to 6
	
table:						'determine the 'clocking rate'
	lookup b4,(18,10,7,4,2,1,0),b3  	'idle + 6 steps of speed
							'only enough memory for 6 steps in lookup table
paus:
	pause b3				
	goto start

horn2:
	sound 2,(57,50)				'starting double horn blast
	pause 200

horn1:
	sound 2,(57,150)
	oldspeed = speed
	goto loop


slowing:  
	decel = 1
	if speed = 0 and oldspeed > 10 then juststopped
	if speed < 60 then loop
	b3 = 8		     			'decelerating at higher speeds gives constant 'fast idle'
	oldspeed = speed
	goto paus

juststopped:
	pause 500
	sound 2,(253,200)				'exhaust brakes sound - try 249 for a quieter hiss
	goto loop
 
Last edited:

hippy

Ex-Staff (retired)
As best I can see the main difference which affects moving the code from 08 to 08M is that the 08M has a 256-step resolution on ADC while the 08 has only 16-step, and is capped at the top end. There will also be slight differences in speed which also seem to slightly affect things when I tested it on both 08 and 08M.

In general it seemed to work on 08M as it does on 08, but didn't always seem to give the exhaust brake sound. My guess is that's likely to do with the ADC resolution. If so the solution would be to add code which converts the 256 step ADC to a 16 step ADC as the 08 has. I might have some code which does that; I'll take a look.
 

bluejets

Senior Member
mmm...Thanks Hippy,
When I ran it in the 08M, it would give irratic rev sounds for a certain input(revs would go up and down) whereas the 08 was fairly stable. Maybe I had other problems there.

There are parts of the program that are obvious as to how they work but the one section that I do not understand is the xor and the lookup. Could you point me in the right direction to a tutorial section where I might find out more about this also.
I could just leave it as it is I guess and tag another chip alongside it as I wanted to add some extra code and it is full (126bytes)
Then again, 08 is not around anymore and only have 1 or 2 left myself.
 

hippy

Ex-Staff (retired)
I also had slight differences in rev sounds but never investigated. I suspect it's all down to difference in ADC.

The XOR seems to be part of a pseudo-random pulse chain generator, the LOOKUP function I'm not entirely sure about but also seems to relates to ADC given the comment in source code.

This is one of those cases where program portability isn't as easy as it sometimes is as it relies on specific features and timing of the 08. The two options are convert the ADC as already suggested, or reverse engineer, work out exactly what it does then reimplement for the 08M.

Both should be possible, the first easier than the second, but both will take a little time to investigate, solve then tweak. Use an 08 for now, plan for an 08M drop-in replacement.
 

bluejets

Senior Member
OK....thanks for your effort....much appreciated

The main generator seems quite tricky for such a small amount of code. I will investigate further......Thanks again
 
Top