Showing posts with label avr. Show all posts
Showing posts with label avr. Show all posts

Sunday, 13 October 2013

Peristaltic Pumps

This is a quick knock up circuit I did on http://circuits.io/

The AT-Tiny uses three wires RX, TX & GND to communicate with the controller. The protocol will say which pump 1-4 and how many mL and the At-Tiny will take care of the rest. Just keep the Enable lines up, no need to for anything else as we're not changing direction or anything. I've left off the possible 4th pump as I haven't got one.

Regular pumps with flow meter

Because of varying head heights of the water storage, return from recycling, etc. issues I have chosen to use a flow meter to regulate water input. The idea being that all water input pumps can be pumping together and shut off once the required amount has been delivered. The flow meter introduces an additional complexity because the flow meter instructions say that the water speed should rise gradually and that air should be prevented from enterting the system. My pumps will be submersed so I'm not sure that will be an issue. For this discussuion that's not really an issue because that is a software problem likely to be quite simple by just modualting the control line.

The flow meter produces 1120 pulses per litre and takes a TTL supply voltage.

This circuit activates either pump, watches the flow pulses and then kills all pumps when the required flow is complete.

Friday, 11 October 2013

Useful pdf about interrupts and clocks

Found a useful reference for interrupts and clocks with good examples of setting all the bits to get them working properly. Handy if you've not done it for a couple o'years like me.
But watch out, the = print as - in Mozilla PDF reader!

Thursday, 10 October 2013

NXP signalling the AVR

I spent an eternity reading PortD instead of PinD. Thank goodness for the power of web searching. Shame everyone programs in C. They are scared of the power.

NXP code


DigitalOut m1(LED1);
DigitalOut m2(LED2);

DigitalInOut DATA(p21);
DigitalInOut CTL(p23);

void set_data(unsigned char i) {
    DATA.write(i);
    m1.write(i);
}

void set_ctl(unsigned char i) {
    CTL.write(i);
    m2.write(i);
}

int main() {
    CTL.output();
    DATA.output();
    
    while(1) {
        set_data(0);
        set_ctl(1);
        wait(3);
        set_data(1);
        set_ctl(0);
        wait(2);
    }
 }

AVR Code

.include "m16def.inc"

; set portB to output
ser r16
out ddrb, r16
clr r16
out portb, r16

; set portD to input with pull-ups
out portd, r16
out ddrd, r16
ser r16
out portd, r16

; do the do
main:
    in r16, pind
    out portb, r16
    rjmp main

Wednesday, 9 October 2013

AVR signalling the NXP

The NXP code is pretty basic

#include "mbed.h"

DigitalOut led(LED1);
DigitalIn DATA(p23);

int main() {
    
    while(1) {
        led.write(0);
        while(DATA);
        led.write(1);
        while(!DATA);
    }
}

The AVR code was a bit trickier as it uses the timer interrupt. Took me a while to get my head round it

.include "TN13DEF.INC"

.org 0000   ;  reset interrupt vector
  rjmp on_reset

.org 0012   ;  timer0 overflow interrupt vector
  rjmp tim0_overflow

on_reset:
  ser r16
  out ddrb, r16 ; set the pin I/O

  ldi r16, 0b_0000_0101 ; set the clock multiplier
  out tccr0b, r16

  ldi r16, 0b_0000_010 ; turn the timer on
  out timsk0, r16

  sei ; turn on interrupts

main:
  nop ; I walk and walk, do nothing 
  rjmp main

tim0_overflow:
  ; negate portb
  in r17, portb
  com r17
  out portb, r17
  reti

Getting the AT-Tiny working with the STK500

Fairly simple, follow online instructions.

  1. AT-TINY13 in SCKT3400D1
  2. Connect the ISP6PIN socket to SPROG1 with the 6-pin cable provided
  3. Connect the PORTE/RST to PORTB/PB5 and PORTE/XT1 to PORTB/PB3
  4. Jumpers VTARGET, AREF, RESET, XTAL1, OSCSEL close; others open

Using it is a bit annoying because you have to take the cables on and off to use the pins.