1Hz oscilator

edmunds

Senior Member
#1
Hi all,

How would you go about generating approx 1Hz signal with minimum number of external (to picaxe) components? I understand, I can use RTC for this - there are many with configurable freq outputs and integrated 32....kHz crystals these days. However, since I do not have backup power, I don't have any good use for the rest of the RTC functionality and tiny (the only suitable) versions are not very cheap.

Intuitively a picaxe comparator with resistor+capacitor could be one thinking direction, but I must confess my analog electronics design skills are not much ;).

Thank you for your time,

Edmunds
 

Pongo

Senior Member
#3
Buy a cheap quartz clock movement with a second hand off ebay, you'll get the crystal and chip that generates 1 second pulses.
 

premelec

Senior Member
#4
Agreed with Pongo - note that the pulse that usually goes to the coil that moves then hand can be put into a single transistor to raise the voltage to 5 volt output pulse and that the clock units can be operated on 5 volts with a resistor in series and capacitor in parallel with the clock unit - also a single AA battery will last over a year in my experience.
 

premelec

Senior Member
#6
@hippy - I wonder what sort of stability you'd get with the RC - without special selection of components etc... OP didn't say about accuracy and stability - so don't know what would suit OPs needs. We used to have unijunction transistors and tunnel diodes for simple oscillators... now there are very compact and programmable oscillator ICs... so many choices better than too few ;-0
 
#7
Last year I purchased 5 x DS3231 RTC modules from ebay for NZ$7.25, about the price of 2 loaves of bread.
Accuracy exceeds DS1307 modules and is easy to read. At $1.45 each that price makes them cheaper than 555 maybe.
 

edmunds

Senior Member
#8
Thanks for all the replies! My favourite is, of course, cutting off what you don't need of an IC. However, that would not be very production or 'assembly in China' friendly :).

The accuracy need is very mild. The totality of the problem is I have blinkers (as in 'turn indicators' and LED, 5mA max) in at least three places of a model vehicle - front, back and back of the trailer on each side. My failed design was to use I2C driven LED drivers (PCA9555) with built in oscillators, that would blink the LED on an I2C command. This did work, but the blink rates of LEDs on the same side of the car were never in sync because of a delay issuing IC commands and more importantly - variations of oscillators in LED drivers.

Then, I had a design, where I used a single LED driver and routed blinker wires all across the vehicle. This solves the sync problem, but adds wiring, which has turned out to be as much of a problem as the sync issue.

Now, I want to revert to I2C = two wire communication to my 'remote PCBs' + two power supplies + GND + oscillating power supply for blinkers. Since I'm switching GND with I2C expanders on all LEDs (headlights, running lights, brake lights, rearward lights etc.) a pulsing power supply wire connected to both blinker LEDs would solve my problem and be the least wiring I seem to be able to come up with.

I actually built a 'relaxation oscillator' with picaxe comparator, but this is 5 external components and three picaxe pins. SFRs need to be used to route the output to a pin and switch comparator in high power/high speed mode for better results. Altogether, this 'costs' a lot more than RTC like this one http://www.farnell.com/datasheets/2...601.507578672.1550963020-379686543.1472069759 with 1Hz output.

So, I'll put one on order and keep thinking on how to best design this.

Thank you all for your time,

Edmunds
 

hippy

Technical Support
Staff member
#9
Then, I had a design, where I used a single LED driver and routed blinker wires all across the vehicle. This solves the sync problem, but adds wiring, which has turned out to be as much of a problem as the sync issue.
Each LED will require V+ and 0V. It is not obvious how you will have less wiring using I2C. And it's not clear why you cannot drive all the LED's direct from PICAXE I/O, maybe using a common ground or V+.

If looking to make things 'manufacturing friendly', to reduce assembly or manufacturing costs, then it's hard to see what would be easier than LED's pushed into the appropriate holes, with flying wires which plug directly into a single control board using two-pin connectors.

I think you might have to explain exactly why KISS wouldn't work, and why a more complicated, more expensive, more involved to assemble, solution is better.
 

edmunds

Senior Member
#10
Hippy,

Thanks for your interest.

There are 10 LEDs on the rear PCB, 10 LEDs on a trailer PCB and 6 to 10 LEDs on the front PCB (there is also a TOF I2C distance sensor ir IR receiver in front to name the most important items). While some of the LEDs come in pairs, this is still many wires between PCBs. Connectors and wires are expensive for both, DIY and production assembly at the size I'm working with.

On top of that, blinking part is a problem from workload perspective. There are ways of carefully programming blinking 'into' many other things picaxe is doing for the vehicle, but I would much prefer to 'give it away' and just issue a command to start or stop blinking and do stuff like reading line magnets, distance to the front vehicle, wireless charging coil voltage, processing IR and Bluetooth commands.

