Programming PICs

Everything technical about radio can be discussed here, whether it's transmitting or receiving. Guides, charts, diagrams, etc. are all welcome.
Albert H
proppa neck!
proppa neck!
Posts: 2780
Joined: Tue Apr 05, 2016 1:23 am

Programming PICs

Post by Albert H » Thu Dec 10, 2020 12:14 pm

The PICs are a great little range of microcontrollers that can be pressed into service for all sorts of functions in transmitters, receivers, level indicators and much more. Programming them with modern computer hardware isn't always straightforward, so I suggest that this thread is built up as a knowledge-base for anyone who wants to use these excellent devices.

The Microchip PIC range is now huge. There are devices for all sorts of uses. In the pirate radio world, the two principal uses are for generating RDS signals and for programming PLL ICs in transmitters and receivers.

Back in the days when I built and sold a lot of gear to pirates, I went from the open four-chip synthesiser (programmed by wire links or fitted and missing diodes) which was cheap and effective (and easily reset to a different frequency) to a little 12F609 specifically programmed for just one frequency that controlled a PLL IC (a 145170, 5511 or 1057). This meant that rig thieves couldn't change the frequency of the PLL which made the rigs a lot less attractive to steal! The downside was that a legitimate frequency change usually meant a late-night visit to a dodgy part of town, carrying a laptop.....

The PICs that are commonly used are all "high voltage" programmed types. This means that they need about 13V to "flash" the non-volatile programme memory and load their programme.

There are a number of PIC programmers on the market. You don't need to spend a lot on one - you can even build one yourself for just a few £/$/€. The most expensive part is a "ZIF" socket (Zero Insertion Force). However, you can buy ready-made programmers including ZIF socket(s) from the Far East for <£10.

The PIC manufacturers (originally Microchip, but there are now "second sources") provide all the programming software tools that you could ever need. The PICs are "RISC" processors, for have very few assembler commands to learn (typically around 30). If you don't want to programme in Assembler, there are higher level language "interpreters" available - ones I've used include PICBasic, MicroC, FORTH, LISP, WISP, and even Perl!

The programme files are loaded into a blank PIC in the form of a "Hex" file - a series of two-digit hexadecimal numbers uploaded serially into the IC with the programmer. Once programmed (and verified), the IC becomes an application-specific logic IC. They're cheap, easily programmed and reproducible.

Hints, tips, and programmes to follow. Anyone who has anything useful to add, please write to this thread!
"Why is my rig humming?"
"Because it doesn't know the words!"
;)

User avatar
sinus trouble
proppa neck!
proppa neck!
Posts: 1410
Joined: Fri Aug 22, 2014 11:34 pm

Re: Programming PICs

Post by sinus trouble » Fri Dec 11, 2020 1:04 am

Thank you Albert! :)

This is a subject i find interesting, However i feel it may be too much for some to take in?

Im not saying anyone is stupid as i also struggle too.

From this point on, Analogue is out of the window, Digital ONLY communicates in 1s and 0s, On or offs, HIGHs or LOWs or steps whichever you wanna call it?

These are also based on a time scale rather than a frequency and will use a reference clock or time basis to determine ON and OFF durations.

The PIC series (Say 16BIT) usually contains 16 Bi-Directional pins which you can set to be either an input or an output? These will be configured in the first part of your assembly code.

Then you have the MEMORY which is assigned in addresses! This sets what your inputs/outputs are doing or executing.

Often in assembly files you will see the command 'GOTO' or 'LOOP' which means it is rolling back to a specified part of the code.

Theres so much more details to go over but theres one tip to assembly codes id like to add!
When you see ; info following is disregarded by the PIC and used mostly by Authors to make sense of whats going on in the code.
I am as stupid as I look! :|

Albert H
proppa neck!
proppa neck!
Posts: 2780
Joined: Tue Apr 05, 2016 1:23 am

Re: Programming PICs

Post by Albert H » Fri Dec 11, 2020 3:49 am

When programming your PIC, you have to tell the IC what "mode" the clock oscillator will be in - RC, crystal, high speed, and so on. There are other configuration settings too - code protect, slowed start-up, brownout detect and more.

