Menu

interrupt and variable frequency

2020-07-15
2020-07-25
  • stan cartwright

    stan cartwright - 2020-07-15
     
  • stan cartwright

    stan cartwright - 2020-07-15

    I want to make a strobed water fountain as a project.
    First an apology to mkstevo for posting on his project,
    I thought he would be interested. Anyway..
    It needs a pump and water .. sorted.
    It needs a variable strobe. This works.

    #chip mega328p,16
    #option Explicit
    #define leds portd.7
    #define potentiom portc.0
    dir potentiom in
    dir leds out
    dim potval as byte
    do
      potval=readad (potentiom)
      wait 18 ms
      wait potval 10us
      pulseout leds,1 ms
    loop
    

    This gives a variable frequency strobe over a few Hz. around the frequency the water drops
    BUT it's a stand alone program.
    searching for info about strobe fountainis incomplete.
    I should use a solenoid valve running under pwm it seems to control water droplets size.
    Well.., a 12V solenoid valve is mechanical and the strobe is around 50Hz. so it's pwm is 50Hz.
    This works for 50Hz. pwm for the solenoid.

    #chip mega328p,16
    #option Explicit
    #include <millis.h>
    #define drop_solenoid portd.6
    dir drop_solenoid out
    #define drop_size_pot portc.1
    dir drop_size_pot in
    dim valve_pot_val  as byte
    dim millis_tmp as long
    millis_tmp = millis()
    do
    ;drop_solenoid pwm.. ie droplet size
      if millis() - millis_tmp >= 20 then ;every 20ms
        millis_tmp = millis() ;reset millis_tmp
        valve_pot_val = scale (readad (drop_size_pot),0,255,0,20)
        pulseout drop_solenoid , valve_pot_val ms ;open valve for drop_size_pot time
      end if
    loop
    

    A pot connected to portc.1 changes the portd.6 on time..
    ie. the valve on/off time and so the droplet size....in theory :)

    Trouble is I can't join the two programs to make one. 2 evenings and no luck.
    It's the variable strobe that is giving me gip. It's very interesting but a bit frustrating.
    I think another approach is needed. Any suggestions welcome.

     

    Last edit: stan cartwright 2020-07-15
  • stan cartwright

    stan cartwright - 2020-07-15

    I think looking at the interrupt demos again might help.
    I don't really understand wait or pulseout.
    I know interrupts still run while wait is running. Not sure about pulseout.

    White leds for the strobe.
    only on for 1mS every 20mS so 0.05 % the power...
    so run at 6V.
    I digress. I have a lamp that came from a shop where everything is £1.
    72 leds in parallel running straight off 4 x 1.5V AA cells.
    I noticed the battery voltage dropped to 3.6V.
    At 50Hz they could run at 6V maybe? ... all part of the project.
    I sent off for 100 white leds.

     
  • stan cartwright

    stan cartwright - 2020-07-18

    After too many hours trying, I am back at my original code for a strobe from 45 to 53 Hz
    I will use 2 arduino nanos..one for the strobe frequency and another for the valve 50Hz on time.
    I spent too long getting it to work on 1 uno.
    I found using 2 timers seems to work. Pity interrupt values are not variable or maybe they are.

    do
      potval=readad (potentiom)
      wait 18 ms
      wait potval 10us
      pulseout leds,1 ms
    loop
    
     
  • stan cartwright

    stan cartwright - 2020-07-25

    I finally joined the variable 46Hz to 54Hz 1ms pulse strobe and the pwm for the solenoid valve
    which is on for 1ms to 19ms every 20ms.
    I used an every 1ms timer0 interrupt for the valve...
    which runs during the main do wait pulseout loop.

    #chip mega328p,16
    #option explicit
    #define valve portd.6
    #define strobe portd.7
    #define drop_size_pot portc.0
    #define strobe_pot portc.1
    dir valve out
    dir strobe out
    dir drop_size_pot in
    dir strobe_pot in
    dim valve_pot_val , mills_counter , strobe_pot_val as byte
    ;-------------------------------
    ;start 1ms interrupt isr
        On Interrupt Timer0Match1 Call valve_isr
        Dim OCR0  AS byte alias OCR0A
        Dim TCCR0 AS  byte alias TCCR0B
        WGM01 = 1
        OCR0 = 249 ;1ms
        TCCR0 = 0x28
        TCCR0 = TCCR0 or 0x03
    '--------------
    do
    ;read strobe pot
      strobe_pot_val = readad (strobe_pot)
      wait 17300 us
      wait strobe_pot_val 10us
      pulseout strobe,1 ms
    ;read valve pot
      valve_pot_val = scale(readad (drop_size_pot),0,255,1,19)
    loop
    ;---------------
    Sub valve_isr ;called every 1mS
      mills_counter ++
      if mills_counter = 20 then
          mills_counter = 0
          set valve on
      else if mills_counter = valve_pot_val then
          set valve off
      end if
    End Sub
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.