Below are some pictures of a 3D rendering of a dated version of structural and electronics parts of the vehicle. There are newer PCBs now and chassis design has been improved, but this should give an idea. The yellow piece contains the front steering mechanism and the green thing has rear axle mounted in white bearings. I'm currently working with vehicles 70mm long from bumper to bumper.

If it seems I'm not giving all the information related to the problem, please accept my apology and know that this only happens as I'm trying to save everyones time. Obviously, it does not always work.


Edmunds
 

Attachments

#11
To go with posts #3 and #4, here are circuits I have used from gutted PCBs from 1.5v battery desk and wall clocks. The coil outputs are 2 seconds and 180° out of phase. Some PCBs have pull up outputs and some have pull down. OR'ing the outputs give you pulses at 1 second intervals.

Ken

1 Second Clock.gif
 

hippy

Technical Support
Staff member
#12
Thanks for the details; with so many LED's I will accept something simpler from front to back to trailer, is a good idea.

Though I2C did not work; ignoring the flashing synchronisation, I believe it could. Time delays between turning one LED on and another should be imperceptible.

I would use a two PICAXE solution. The master doing all it has to plus sending out an indication of what LED's should be doing, 'turn left', 'turn right', 'turn off', 'hazards on', 'hazards off', 'brake on', 'brake off', etc.

The second can take that data, handle the 1Hz generation entirely in software, and send out appropriate I2C commands to control the specific LED's.

The advantage of that is you not are tied to 1Hz flashing, hazards can be faster or slower than indicators if that makes things look better, and the same concept and hardware can do other clever stuff like alternating headlights for things like model emergency vehicles if you ever come to make one of those.

Edited: not tied
 
Last edited:

AllyCat

Senior Member
#13
Hi,

