Posted on Leave a comment

Trump Screws Electronics Enthusiasts

This is not a political thing I’m doing. I have no dog in the hunt over gay rights or the upcoming Russian invasion. I’m just a bad maker and worse engineer. However, I just heard today on the Macrofab Podcast that my unpopulated PCB orders will face a new government tax of 25%. A kit I wanted to sell for $8 will now have to sell for $10. I will sell less. Broke people who want to buy my kits will get less money for their buck.

I don’t know ANY of the details of the current macro trade stuff. I try to stay exactly five years behind on politics. (It’s much more fun.) What I do know is I’m taking a direct hit and my business will directly suffer. It’s one thing to charge more money on the consumer level. It’s another thing to affect the livelihood of small business owners.

Random Application of Tariffs

Another truly intriguing part about these tariffs is how selective they are in their taxation.

Unpopulated PCBs
If a printed circuit board (PCB) is populated with components in China, there is no additional tariff. The reasons for this seem intuitive. Apple has lobbyists. Apple doesn’t want their phones to go up 25%. It’s too bad smaller business owners don’t have any representation.

Flyback diodes
If a diode is to be used for voltage suppression, it is taxed. How in the hell do they know if I’m going to use a diode for rectification or voltage suppression? That’s a good one. Where did they find the tax attorney who has a background in electronics? That’s impressive, actually.

Potentiometers (not resistors)
Fixed resistors don’t get an additional hike. Variable potentiometers go up 25%. Who comes up with this stuff?

Transformers under 1kA
Transformers under 1KA – essentially all consumer grade transformers – go up 25%. The big, industrial transformers face no hit.

I’ve always been perplexed why the tax code favors horse farmers differently than corn or cow farmers. (Each group has varying lobbyist strength.) I’m not aware of the flyback diode industry having a powerhouse lobby that the rectifier diode industry just can’t keep up with.

Where Is The Money Going?

The real question is where is this money going? I did the unthinkable and Googled this tariff mess. I see both China and the US are cranking up their taxes. Ok. Is this to pay off the debt? Are they building a new Hoover dam? Are we invading a new country? I’m just trying to figure out why we’d reduce US prosperity and increase the prices of U.S. manufactured goods. If I know where my money (and business) are going, I’ll be more inclined to pony up.

Posted on Leave a comment

Baseline ADC Readings Through Serial on AtMega328p

I hope this is legal putting this here. This is modified code from the Make: AVR Programming book. If you wanting to hop from Arduino to C Programming, this book is INCREDIBLE! Seriously, just freakin’ buy it.

This code measures a voltage coming into PC0 and spits it out through the serial monitor. The scaling isn’t right, but adjusting the voltage on PC0 with a potentiometer delivers reasonable results.


// ************ ADC works well enough   
//p.135  AVR Programming Make Book Mostly ********************
// The scaling is screwy, but I can adjust a potentiometer 
//and get reasonable 8-bit data
// ADC is reading PC0.  

#include <avr/io.h>
#include <util/delay.h>
#include "pinDefines.h"
#include "USART.h"

static inline void initADC0(void) {
	ADMUX |= (1 << REFS0);  // reference voltage
	ADCSRA |= (1 << ADPS1) | (1 << ADPS0); // ADC clock prescaler /8
	ADCSRA |= (1 << ADEN);  // enable ADC	
}

int main(void){
	// Inits
	uint16_t adcValue;
	//uint8_t i;
	initADC0();
	initUSART();
	printString("Hello!\r\n");
	
	while (1) {
		ADCSRA |= (1 << ADSC);  // start ADC conversion
		loop_until_bit_is_clear(ADCSRA, ADSC);  
                // wait until finished
		adcValue = ADC; // Read ADC in
		
		_delay_ms(50);
		transmitByte(adcValue);
		_delay_ms(1000);
		
	}  // end big loop
	
	return(0);
}
Posted on Leave a comment

Is there evil in the world? Yes! LabVIEW!

My boss – okay he’s a professor at school – at my internship – okay, it’s an unsanctioned internship and I’m working for free – asked me to clean up the GUI on a LabVIEW power measurement circuit. I have vast experience with .css from my html background so I thought “no problem”.

I’ve debated if evil truly exists beyond the realm of the mentally ill. Evil acts certainly occur. Is Jeffrey Dahmer evil or just crazy? Maybe this crazy vs evil thing is a semantic mess, but we treat evil much differently than we treat insanity in American culture.

Now I have my answer. I can say definitively, 100%, without a doubt that evil exists in the world and I can only assume that the creators of LabVIEW over at National Instruments are not mentally ill. It would take too many people all with the same scheming hands and maniacal laugh to be working in unison to create a tool that has created so much wrong in the world.

How many hours do I need to invest in adjusting the size of font? Should it take hours and hours to change the background color? Why can’t I just select the good ol’ color codes from the html world or the Photoshop world? Why is it when I save a file, I’m asked all these nonsensical questions when the current paradigm of saving files is well-understood and works incredibly well. Why is it the movement resolution of a label is high when three inches from the gauge, but heavily quantized when close to the target.
WHY CAN’T I ZOOM??????

