Saturday, August 29, 2020

0000 0000 0011 1110

LM358 Single Rail OpAmp Square Wave Oscillator

Slightly obsessed with the idea of a square wave oscillator as a timer, I have found many circuits which use an OpAmp to generate a square wave. Having tried a few, I settled on the LM358 datasheet version (p. 17, Figure 27) as follows.

There's a nice explanation of the theory and calculations for this type of circuit found on this site. Rather than the values for R1 etc,. shown in the datasheet, however, I used the following slight variation.



The changes were made mainly so that I could vary the oscillations (R4), and also I added an LED because if it's not blinking then it's not really electronics...


Here it is "in the flesh", and the video contains the all important blinking stuff.





Saturday, August 22, 2020

0000 0000 0011 1101

FreePDK Padauk Programmer - Part Two

On the last blog I wrote about the torturous road taken in soldering up an open source PCB designed (reverse engineered) to program the most intriguing Padauk microcontrollers.

After tens of hours of tears, sweat and the odd expletive - the fourth version I attempted actually worked. So now I take a closer look at the programming of these little chips.


It's worth noting that the toolchain for the factory supported IDE is entirely different to the open source version, and at this stage it seems you must choose one or the other.

With that in mind, I firstly installed dfu-util, and using the following code was able to successfully install the programming firmware onto the STM32 as per the instructions.

dfu-util -d 0483:df11 -a "@Internal Flash  /0x08000000/064*0002Kg" \
   --dfuse-address 0x08000000 -D EASYPDKPROG.dfu

   dfu-util 0.9
   ...
   Opening DFU capable USB device...
   ID 0483:df11
   Run-time device DFU version 011a
   Claiming USB DFU Interface...
   Setting Alternate Setting #0 ...
   Determining device status: state = dfuERROR, status = 10
   dfuERROR, clearing status
   Determining device status: state = dfuIDLE, status = 0
   dfuIDLE, continuing
   DFU mode device DFU version 011a
   Device returned transfer size 2048
   DfuSe interface name: "Internal Flash  "
   Downloading to address = 0x08000000, size = 29068
   Download  [=========================] 100%        29068 bytes
   Download done.
   File downloaded successfully

All went smoothly and so next it was a tough choice to select the first guinea pig IC. I think that of all the Padauk chips that I have ordered, the one showing the most potential for the types of projects that I like to get involved with is the PFS154-S08 available from LCSC.

Into the cradle went the chip and then I wanted a simple method of checking if the programming side of things worked. The obvious choice was of course a blinking LED - the "Hello World" of microcontroller programming.

/*
  BlinkLEDs

  Flicks on and off two LEDs attached to PA4 and PA3 of the PFS154-S08 chip.
  Uses a timing loop for delays.

*/

#include <pdk/device.h>
#include "auto_sysclock.h"
#include "delay.h"

// LEDs are placed on the PA3 and PA4 pins
#define LED1 4
#define LED2 3

// LED is active low (current sink), so define helpers for better readability below
#define turnGLedOn()   PA &= ~(1 << LED1)
#define turnGLedOff()  PA |= (1 << LED1)
#define turnBLedOn()   PA &= ~(1 << LED2)
#define turnBLedOff()  PA |= (1 << LED2)

// Main program
void main() {

  // Initialize hardware
  PAC |= (1 << LED1);          // Set LED as output (all pins are input by default)
  PAC |= (1 << LED2);          // Set LED as output (all pins are input by default)
  turnGLedOff();
  turnBLedOff();

  // Main processing loop
  while (1) {
    turnGLedOn();
    _delay_ms(250);
    turnGLedOff();
    _delay_ms(250);
    turnBLedOn();
    _delay_ms(250);
    turnBLedOff();
    _delay_ms(250);
  }
}

// Startup code
unsigned char _sdcc_external_startup(void) {
  AUTO_INIT_SYSCLOCK();
  AUTO_CALIBRATE_SYSCLOCK(TARGET_VDD_MV);
  return 0;
}

---------------

make clean program
rm -r -f .build .output
sdcc -mpdk14 -c --std-sdcc11 --opt-code-size -DPFS154 -DF_CPU=1000000 -DTARGET_VDD_MV=4000 -I. -I../include -o .build/main.rel main.c
sdar -rc .build/lib.lib 
sdcc -mpdk14 --out-fmt-ihx -o .output/BlinkLED_PFS154.ihx .build/main.rel .build/lib.lib
makebin -p .output/BlinkLED_PFS154.ihx .output/BlinkLED_PFS154.bin
---------- Segments ----------
.  .ABS.                            00000000    00000000 =           0. bytes (ABS,CON)
.  .ABS.                            00000000    00000000 =           0. bytes (ABS,CON)
HEADER1                             00000000    00000002 =           2. bytes (ABS,CON)
HEADER3                             00000000    00000010 =          16. bytes (ABS,CON)
PREG2                               00000000    00000002 =           2. bytes (ABS,CON)
RSEG0                               00000000    00000002 =           2. bytes (ABS,CON)
DATA                                00000002    00000007 =           7. bytes (REL,CON)
HOME                                00000022    00000002 =           2. bytes (REL,CON)
GSINIT                              00000024    00000014 =          20. bytes (REL,CON)
GSFINAL                             00000038    00000002 =           2. bytes (REL,CON)
CODE                                0000003A    00000094 =         148. bytes (REL,CON)
SSEG                                FFFFFFFF    00000001 =           1. bytes (REL,CON)
------------------------------
Size of BlinkLED_PFS154.bin: 206 bytes
easypdkprog -n PFS154 write .output/BlinkLED_PFS154.ihx
Erasing IC... done.
Writing IC (103 words)... done.
Calibrating IC
* IHRC SYSCLK=1000000Hz @ 4.00V ... calibration result: 999229Hz (0x7D)  done.