"Direction Indicators" (and "Hazards") are normally specified as between 1 Hz and 2 Hz (120 pulses/minute), e.g 1.5 Hz +/- 30%. You can probably make such a Low Frequency "RC" oscillator (ramp/sawtooth) by simply adding a capacitor (some uF) across a "Touch" input pin (to ground). Then create the "square wave" by using a/the internal comparator, or simply any digital input (threshold around 1.4 volts). Various Touch charge/discharge currents can be selected according to the PIC data sheet (perhaps auto-calibrate the frequency with reference to the PICaxe's master/program clock).

Cheers, Alan.
 
#14
If I wanted minimal components and a 1 second oscillator for something such as indicators with only the need for accuracy to be mild, I'd probably do something like this:

Code:
init:
setfreq m64

main:
let w0=w0+1

if w0=3070 and b2=0 then let w0=0 let b2=1 high b.7 endif
if w0=3070 and b2=1 then let w0=0 let b2=0 low b.7 endif

goto main
Just because I currently have one setup on the bench for another reason, I used a 20X2.

So as to offer very close to 1 second, I timed/measured this with a Bitscope BS10U and experimented with the count (3070) to achieve a measurement of 1.000s. In precision terms it is by far NOT perfect, but it is mildly accurate, certainly good enough for indicators and requires ZERO external components from a Picaxe.


Hope this helps.

Regards,
Mort.
 

Attachments

hippy

Technical Support
Staff member
#15
Mort's trick of simply incrementing and noting counts is something I have used.

The best hard-loop generation for accurate timing is probably to use a PAUSEUS command, as that can be tweaked by small increments to compensate for the time of the other commands -
Code:
Do
    PauseUs 981         ; 981 x 10us @ 4MHz = 9810us = 9.81 ms
    Toggle B.7
Loop
That should allow tweaking by +/-10us at 4MHz, +/-625ns at 64MHz.

For accurate shorter times, where altering the actual number in the PAUSEUS command can affect the memory layout and thereby alter the loop timing itself, one trick is to ensure that any such change comes later in the program -
Code:
Init:
  Gosub SetW0
Main:
  Do
      PauseUs w0
      Toggle B.7
  Loop
SetW0:
  w0 = 981
  Return
 

edmunds

Senior Member
#16
Hi,

"Direction Indicators" (and "Hazards") are normally specified as between 1 Hz and 2 Hz (120 pulses/minute), e.g 1.5 Hz +/- 30%. You can probably make such a Low Frequency "RC" oscillator (ramp/sawtooth) by simply adding a capacitor (some uF) across a "Touch" input pin (to ground). Then create the "square wave" by using a/the internal comparator, or simply any digital input (threshold around 1.4 volts). Various Touch charge/discharge currents can be selected according to the PIC data sheet (perhaps auto-calibrate the frequency with reference to the PICaxe's master/program clock).

Cheers, Alan.
Alan, I have not quite figured out if and how I could use this as I would like to get an external pulsed signal and as far as I understand, I can adjust pulse length, but I need an external trigger for every pulse. This also takes at least three picaxe pins and blocks one more (comparator+). Another chapter suggests CTMU module can be used to convert a varying voltage from a sensor into correspondingly varying duty cycle PWM signal, which would be what I'm after in many ways. So don't know yet.

At the same time, what a discovery CTMU module is! I have been thinking about touch pins as something meant for touch pads and thats it. I have been so wrong. Measuring time between external events in ns range, measuring capacity, current, resistance, voltage, stretching signals and what not! Here is a app note for the interested listing 48 possible uses of the module some of them being even eliminating hunger in the World and ending all wars :).

Thank you,

Edmunds
 

edmunds

Senior Member
#17
Thanks for the details; with so many LED's I will accept something simpler from front to back to trailer, is a good idea.

I would use a two PICAXE solution. The master doing all it has to plus sending out an indication of what LED's should be doing, 'turn left', 'turn right', 'turn off', 'hazards on', 'hazards off', 'brake on', 'brake off', etc.
I2C as such did work and reasonably well. I have had issues with a hanging bus on some vehicles, but this could be due to hardware issues and it could also be possible to work around this in software.

I have been running from multi-picaxe solution, because of complexity of maintaining several sets of code. However, I'm running several slots on the main picaxe anyway and adding another one does not seem so bad anymore.

Has anyone tried to pokeSFR pin4 [C.3] into being an output? I don't have any hardware with me here, cannot test myself :).


Thanks,

Edmunds
 

hippy

Technical Support
Staff member
#18
Has anyone tried to pokeSFR pin4 [C.3] into being an output? I don't have any hardware with me here, cannot test myself
Assuming that's on an 08M2, 14M2 etc, is defined as Input Only; that doesn't work because there is no physical output hardware for those pins in the silicon. Any bit setting in the TRISC for physically input only pins just gets ignored.

I believe some people have used the trick of enabling the pull-up on such pins where available and detecting that change with a FET or transistor to create an output.
 

edmunds

Senior Member
#19
Assuming that's on an 08M2, 14M2 etc, is defined as Input Only; that doesn't work because there is no physical output hardware for those pins in the silicon. Any bit setting in the TRISC for physically input only pins just gets ignored.

I believe some people have used the trick of enabling the pull-up on such pins where available and detecting that change with a FET or transistor to create an output.
You are right, sorry, I misread the data sheet.

Thank you,

Edmunds
 

premelec

Senior Member
#20
A CMOS 4060 device has 14-stage binary ripple counter and oscillator - very small parts available - only a few external components will produce 1 Hz square wave or other rectangular wave - they are cheap...
 

hippy

Technical Support
Staff member
#21
A PICAXE can probably do a lot of what a 4060 can do and perhaps more flexibly. One can create as many pulsed outputs with independent frequencies and duties as there are pins, for example -
Code:
Do
  w0 = w0 + 1 // PERIOD
  pinC.0 = w0 / DUTY Max 1
Loop
 

premelec

Senior Member
#22
Hi hippy - of course I'm well familiar with PICAXE's wondrous abilities. I'm thinking [correctly or not] that edmunds wants a bunch of flashers - could use a bunch of SMD 08M for compact flasher function however also 4060 might be sufficient for just turning on and off LEDs flashing... as usual whatever works [and I still have some 08s - no need for hacksaw job...]. I'm thinking of something that would stay at the LED location so only switch a V+ signal would set it going - perhaps reducing wiring but maybe not... I've lost track of the actual configuration, Considering the current automotive bus protocols i suppose there are chips that do it all anywhere in the vehicle... ;-0
 

edmunds

Senior Member
#23
Hippy, is timer0 available for us through PokeSFRs? I have sort of neglected it, because it is not used for PWM or counting functions when I was at timers, but it seems, with a 255 prescaler, in 16bit mode I could generate interrupt every 0.5s on overflow to toggle a pin. If access to interrupt registers was permitted...

Thank you,
Edmunds
 

AllyCat

Senior Member
#24
Hi,
Alan, I have not quite figured out if and how I could use this as I would like to get an external pulsed signal ..
Sorry, I've only limited internet access at the moment and haven't tested this, but.......

If you put a capacitor of 1 - 10 uF on any "touch-compatible" pin you should be able to create a low-Hz triangle or sawtooth waveform by using SFR commands to enable the low/medium/high current source (~5 - 50 uA) and using the DAC at (say) Level 24 to adjust the upper threshold. Then trim the frequency, if required, by setting the DAC Level +/- a few steps (the program could auto-detect the charge/discharge times from the SFR flag).

Use a digital input to "slice" the triangular waveform as a square (rectangular) wave; this might need a second pin or it may be possible to enable both the oscillator (current source) and digital ("TTL") input on the same pin, by using the relevant SFR commands. Use the digital input as a pin-interrupt to execute "ON/OFF" I2C commands, to operate the flashers as required (which I thought was what you are attempting to do).

Cheers, Alan.
 
#25
I've used a bunch of methods over the years for pps ... from 555 to RC+FETs, including the surplus battery operated wall clock (wife used to work in a doctor's office, I had a stack of clocks with adverts.)
This link has a number of approaches: https://tronixstuff.com/2013/07/31/four-1-hz-oscillator-methods/
and I have even used an tiny85 and crystal at 3.3V to perform the task: https://www.hackster.io/rayburne/1-second-tiny85-timer
I think it reallly boils-down to what the project builder decides to do; that is, what is in the parts bin and what accuracy is needed.

