Saturday, February 6, 2021

0000 0000 0101 0011

PFS154 "unleashed"

Now that I have a working Padauk programmer, I am keen to explore the capabilities of these chips. The interesting quirk straight up is that these chips sink current - that is the opposite to what I have experienced with AVR chips.

My first thought was of how to make use of this "feature" as an output as per my experience. With not much sophistication I whipped up a "NOT" gate using a SS8050 transistor as we've seen on this blog before.

So then I fed the "reversed" signal to the ULN2803 (of yet another previous blog), and modified the code that comes with the freepdk programmer project as below.

/*
  BlinkLED

  Turns an LED on for one second, then off for one second, repeatedly.
  Uses a timing loop for delays.
*/

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

// LED is placed on the PA3 pin (Port A, Bit 3) with a current sink configuration
#define LED 3

// LED is active low (current sink), so define helpers for better readability below
#define turnLedOn()   PA = 0b00000000   // original:  PA &= ~(1 << LED_BIT)
#define turnLedOff()  PA = 0b00001000   //            PA |= (1 << LED_BIT)

// Main program
void main() {

  // Initialize hardware
  PAC = 0b00001000;          // original: PAC |= (1 << LED_BIT);
  turnLedOff();

  // Main processing loop
  while (1) {
    turnLedOn();
    _delay_ms(200);
    turnLedOff();
    _delay_ms(1200);
  }
}

// Startup code - Setup/calibrate system clock
unsigned char _sdcc_external_startup(void) {

  AUTO_INIT_SYSCLOCK();
  AUTO_CALIBRATE_SYSCLOCK(TARGET_VDD_MV);

  return 0;   // Return 0 to inform SDCC to continue with normal initialization.
}

Finally, as the ULN2803 also sinks (large) current, I pressed a 3W LED into action and had some major blinky action.

I know it does not seem like much, but there was real joy in finally making a "project" using the Padauk at the heart. I've got my sights set on PWM next - maybe controlling a motor (the ULN2803 also reputedly does excellent work in this regard).




No comments:

Post a Comment