Windmill controller logger shield

We can build a Windmill controller and/or logger which monitor the charging regime and also can logg some data regarding to wind speed, windmill rpm and amps, battery voltage, solar panel volts and amps. The harware is heavly based on Piclog, Glenn's Windmill Picaxe logger.

1. The Firmware (Jal program)

The ADC stuff was presented here so, we are discussing about methods on counting pulses, with or without an USB connection.

1.a Counting pulses on positive edge

On many high level pic programming languages (mainly, Basic languages) we have a specific function for counting pulses. It exist on Picaxe Basic, Proton Basic, Pic Basic, Oshonsoft Basic and probably on others which I'm not aware of them. In Jal we don't have such a function which is based on non-blocking delays. Fortunately, in official package is included a library named "timer0_isr_interval.jal" which is doing exactly that: non-blocking delays. In the header of this lib is included an example of how to set a non-blocking delay.

A non-USB example:

-- Counting pulses on positive edge
include freejalduino4.jal
const timer0_isr_rate = 1000 -- 1 kHz isr rate
const DELAY_SLOTS = 1 -- we need only one delay at a time
include timer0_isr_interval
timer0_isr_init() -- init timer0 isr
var bit flag
var word counting -- if more than 65535 counts on 1 second expected,
                      -- use dword type instead of word.
enable_digital_io() -- all pins are now digital
-- define on which pin we do counting
D7_direction = INPUT
flag = 0
counting = 0
forever loop
  -- ======== start the counting procedure ========
  -- start the delay of 1 second on first slot (which is 0)
  set_delay(0, 1000)
  repeat
    if D7 == 1 then -- positive pulse on D7 pin
      flag = 1     -- so, mark it to be counted when pulse will fall
    elsif flag == 1 then -- now D7 is 0 (pulse fallen = complete) and if flag is set,
                         -- we count the pulse
      counting = counting + 1  -- counted! huray, we have a pulse!
      flag = 0     -- ok, clean the flag to be ready for another rising pulse
    end if
  until check_delay(0) -- check the slot to see if delay expired
  -- time expired, we erase the flag
  flag = 0
  -- ============= end the counting procedure ===============
  -- do something with counting variable and then reinitialize it
  -- ok, did something (e.g., sent the value via serial or displayed on LCD)
  counting = 0
end loop

This is the "usual" method of counting pulses on positive edge. Is easy to modify it for the negative edge - an exercise for the reader?

An USB example: Unfortunately, we will loose the USB connection (and the application will be blocked) if there is no activity for a maximum of 10 milliseconds pause. We need to deal with that. Bellow is my proposal. I will not go for a maximum of 10 millisecond delay because it is possible to loose the connection. I will "push" the USB at every 5ms and this is the interval for counting. I will count pulses on 5ms interval and repeat it 200 times to gather 1 second.

-- Counting pulses on positive edge include freejalduino4.jal include usb_serial include print  const timer0_isr_rate = 1000 -- 1 kHz isr rate const DELAY_SLOTS = 1 -- we need only one delay at a time  include timer0_isr_interval timer0_isr_init() -- init timer0 isr  var bit flag var word counting -- if more than 65535 counts on 1 second expected,                       -- use dword type instead of word.  enable_digital_io() -- all pins are now digital  -- define on which pin we do counting D7_direction = INPUT  flag = 0 counting = 0  usb_serial_init()  forever loop   usb_serial_flush()   -- ======== start the counting procedure ========   for 200 loop -- 5 * 200 = 1 second     -- start the delay of 5 milliseconds on first slot (which is 0)     set_delay(0, 5)     repeat       if D7 == 1 then -- positive pulse on D7 pin         flag = 1     -- so, mark it to be counted when pulse will fall       elsif flag == 1 then -- now D7 is 0 (pulse fallen = complete) and if flag is set,
                           -- we count the pulse         counting = counting + 1 -- counted! huray, we have a pulse!         flag = 0     -- ok, clean the flag to be ready for another rising pulse       end if     until check_delay(0) -- check the slot to see if delay expired     usb_serial_flush() -- tell to the usb we are active   end loop   -- cycle ended, we erase the flag   flag = 0   -- ============= end the counting procedure ===============    -- do something with counting variable and then reinitialize it   print_word_dec(usb_serial_data, counting)   -- use print_dword_dec() if counting exceed 65535   usb_serial_data = 13 -- cr   usb_serial_data = 10 -- lf   counting = 0 end loop 

Why not a 10 millisecond delay? Well, we can try that anyway but is not about an exact delay as is a blocking one (delay_1ms(10)). We start the timer, we do other things then check if the timer has finished his counting. If you get over 10ms, then you may loose USB connection so, 5ms is better.

2. The Hardware

-- not yet available --