Microchip will send you a huge book and the programming software tools on CDs - you can apply through their website.
"Why is my rig humming?"
"Because it doesn't know the words!"
;)

zulu53
who u callin ne guy bruv
who u callin ne guy bruv
Posts: 38
Joined: Sat Mar 28, 2020 12:45 am

Re: Programming PICs

Post by zulu53 » Sat Dec 12, 2020 9:08 pm

Thank you very much Albert for your great initiative. This is the topic I have been waiting for a long time.

My knowledge of PLL stopped in the MC145151 / 2 era. So, sentences like: "The simple" PIRA "1057 is well known and easy to replicate. It uses a cheap PIC and a 4MHz crystal." created on me some frustration and a feeling of helplessness.

I hope your approach continues to be didactic and accessible to everyone so that even newbies can reach a reasonable level of knowledge about modern PLL circuits and Programming PICs. Regards

alfaeire
no manz can test innit
no manz can test innit
Posts: 142
Joined: Tue Aug 11, 2015 11:17 am

Re: Programming PICs

Post by alfaeire » Sun Dec 13, 2020 9:09 am

https://dl.wish.com/8Vo5T

3 euro. Programs pic, eprom etc.

Sent from my ONEPLUS A5010 using Tapatalk


User avatar
sinus trouble
proppa neck!
proppa neck!
Posts: 1410
Joined: Fri Aug 22, 2014 11:34 pm

Re: Programming PICs

Post by sinus trouble » Mon Dec 14, 2020 12:09 am

I noticed MICROCHIP mentioned a simulator software in the datasheets.

That could be very handy as it would eliminate the hassle of flashing test codes or 'In circuit programming' of actual devices!
I am as stupid as I look! :|

Albert H
proppa neck!
proppa neck!
Posts: 2780
Joined: Tue Apr 05, 2016 1:23 am

Re: Programming PICs

Post by Albert H » Mon Dec 14, 2020 1:48 am

zulu53 wrote: Sat Dec 12, 2020 9:08 pm Thank you very much Albert for your great initiative. This is the topic I have been waiting for a long time.

My knowledge of PLL stopped in the MC145151 / 2 era. So, sentences like: "The simple" PIRA "1057 is well known and easy to replicate. It uses a cheap PIC and a 4MHz crystal." created on me some frustration and a feeling of helplessness.

I hope your approach continues to be didactic and accessible to everyone so that even newbies can reach a reasonable level of knowledge about modern PLL circuits and Programming PICs. Regards
I'll do my best to keep this as simple and easy to follow as possible.

The PIC range of microcontrollers are wonderful little devices, and it never ceases to amaze me just how cheap they are.

Note: The parts that you want to use are the 12F... and 16F... types. The "F" denotes "Flash programmable" and these types can be wiped and reprogrammed as many times as you want. Microchip warn that there is a limit to the number of times these parts can be reprogrammed, but I've never had any issues with "worn" chips. The other type - the "C" series are (sometimes) a bit cheaper, but can only be programmed once - the code is permanently burned into the chip.

The chips that we're going to be interested in are powered with 5V - they draw little current, so the 78L05 is an ideal regulator for them.

The ICs that I'm most used to use either external crystals to clock them, or (sometimes) a simple RC network for a slower clock where frequency stability isn't too much of an issue.

If you take a look at the "Pira" SAA1057 PLL circuit, you'll see that the PLL IC has a 4MHz reference crystal, and the PIC (16F84) is clocked with an RC oscillator. The datasheet for the PLL is at https://www.pira.cz/pdf/SAA1057.pdf It's worth having a look at the Philips booklet, because it gives quite a lot of information about the internals of the '1057, and explains the nature of the data that the IC expects to receive. It also tells you how to wire up the chip and the precautions you need to take.

The way that the "Pira" circuit actually works is fairly simple - at power-up, the PIC scans the 8 DIP switches, and then sends two short bursts of data to the PLL IC. The PIC then goes to sleep, as it has nothing else to do - the PLL IC has the data it needs to do its job. This is held in its internal (volatile) registers.