Ray
 
#26
Can't get much simpler & cheaper than this:
this is what I use for a "time on water" counter (it matches my Humminbird at end of day)
I never use the time & date stuff (don't need another clock)
it's also handy if you want to sync multiple Picaxes (or other uProcs)
if my memory is correct, with a watch battery, it keeps on working without I2C

; XL can be any register you choose
symbol DS1307 = $D0 ; actual I2C address for clock is 104(68h)
hi2csetup i2cmaster, DS1307, i2cslow, i2cbyte ; plug in Real-Time Clock I2C address
let XL = 0 : hi2cout $0,(XL) ; write DS1307 seconds register to enable clock
let XL = $10 : hi2cout $7,(XL) ; write DS1307 frequency output register (enable 1 Hz Output)
 

edmunds

Senior Member
#27
Dear all,

Once again, thank you for all the replies. The solution I have designed into a PCB that is being produced at some place China as we speak, is based on TCA6507 - 'LOW-VOLTAGE 7-BIT I2C AND SMBus LED DRIVER WITH INTENSITY CONTROL AND SHUTDOWN'.

The device measures just 2.00mm x 1.40mm in the smallest available package, has built in oscillator for blinking and dimming and seven outputs in total, 40mA each. While 40mA x 7 seems totally unrealistic for such a small package, I'm only interested in one high current output for LEDs and 40mA is more than enough. I have used 4 outputs to save some picaxe pins to control status inputs for STSPIN220 stepper motor driver and the remaining two are just routed to pads on a side for future functions. I will try to remember to report here when the boards and devices arrive (only DigiKey stocks the right package) and it actually works, but for now - considered done :). Attached two images of top and bottom layers of a 4-layer PCB - picaxe 40x2 UQFN in the spotlight.


Cheers,

Edmunds
 

Attachments

Last edited:

The bear

Senior Member
#28
@ hippy'
Post #21 above, looked very interesting and potentially useful.
However, I cannot make sense of it.
Is the 'Period' in mS. or uS., and the 'Duty' in % ?
A very simple example would be appreciated.

Do
w0 = w0 + 1 // PERIOD
pinC.0 = w0 / DUTY Max 1
Loop
 

hippy

Technical Support
Staff member
#29
Post #21 above, looked very interesting and potentially useful.
However, I cannot make sense of it.
Is the 'Period' in mS. or uS., and the 'Duty' in % ?
The 'period' and 'duty' are in terms of "loops", which is admittedly somewhat abstract.

Put a "PauseUs 100" in the loop and it's in terms of 1 ms because that's how long a loop would take with that included at 4MHz.

Do you have a scope or logic analyser? If so this will show a high-low combined period of 10 ms, with a 4 ms low and a 6 ms high.
Code:
Symbol PERIOD = 10
Symbol DUTY = 4
Output C.0
Do
  w0 = w0 + 1 // PERIOD
  pinC.0 = w0 / DUTY Max 1
  PauseUs 100
Loop
Or you can attach an LED+R between V+ and the pin ( active low ), change the "PauseUs 100" to "Pause 1000", and have a loop time period which is more humanly observable; a 10 second period, with 4 seconds on, 6 seconds off.

Code:
         _         ___________         __
LED    :  |_______|           |_______|

w0     :   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4  
       
DUTY   :  |<- 4 ->|           |
          |                   |
PERIOD :  |<------- 10 ------>|
If one wanted a 'duty' in terms of percent of 'period' ...

DUTY = PERIOD * percentage / 100

Watching out for 16-bit overflow in that multiplication of course. And noting a DUTY of zero causes problems in this simplistic demonstration.
 
Last edited:
Top