Nervously I transferred the programmed chip to a breadboard set up with the requisite connections and LEDs, turned on the power and was overjoyed to be greeted with blinking as required.


The next journey is to look at how this code works, then hopefully a repetition of the code in assembler. Looking ahead I would like to replace the ATTiny13 in the candle project with my own home grown Padauk assembler code. That should keep me a bit busy.

Thank you EEVBlog community, PCBWay and all those subscribers to the channel for your support, advice, encouragement and good will.



Saturday, August 15, 2020

0000 0000 0011 1100

FreePDK Padauk Programmer - Part One

A journey of 1000 miles begins with one step. Around a year ago I became aware that Dave Jones of EEVBlog fame was singing the praises of a technically capable but obscure microcontroller available for around 3 cents each in bulk. 

Who wouldn't want a capable microcontroller for just a few cents? The downsides of procuring this chip for use by your average home hobbyist include:

  1. Non-English datasheets (slowly starting to change)
  2. No way to program them (unless you want to buy an expensive - almost bespoke - programmer)
  3. "Interesting" IDE
  4. Non-standard language
  5. Little or no online support
But that didn't stop the EEVBlog community from reverse engineering the programmer and making a PCB that is capable of transferring the required binary sequences and getting a result from these chips. The work has been amazing and about 6 months ago I decided to have a go at making one of these open source wonders.


After the usual 2020 difficulties with freight and supply I found myself in the garage at the bench with the requisite bits and pieces and a hot soldering iron. Thank you to PCBWay who manufactured and sent the PCBs all the way to Tasmania to be melted by my incompetence.

Several swearing hours later I had a mostly fused PCB that at best might be useful for shoehorning a recalcitrant foot into a tiny boot - but way short of the digital magic required to unlock an inscrutable chip!



If MKI was a mess, then MKII was even worse! Fried components, mountains of congealed flux, ripped tracks and general mayhem ensued BUT I was able to connect and program the firmware onto the STM32F072C8T6 chip. This small success was great timing because at that stage I was ready to abandon the project and admit defeat.


I've never solved a problem by giving up, and now with a sniff of success I spent a careful week, an hour here and there, putting together MKIII - which....did not work at all!


The dreaded USB connector seemed OK (after a few tries), but who knows in among that mess if any connections are actually in place - certainly the voltage checks I did seem to point to an entirely different circuit!

So with a heavy heart I reluctantly started the MKIV version. Was this going to be another waste of time? Careful soldering, careful checking and many hours later I plugged it in - and...nothing!

In the depths of despair I had a sudden flash of inspiration (or desperation) and desoldered the STM32 from the failed (but talkative) MKII board and swapped it in on the MKIV board. Hilariously I blew several components together with the hot air gun (and melted some plastic) which took a bit of sorting out.


But...success! I now have a working opensource free-pdk.github.io PCB that can load the firmware, recognise a Padauk chip AND program it to blink like a champion. What a journey. In the next blog I'll look at the programming side of this circus, er...circuit.



 

Saturday, August 8, 2020

0000 0000 0011 1011

LM386N-4 Amplifier

Earlier on this blog and the associated YouTube channel I made an amplifier based on the remarkable LM386 OpAmp. The circuit was from this website, the prototype worked great, and I was inspired to design a PCB based on this success using EasyEDA. Then the project languished for a few months while I did some other stuff (Ibid.)




Then, for some reason I can't quite fathom, PCBWay reached out and requested to sponsor some of my work. The amplifier PCB came screaming off the "bench" and into the game and a few weeks later some bright shiny PCBs appeared. The build quality was great, even if there was an obvious shortcoming with my design!

Middle space too small - Crowded House Music?

So the actual PCB works fine, and the build is a very simple and fast one. The music is non-copyright and the end result is quite pleasing - thanks PCBWay!



Saturday, August 1, 2020

0000 0000 0011 1010

Monster Mailbag (Part Two)


Only for the dedicated, here is part two of the "Monster Mailbag". Feedback welcome!

Next week I return to making stuff, in this case an LM386 amplifier with a bit of blog history - and a new partnership as well.