One codeword sent carries the configuration information. It tells the PLL IC to use its "FM" input, and also how to configure its internal reference dividers and the phase comparator. The other codeword includes the data taken from the DIP switches, and tells the PLL IC how to set the carrier divider and prescaler.

Communication from the PIC to the PLL IC is carried out using the I²C protocol. This uses three wires - Data, Dlen (data length), and Data Clock. The Philips datasheet shows the format of the data that has to be squirted into the chip. It goes in serially, and is held in "data latches".

If you look at the circuit diagram, you'll see that there are three port pins on the PIC pins 1, 2 and 3. These are connected directly to the inputs on the PLL IC. You'll also notice that there's a fourth data line with a pull-up resistor and a momentary switch to ground. This is used to "reset" the PIC, and forces a re-scan of the DIP Switches and sends the data to the PLL, pretty much the same as a power-up. The rate at which the info goes into those data latches in the '1057 is not too critical, which is why we can get away with a simple RC clock for the PIC. The timing components are on pin 16 of the PIC.

The PLL works as you'd expect - it is fed a sample of the output frequency, and it produces a control voltage to steer the transmitter VCO on to the correct frequency and keep it there. One of the nice things (and often overlooked) is that the SAA1057 will handle a tuning voltage of up to 30V on Vcc3. This allows the use of less sensitive voltage control of the oscillator whilst still being able to tune anywhere in Band II, improving phase noise figures and making the VCO less prone to hum pickup. I usually use a little single transistor blocking oscillator to generate the 30V, and just make very sure that there's no 120kHz ripple on the varicap supply!

At power-down, the PLL IC "loses" its settings, so the PIC re-loads them on each power-up.

Building the circuit isn't difficult. There are some simple PCB layouts (our friend "Sinus Trouble" put up a whole exciter layout using the old "Veronica" VCO and amplifier stages and the "Pira" PLL - it's a neat layout). Constructing the circuitry shouldn't pose any problems. The only bit you'll find tricky - especially if you've never done it before - is programming the PIC.

Fortunately, the Hex File for this project is widely available, as is the chart that details the DIP Switch settings for each Band II frequency.

In my next post, I'll explain exactly what you need to get to programme PICs, and exactly how to go about programming them. I'm going to recommend a simple serial programmer that you can build yourself (or buy for a few quid online), and explain how to configure your computer to write programmes and data into PICs. I mostly use Linux, but I will include details for the Windoze-afflicted. Mac owners should know better......!
"Why is my rig humming?"
"Because it doesn't know the words!"
;)

Albert H
proppa neck!
proppa neck!
Posts: 2780
Joined: Tue Apr 05, 2016 1:23 am

Re: Programming PICs

Post by Albert H » Mon Dec 14, 2020 2:07 am

alfaeire wrote: Sun Dec 13, 2020 9:09 am https://dl.wish.com/8Vo5T

3 euro. Programs pic, eprom etc.

Sent from my ONEPLUS A5010 using Tapatalk
Unfortunately, this won't programme "high voltage" PICs - it's really meant as a cheap EPROM blower. Better to get a PICKit3, K150, JDM, WISP or similar. None of them should cost more than about £10
"Why is my rig humming?"
"Because it doesn't know the words!"
;)

Albert H
proppa neck!
proppa neck!
Posts: 2780
Joined: Tue Apr 05, 2016 1:23 am

Re: Programming PICs

Post by Albert H » Mon Dec 14, 2020 2:24 am

One thing that I forgot to mention about the "Pira" PLL - the PIC sleeps for about 30 minutes, then does another squirt of the data to the PLL. The author of the original programme found that this was a good way of taming tricky VCOs and making sure that the rig stayed on frequency. I found that this really wasn't strictly necessary, since the PLL IC reliably held the configuration data for as long as power was applied, and my VCOs were never so bad that they'd drift out of the range of the PLL!
"Why is my rig humming?"
"Because it doesn't know the words!"
;)

zulu53
who u callin ne guy bruv
who u callin ne guy bruv
Posts: 38
Joined: Sat Mar 28, 2020 12:45 am

Re: Programming PICs

Post by zulu53 » Mon Dec 14, 2020 5:40 am

So far, so good. I can follow your explanations, they are very clear. Thank you, I will read the Philips booklet on SAA1057, as recommended.