There isn’t a single facet of the LabVIEW software that doesn’t take 10x longer than it should to learn. At the end of the day, the hardware behind LabVIEW is so ridiculously high priced that I can’t think of an instance where the graphical software makes a bit of sense to implement. Because LabVIEW will waste hours and hours on things that Microsoft Paint mastered in 1991, the overall project time isn’t all that different from what one may expect when programming in C.

LabVIEW is evil. Case closed.

Posted on Leave a comment

Controlling PWM With Potentiometer On AtMega328p

This is crude, but the thing works.  We’ve all seen this on the Great Scott Youtube channel (among other places) where a potentiometer controls the duty cycle of a PWM waveform on an oscilloscope.  This version isn’t pretty.  It needs some sanding and painting.  However, it’ll get a person started.  I’m adding it here as my personal library to steal from as needed.  Feel free to do the same.

Most of it is also stolen/borrowed from two main sources.

  1.  AVR Programming book by Make  (p.135)
  2.   AVRFreaks.net forum post 

Hardware Requirements

PC0 is looking for an input voltage ( keep it under 5V!!!!).  I made a voltage divider with a 10k resistor and a 10k pot using the AtMega’s 5V supply.  This will max out at 2.5V so I’m definitely throwing resolution away.

AREF needs 5V, too.  I tossed a random cap across it any GND to reduce some of the nasties.

#include <avr/io.h>
#include <util/delay.h>
#include "pinDefines.h"
#include "USART.h"

static inline void initADC0(void) {
	ADMUX |= (1 << REFS0);  // reference voltage
	ADCSRA |= (1 << ADPS1) | (1 << ADPS0); // ADC clock prescaler /8
	ADCSRA |= (1 << ADEN); // enable ADC } uint16_t divider = 1; void Duty( uint8_t percentage, uint16_t ICR1_value) { percentage = (percentage > 100 ? 100 : (percentage < 0 ? 0 : percentage)); uint16_t OCR = (uint16_t)(((uint32_t)percentage * (uint32_t)ICR1_value)/100) ; // Set pwm percent of pwm period OCR1AH = OCR >> 8;
OCR1AL = OCR & 0xFF;
}

void FrequencyPWM(uint16_t frequency, uint8_t percentage)
{
uint16_t TOP = F_CPU/(divider*frequency) - 1;
ICR1H = TOP >> 8;
ICR1L = TOP & 0xFF;
Duty(percentage, TOP);
}

void PWM1_INIT()
{
DDRB |= (1 << PINB1);
//DDRB |= (1 << PINB2);
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 62.500 kHz - I changed this to No prescailing using CS12=0, CS11=0, and CS10 = 1
// Mode: Fast PWM top=ICR1
// OC1A output: Non-Inverted PWM
// OC1B output: Non-Inverted PWM
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer Period: 1 s
// Output Pulse(s):
// OC1A Period: 1 s Width: 0.2 s
// OC1B Period: 1 s Width: 0.40001 s
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=(1<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (1<<WGM11) | (0<<WGM10);
TCCR1B=(0<<ICNC1) | (0<<ICES1) | (1<<WGM13) | (1<<WGM12) | (0<<CS12) | (0<<CS11) | (1<<CS10);
TCNT1H=0x00;
TCNT1L=0x00;

FrequencyPWM(50, 10);
}

int main(void){
	
	PWM1_INIT();
		
	// Inits
	uint16_t adcValue;
	//uint8_t i;
	initADC0();
	initUSART();
	printString("Hello!\r\n");
	
	FrequencyPWM(10000, 50);
	_delay_ms(100);
	
	while(1){
		ADCSRA |= (1 << ADSC);  // start ADC conversion
		loop_until_bit_is_clear(ADCSRA, ADSC);  // wait until finished
		adcValue = ADC; // Read ADC in
		_delay_ms(50);
		transmitByte(adcValue);
		//_delay_ms(1000);
		
		uint8_t scaled_ADC = adcValue / 3;
		FrequencyPWM(10000, scaled_ADC);   // ( frequency , duty cycle % )	
	}	
}
Posted on Leave a comment

A Usable Dark Theme in Eclipse in 10 Seconds

I just spent about 3 hours getting lost in the bottomless toilet that is the Eclipse Preferences menu. For those who are out of the loop, dark themes are like running water and refrigeration. There is no going back to old ways without them. I’d consider ditching the fridge before giving up dark themes. Many IDEs make this easy on you. Sublime Text comes this way. Notepad++ can get you there in 3 seconds. Eclipse has been a disaster. The reason is that Eclipse has their colors busted into an untold number of menus and they seem to look at the theme of the code differently than the theme of their GUI.

Solution
Help > Eclipse Marketplace > Search for “Darkest Dark Theme with DevStyle”

Install it. Do whatever it says. Done

This should have been a default feature in Eclipse. It would have saved me about three hours of horror.

Brandon