PICAXE capable of capturing enough information for a dashboard?

cloudy

Member
Have used smaller picaxes for lots of small projects - but wanted to see if it could do a larger project I've got

Requirement


Reading at least 20hz

5 digital inputs
11 analog inputs
2 frequency inputs (between 30-300Hz)
1 i2c device (maybe more than this but not at 20Hz)
input serial commands for pwmout below

Output
regular serial string of the above data probably at 115200bps
2x independent PWM servo outputs


I was hoping a 28X2 could achieve this - any thoughts as to whether it's up to it?
 

lbenson

Senior Member
Looks to me like you're short three I/Os with a 28X2. A 40X2 should handle the I/Os, but cycling 20 times per second could be a problem--how do you propose to read your frequencies?
Code:
28X2

i2c: C.3,C.4
hserin: C.7
11xADC: A.0-A.3, B.0,B.2-B.5,C.5,C.6
digital in: C.0,C.1,B.6,B.7,[?]
freq: [?,?]
serout: A.4 (max 76800 @ 64mHz)
2xpwm: C.2,B.1
If you use a 40X2, you could get 115200 serial output using the hserout pin.

But ... the safety question: dashboard for what?
 
Last edited:

cloudy

Member
Realised I was short on the 28 - 40 does seem to cover
It's a square wave frequency @ 50% input, so was hoping to do a pulsin to measure pulse length - and therefore the frequency
I presume the pulsin command blocks until the pulse is read? (until timeout of 0.16384s timeout @ 16mhz) which should still capture the lowest freq which has a pulse length of 0.016 seconds) Failing that I could do a count, but not sure how accurate that would be with a short time domain and low frequency

Automotive application btw
 

hippy

Ex-Staff (retired)
I think erco might be on the right track. It may not be easy to handle everything together on a single PICAXE no matter how fast it runs. It really depends on what you are monitoring / recording, what data you need to accumulate and in what time frame.

It would be fairly easy to have a multi-drop serial line so all PICAXE chips can report out on that one line as if the data were coming from a single chip.
 

cloudy

Member
Most of it is written and working great on a 40X2, digital inputs/analog, reads an i2c input, then spitting that out at 30hz on the hserout -The tricky part is sensing the two frequency values, if I do it on the main chip, if no pulses are received (either input could have no pulses) I'm stuck with a 2x timeout delay in the loop which is far too long to keep a 30hz loop.

Other ideas I had for this:
Another 2 X2 picaxes, in i2c slave mode. Though I understand when 'locked' up waiting for pulsin, it probably won't be able to answer i2c requests anyway
2 PICAXE 08 - pulsein then output a constant PWM for the main processor to read quickly. I think the pulsin again causes the PWM output to be disturbed...
2 PICAXE 08 - serial network, complex and not sure how the tight loop on the hardware serial can be trying to do "software" serin - the pulsin on the slave device might hang this all up anyway
1 PICAXE 08 - constantly spit out the value over serial after each pulsin, rely on hserin background receive on the 40x2 to buffer the values
Some sort of frequency measuring i2c IC - This would be ideal, but cannot seem to see anything to do the job...
EDIT: Just found this: http://www.sensorsportal.com/DOWNLOADS/UFDC_1.pdf
Not sure if it's a commonly available part though


Getting the value on the i2c bus would seem the neatest approach, anyone have any cunning ideas?
 
Last edited:

Jeremy Harris

Senior Member
I've used multiple 08M Picaxes to do front end stuff and spit data out via serial links to another Picaxe doing the display and storage stuff. It works well with hardware serial inputs and if you do some basic signal processing and number crunching at each 08M (08M2 now) then it can reduce the load in the main program loop on the master.

You can, I believe, implement a multidrop serial network that can reduce the load still further. One easy way would be daisy chain the 08M2s doing the front end stuff, so each receives serial data from the one in front and appends its own data to it. This daisy chain approach won't work for frequency measurement, because of the blocking problem, but it may well take the load off the master Picaxe for some of the other stuff, and therefore speed things up.

Peter Perkins did a very clever battery management system using dozens of daisy chained 08's (may have been 08M's) some years ago, all feeding data via a single serial connection to a master Picaxe controlling a display etc. There's a thread here on it somewhere.
 

cloudy

Member
If anyone is interested in the solution - I used 2 PICAXE 08M2s (one for each channel) measuring with pulsin, scaling to 10-90% duty on the PWM out, and sending that continuously at 1000Hz for the main 40X2 to read using pulsin "instantly". This gives me about 800 unique values so there is some aliasing but the prescaling means the accuracy is even across the output range. When input pulsin times out, 95% duty is sent and the 40X2 understands thats as a zero value.
Cheap and neat :)
 

lbenson

Senior Member
Thanks for reporting your solution to a tricky problem. Sometimes we don't hear back and don't know which if any of the suggestions offered worked.

Your 08M2 code looks like it would be very brief--can you post it?
 

cloudy

Member
It's dirty proof of concept code, but might help point someone in the right direction

Code:
'Measure pulse, and make PWMOUT follow
#Picaxe 08M2
'Input range 8hz (pulsin 25000) > 500hz (pulsin 400)
'Output pulse can range from 20 >  833us  (900us engine stopped)

symbol PWMOUTPUT = C.2
symbol FREQSENS = C.1 
symbol FREQ_STATE = w0   'Raw Pulse length read
symbol FREQ_SCALED = w1  'Eventually becomes RPM
symbol PWMCALC = w2	 'Scaled Output PWM pulse length


setfreq m16 '16mhz gives best timeout for pulsin

init:	pwmout PWMDIV16,PWMOUTPUT,250,900	; start pwm with engine stopped signal

main:	

pulsin FREQSENS,1,FREQ_STATE 'higher value = lower rpm - except 0 which = stopped

'Sample Data
'min 1us   500rpm (8.3hz) =   23950
'middle  425us  9750rpm (162.5Hz) =  1230
'max 850us  20,000rpm (333hz) = 600

'Convert pulse length to pulses per second
'1 second = 200,000 pulsin units @16mhz so div by 4 to fit 50,000 



if FREQ_STATE = 0 then 'timeout - engine is stopped
	FREQ_SCALED = 900 'dont calc rpm just give longest duty 
else
	if FREQ_STATE < 750 then 'RPM is over 16,000
		FREQ_SCALED = 16000
		else
		
    ' Get RPM
	FREQ_STATE = FREQ_STATE/4 'scale for next calc to fit in memory
	FREQ_SCALED = 50000/FREQ_STATE ' = RPS
	FREQ_SCALED = FREQ_SCALED * 60 ' = RPM
	end if
	
	'Linear Scale RPM >  'Output pulse 20 (500rpm) >  833us (16000rpm)  (900us engine stopped
	'divide by 18
	PWMCALC =  FREQ_SCALED / 19

end if


pwmduty C.2,PWMCALC	; set pwm duty    on time is effectively microseconds


goto main		; loop back to start
 
Top