User avatar
sinus trouble
proppa neck!
proppa neck!
Posts: 1410
Joined: Fri Aug 22, 2014 11:34 pm

Re: Programming PICs

Post by sinus trouble » Tue Dec 15, 2020 12:16 am

I absolutely love the SAA1057 I have used it so many times, Yet still it never fails to impress me!

Anyways back to subject, I would highly recommend anyone who wishes to learn more about PICs? To familiarise yourselves with how Binary and Hexadecimal counting works.

There are an abundance of documents online and even simple videos too.
I am as stupid as I look! :|

zulu53
who u callin ne guy bruv
who u callin ne guy bruv
Posts: 38
Joined: Sat Mar 28, 2020 12:45 am

Re: Programming PICs

Post by zulu53 » Fri Dec 18, 2020 1:07 pm

Hello Sinus! Thanks for the suggestion to learn binary and hexadecimal count. In fact, binary count allowed me to use MC145151 and specially MC145152 for programming virtually any frequency using different prescalers and / or crystals. I can imagine that hexadecimal count has, at least, the same degree of importance for PIC programming. Regards

User avatar
sinus trouble
proppa neck!
proppa neck!
Posts: 1410
Joined: Fri Aug 22, 2014 11:34 pm

Re: Programming PICs

Post by sinus trouble » Sat Dec 19, 2020 12:44 am

zulu53 wrote: Fri Dec 18, 2020 1:07 pm Hello Sinus! Thanks for the suggestion to learn binary and hexadecimal count. In fact, binary count allowed me to use MC145151 and specially MC145152 for programming virtually any frequency using different prescalers and / or crystals. I can imagine that hexadecimal count has, at least, the same degree of importance for PIC programming. Regards
Yes it is a strange concept to many newcomers, The 'Computer' cannot understand conventional ways that a human would count! The Digital realm can be a daunting place? But with determination and a willing to learn, things become easier.

I am by far no expert and not ashamed to say so! My learning curve is not looking likely to end anytime soon.
I am as stupid as I look! :|

User avatar
Bton-FM
tower block dreamin
tower block dreamin
Posts: 463
Joined: Sun Jun 16, 2019 2:55 pm
Location: Beside the seaside

Re: Programming PICs

Post by Bton-FM » Sat Dec 19, 2020 1:09 am

sinus trouble wrote: Sat Dec 19, 2020 12:44 am
zulu53 wrote: Fri Dec 18, 2020 1:07 pm Hello Sinus! Thanks for the suggestion to learn binary and hexadecimal count. In fact, binary count allowed me to use MC145151 and specially MC145152 for programming virtually any frequency using different prescalers and / or crystals. I can imagine that hexadecimal count has, at least, the same degree of importance for PIC programming. Regards
Yes it is a strange concept to many newcomers, The 'Computer' cannot understand conventional ways that a human would count! The Digital realm can be a daunting place? But with determination and a willing to learn, things become easier.

I am by far no expert and not ashamed to say so! My learning curve is not looking likely to end anytime soon.
For newcomers, it might be worth getting to grips with the Arduino IDE first. It’s similar to C and easy to get the hang of. If you use one of the boards with a USB port on port on it, it’s trivial program.

I’ve written a program with it that controls the TSA5511 by using the wire library, some basic bit math and a ‘while’ statement. For the IC I used and 8 pin SMT ATtiny that costs about 30 pence each. Before I tried it with an ATtiny, I used the Arduino nano to test the code. Then, I used the arduino nano as an ISP (In series Programmer) to program the ATtiny.

Before I did this I knew diddly squat about coding, only odds and ends of HTML from when I was at school and I managed to make it work quite quickly. My advice to anyone who wants to learn to code is grab an Arduino Nano for 3 credits of the realm and get stuck in!

Albert H
proppa neck!
proppa neck!
Posts: 2780
Joined: Tue Apr 05, 2016 1:23 am

Re: Programming PICs

Post by Albert H » Sat Dec 19, 2020 2:57 am

We'd all be interested in your code for the AT Tiny! Is it fixed frequency or tunable?

