Page 2 of 2

Re: 16f18877 internal Zero Cross Detector

Posted: Tue Feb 10, 2026 10:26 am
by mnfisher
That sounds very neat - you could probably knock up a similar setup in TINA as a demo system?

Nice to know that not everything needs an MCU and 'AI' to work :-)

Martin

Re: 16f18877 internal Zero Cross Detector

Posted: Tue Feb 10, 2026 12:45 pm
by chipfryer27
Hi Martin

A few years back I documented the resurrection of my TRS-80 (Lev11 16K, yes, bow down and worship.....) and I found some of the interface boards I made for it and similar Z80 based machines running some form of BASIC.

At the time of the CPC464 mentioned above, I was probably around 19 or 20yrs old and had never heard of PCB layout / Circuit Simulation tools, and if they even existed back then would most certainly have been way out of my price range. If you took the back off of pretty much any consumer electronics at the time, traces looked at best hand drawn by a drunk on a trampoline...... which admittedly does sound a lot of fun.

An A4 notepad was my design tool to scribble things down and once I was reasonably satisfied that my logic was correct I would use a Staedtler A4 drawing board to tidy up my lines etc (still have that). Simulation was done by pencilling in a "1" or "0" at the data bus, following the trace and pencilling in the corresponding level there etc etc until you had gone through your logic chain and arrived at your output.

Vero boards were my weapon of choice as I had no way to produce PCBs. However the boards were only used to mount components. Wiring between pins was done by direct connection with wires routed "neatly" on the surface. Amazingly it was always correct first time........... :roll: I probably still have my Antex 18W iron from then. Vero is unsuitable for "Mains", that was all off the "logic" boards.

Nowadays though the whole lot could be simply done using as you suggest TINA (other far more expensive methods are also available). Although in the "city" there was a specialised component store (Andrew Marshall I think) that could probably have sourced more complex chips, everything was built using either 74-series or 4000-series gates that Tandy stocked. AND/NAND/OR/XOR/NOR/J-K Flip-Flops etc were the bread and butter, not forgetting the ubiquitous Tri-State Buffer, essential for anything appearing on an Address / Data bus. Why wait for stock of a 4-input gates to arrive when I could use two 2-inputs and a spare gate on some other chip elsewhere on the board.......

Now I think on it, I also had an 8 x 8 grid, much like the 8x8 LEDs you get nowadays. Of course this was far greater in size and if I remember correctly I would send a byte, which was two nibbles, each bit of the nibble being the leg of a column / row. I would have had to have used full address decoding for this, as it would take up the entire 8-bit data bus leaving no room for other "Out" statements. For those interested the Out and In statements were available in Z80 machines and simplified interfacing. If you issued for example OUT,255 then all bits of the data bus would go high plus the "Out" line. To take an input you used IN,x and this would enable the "In" line, read the data bus and assign to variable "x". The Out / In pins enabled the Tr-State Buffers (and possibly other logic too). Made a huge difference to the logic required to interface.....

"Grrr..them youngsters nowadays don't know they're born......." :lol:

Regards

EDIT....
It was a long time ago...... Now I've thought on it, the Out/In used the lower 8-bits of the address bus plus the Out/In lines to give 256 addresses with access to the 8-bit data bus. My 8x8 grid would simply have been address 0000 0001 + OUT or similar. The OUT would have enabled Tri-State Buffers plus other logic.

Re: 16f18877 internal Zero Cross Detector

Posted: Tue Feb 10, 2026 3:45 pm
by medelec35
What I did to detect ZCD on a microcontroller that did not have ZCD was to use a resistor to prevent too much or reverse current on a pin. detect for 0v (positive half cycle), then timed 10 ms for the zero crossing after the negative half cycle.
That made the AC motor i controlled via MOSFET and a bridge rectifier very quite, the was no buzzing like there is with triac control.

Re: 16f18877 internal Zero Cross Detector

Posted: Tue Feb 10, 2026 4:22 pm
by hippalator
mnfisher wrote:
Mon Feb 09, 2026 7:46 pm
The pin declared in properties is for output - I'd connected this (RD1) to a logic analyser - it was easier than wiring up a UART convertor...
The zero crossing interrupts on RA0 - I think this is fixed on the 18877 - but other PICs might be able to remap to other pins.. This is set up (analog / input) in the interrupt enable block.

The output is defined in properties:

properties.png


I would recommend doing pin assignments like this (rather than using Input/Output blocks) - except for very small pieces of code. It enables the pin to be changed easily (without having to alter all the Input/Output blocks) - and the pin can be written using pin = value or read using value = pin (where value will be 0 or 1)

Use of properties allows many very useful features - click add property and take a look...

Martin
I looked for your pin property over the past weekend but I found nothing.
I'm using Version 11

Re: 16f18877 internal Zero Cross Detector

Posted: Tue Feb 10, 2026 4:29 pm
by chipfryer27
Hi Martin

That's an interesting way to do it. Software to the rescue. Never thought on that way, but now you mention, it is so obvious :lol:

Wish I had access to uC back in the day.....

Regards

Re: 16f18877 internal Zero Cross Detector

Posted: Tue Feb 10, 2026 4:37 pm
by chipfryer27
Hi

View > Component Properties > Add New

Screenshot 2026-02-10 163212.jpg
Screenshot 2026-02-10 163212.jpg (102.57 KiB) Viewed 30 times

Select to suit, e.g. Single Digital Pin

Screenshot 2026-02-10 163247.jpg
Screenshot 2026-02-10 163247.jpg (29.31 KiB) Viewed 30 times


Finally select your pin.

Screenshot 2026-02-10 163431.jpg
Screenshot 2026-02-10 163431.jpg (35.34 KiB) Viewed 30 times

Regards

Re: 16f18877 internal Zero Cross Detector

Posted: Tue Feb 10, 2026 5:05 pm
by hippalator
I've learned something today.
Thank you

Re: 16f18877 internal Zero Cross Detector

Posted: Tue Feb 10, 2026 5:08 pm
by chipfryer27
All thanks go to Martin

I learned it from him ages ago. I saw he was using it but couldn't figure out how. Did take me a bit of poking around to find it :)

Regards