PWMOUT not steady

Kecked

Member
As some of you have read I am making an analog meter clock. I finally got the clock running and the pwmout /pwm duty working and the seconds meter reads as it should but it jumps at points. Any idea why every 10 seconds or so it jumps a little? fir example it ticks as it should up to 9 then jumps to 13 and continues on to 20 or so and jumps again to 23 or so then at 30 jumps alittle agin or 40 it jumps then at 50 or so. I tried differnt meters and the jump is real. The pwm cycle and duty do not reset I checked that. I even made it only count to 50% duty during the period thinking that might be it. I also rem'd all the clock functions except the pwm functions and still the same. I changed osc speeds, etc....always the same. Even tried a cap to smooth the output. Now what I did not do is use an opamp as a buffer. Could I be loading the micro pin? The meter reads 0-20ma so I doubt that and it is 33 ohms coil with a 220 ohm in series to make sure I can't go beyond 20ma.

Ok enough babble ideas?

Code:
#picaxe 28x2

' Converted by X2 Conversion Wizard Version 2.0.5 (2010r4.1)

let dirsB = %11111111
let adcsetup = 0

'ANALOG CLOCK WITH LCD September 23, 2012
'Marc Rubin

'Set Clock

let dirsB = %11111111
let adcsetup = 0
setfreq m4
Pause 250

	Symbol seconds 	= b0
	Symbol mins 	= b1
	Symbol hour 	= b2
	Symbol day 		= b3
	Symbol date 	= b4
	Symbol month 	= b5
	Symbol year 	= b6
	Symbol control 	= b7
#rem
      Let day     	= $01
	Let year    	= $12	
	Let month   	= $09	
	Let date    	= $30	
	Let hour    	= $21	
	Let mins    	= $02	
	Let seconds 	= $30	
 	Let control 	= %00010000 ; Enable output at 1Hz


'Write to Clock on I2C Bus

  hi2csetup i2cmaster, %11010000, i2cslow_32,i2cbyte
  writei2c 0, (seconds, mins, hour, day, date, month, year, control)
#endrem

'Meters pwm setup
	PWMout c.1,99,0 
	PWMout c.2,99,0
	PWMout b.5, 99,0
Main:

'Readout Clock on I2C Bus

		i2cslave %11010000, i2cslow_8, i2cbyte
		readi2c 0, (seconds, mins, hour, day, date, month, year, control)
	


'BCD to ASCII Conversion

			BCDTOASCII hour,		b8,b9
 			BCDTOASCII mins,		b10,b11
 			BCDTOASCII seconds,	b12,b13
 			BCDTOASCII month, 	b14,b15
 			BCDTOASCII date, 		b16,b17
 			BCDTOASCII year, 		b18,b19

'Determine day of week

	IF DAY=1 THEN LET B20="S":LET B21="U":LET B22="N"
	ENDIF
 	IF DAY=2 THEN LET B20="M":LET B21="O":LET B22="N"
	ENDIF
	IF DAY=3 THEN LET B20="T":LET B21="U":LET B22="E"
	ENDIF
	IF DAY=4 THEN LET B20="W":LET B21="E":LET B22="N"
	ENDIF
	IF DAY=5 THEN LET B20="T":LET B21="H":LET B22="U"
	ENDIF
	IF DAY=6 THEN LET B20="F":LET B21="R":LET B22="I"
	ENDIF
	IF DAY=7 THEN LET B20="S":LET B21="A":LET B22="T"
	ENDIF

'Send to LCD
			i2cslave $C6,i2cslow_8,i2cbyte
			pause 10
			hi2cout 0,($FE,$80,$20,$20,$20,$20,b8,b9,":",b10,b11,":",b12,b13,255)
			pause 10
			hi2cout 0,($FE,$C0,b20,b21,b22,":",B14,B15,"/",B16,B17,"/",B18,B19,255)
			pause 10
			
'meters
		w20=seconds*3
		w21=mins*3
		w22=hour*8
		pwmduty c.1, w20
		pwmduty c.2, w21
		pwmduty b.0, w22

goto main
 

erco

Senior Member
Neat project! Accuracy aside, something's going on in the background periodically. For starters, try adding a DISCONNECT at the start of your program to eliminate that possible interference.
 

Goeytex

Senior Member
Assuming there is no hardware issue ...... My guess it that is it a conflict between PWM and I2C.

See Manual 2 Appendix 4. While not exhaustive, it gives a fair idea of possible conflicts.

You may want to post your schematic so that folks can possibly see if there is anything there
that could causing this. With no schematic we can only guess.
 

Kecked

Member
reply

The schematic is soo simple I can just describe it. 28x2 with Axe033/ds1307 on I2C bus, three pwm outs with resistors and pots between the pwm pin and the meters. Other side of meter goes to ground and last the standard programming resistors.

Its on a breadboard run off a regulated 5v supply. Got the obligatory 0.1uf decouplers in place. The only thing I have not tried yet is to write a simple pwm for next loop that just counts like the pwm duty cycle from the time with nothing else running.
The other thing I was thinking was that maybe it could ge the interrupt flag overflowing? I read somewhere on the x2 devices that this sets a flag. Whatever it is is really consistant so it has to be something non random. Its not like a glitch or such. i also tried pwm periods from 100hz to 100khz and it is the same each time. The other thing I might try is to remove the ds1307 from the lcd since I don't need an lcd except for debug and calibrating the meters. Only I am not sure how to remove it from the axe033 and retain the programming. Guess I could use the lcd in serial mode then and see if it works.

Always something but I am learning and that is what counts.

ERCO I did try the disconnect command and now I learned what a "HARD RESET" is for :) Didn't make a difference.
 

Goeytex

Senior Member
Word descriptions of a circuit almost never tell the whole story. That's whey we ask for schematics and photos. Having others review schematics and see actual circuits many times leads to a speedy solution. Instead days or weeks to a resolution or even abandonment of a project, many times a problem can be found in a few hours. But If you don't want to draw and post a schematic that's your choice.

Do you have a scope ?
 

Kecked

Member
I'll draw something and upload it. Yes I have a scope and there is a definite jump in the pwm duty cycle so it is real. i also see the same jumps on the VSM simulation so it has to be a system designed issue. I must be doing something or not doing something that causes the issue. I'm looking at interupts to see if some kind of overflow tag might be the problem.
 

Technical

Technical Support
Staff member
why the setfreq m4 command, which in turn then does not match the i2c i2cslow_8 setting?
And remember the duty must never be above 4x period, you don't have any checks for 99x4 overflow?
And you are multiplying a bcd value (e.g. hour) x 8 - shouldn't you convert the value to a normal integer first? Multiplying a BCD value will give strange results, e.g. when you get to 10 what you expect to be 10x8 will actually be 16x8 ($10 x 8)

 
Last edited:

Kecked

Member
I got it!!!!!!!!!

let w20= bcdtobin seconds
pwmduty c.1, w20
let w21= bcdtobin mins
pwmduty c.2, w21
let w22= bcdtobin hour
pwmduty b.0, w22

I hope I don't make that mistake again. I got to read up on this math.
 
Last edited:
Top