I used the Arduino in a couple of industrial control projects - there's a compiler that turns PLC Ladder code into Arduino-speak. I found that to be a quick and effective solution to a logic problem, but it can't be certified (like PLC code can be), so I ended up using a Wago PLC (the most expensive available) just to make a point and piss the client off!
"Why is my rig humming?"
"Because it doesn't know the words!"
;)

User avatar
Bton-FM
tower block dreamin
tower block dreamin
Posts: 463
Joined: Sun Jun 16, 2019 2:55 pm
Location: Beside the seaside

Re: Programming PICs

Post by Bton-FM » Sat Dec 19, 2020 11:33 am

Albert H wrote: Sat Dec 19, 2020 2:57 am We'd all be interested in your code for the AT Tiny! Is it fixed frequency or tunable?

I used the Arduino in a couple of industrial control projects - there's a compiler that turns PLC Ladder code into Arduino-speak. I found that to be a quick and effective solution to a logic problem, but it can't be certified (like PLC code can be), so I ended up using a Wago PLC (the most expensive available) just to make a point and piss the client off!
There’s a few variants of the code:

1.Fixed frequency.

2.Selecting frequency at switch on by climbing up the band in 50Khz or 100Khz steps by shorting two pads together and soldering two pads together to finish. I think I read you did something similar on here so I gave it a go. It’s a convenient way of selecting frequency, especially when there is limited pins. It also makes it harder for thieves to retune....

3.Tuning up and down the band with two push buttons.

There is a lock LED and unlock LED as well as out of lock power down output.

I’ll post one of the variants when I get the chance but I am busy at the moment (hence why I haven’t said much on here recently).

User avatar
sinus trouble
proppa neck!
proppa neck!
Posts: 1410
Joined: Fri Aug 22, 2014 11:34 pm

Re: Programming PICs

Post by sinus trouble » Sat Dec 19, 2020 11:10 pm

Nice work B-Ton :)

I have never used them before, I keep meaning to get hold of one.

I guess the main aim for these products is to make coding easier to understand, So i totally agree that they are a viable option!

Not just for beginners, But Professional use too.
I am as stupid as I look! :|

alfaeire
no manz can test innit
no manz can test innit
Posts: 142
Joined: Tue Aug 11, 2015 11:17 am

Re: Programming PICs

Post by alfaeire » Fri Mar 12, 2021 11:39 am

I have 2 tugicom tx190 exciters,
I was switching out the pic 18f1220 from one board to the other instead of flashing but somehow managed to bend 2 legs and then they broke off when I straightened them.. I'm now aware how fragile they can be.

So, I hopped over to ebay to buy a new one thinking I can program it via the rs232 on the board as is usually done to flash the RDS.

The more I'm looking into it, the more it looks like I'll need the code from the original chip or it won't work.

If I was to order the PICKit3 or K150 will this allow me to pull the code from the non damaged chip to flash the one that's already in the mail?

Sent from my ONEPLUS A5010 using Tapatalk


User avatar
Zozo
tower block dreamin
tower block dreamin
Posts: 256
Joined: Sun Feb 14, 2021 9:33 am
Location: 3rd rock from the Sun

Re: Programming PICs

Post by Zozo » Fri Mar 12, 2021 9:26 pm

You can try with copying the code, but I'll be amazed if the code protection fuse is still intact. Maybe worth emailing Tugicom. You never know, you might get a reply. [email protected]

I'm sure the RDS attributes via the RS232 are sent to the "Data Memory" of the 18F1220 but the core code is programmed into the "Program Memory" which is possibly code protected

Maybe someone else on here will advise better.
Give me a AM transmitter with things that glow any day.

User avatar
Electronically
tower block dreamin
tower block dreamin
Posts: 431
Joined: Wed May 13, 2015 11:43 am

Re: Programming PICs

Post by Electronically » Fri Mar 12, 2021 10:29 pm

Word of advice about ic to protect you from bending the legs. Is place one side of the ic flat to the table press firmly then flip to the other side press till both sides are equal,
Now onto the next part if you wish to programme the ic then you must learn python. Python is no hard hard to learn just a little knowledge before you know it you've programned your lcd

Sent from my AMN-LX9 using Tapatalk


Post Reply