Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Timer that will fire at 100-400kHz

Timer that will fire at 100-400kHz

Scheduled Pinned Locked Moved Visual Basic
csharpcsshelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gengel
    wrote on last edited by
    #1

    Good Day, I am busy writing a I2C communication link through the printer port. I need to set up a square wave of 100-400kHz for the I2C clock signal. This is for an EEPROM programmer. I was going to use the windows timer, but the interval only goes down to 1 ms. I need an interval less than 10 to 2.5 nano second. I was trying to use system.timers.timer, but am not sure if this is the correct class for what I need to do. Is there another way to create and interval or a delay in vb.net? Is there an example implementation for sytem.timers.timer? Here is my code for system.timers.timer: Public Class Main Dim WithEvents myTimer As New System.Timers.Timer Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myTimer_Init() AddHandler myTimer.Elapsed, AddressOf myTimer_Run End Sub Sub myTimer_Init() With myTimer .Interval = 0.001 .Enabled = True End With End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click myTimer.Start() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click myTimer.Stop() End Sub Dim counter As Long Sub myTimer_Run() counter += 1 TextBox1.Text = counter.ToString End Sub End Class Error at runtime: Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on.

    G 1 Reply Last reply
    0
    • G gengel

      Good Day, I am busy writing a I2C communication link through the printer port. I need to set up a square wave of 100-400kHz for the I2C clock signal. This is for an EEPROM programmer. I was going to use the windows timer, but the interval only goes down to 1 ms. I need an interval less than 10 to 2.5 nano second. I was trying to use system.timers.timer, but am not sure if this is the correct class for what I need to do. Is there another way to create and interval or a delay in vb.net? Is there an example implementation for sytem.timers.timer? Here is my code for system.timers.timer: Public Class Main Dim WithEvents myTimer As New System.Timers.Timer Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myTimer_Init() AddHandler myTimer.Elapsed, AddressOf myTimer_Run End Sub Sub myTimer_Init() With myTimer .Interval = 0.001 .Enabled = True End With End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click myTimer.Start() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click myTimer.Stop() End Sub Dim counter As Long Sub myTimer_Run() counter += 1 TextBox1.Text = counter.ToString End Sub End Class Error at runtime: Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on.

      G Offline
      G Offline
      gengel
      wrote on last edited by
      #2

      My math was wrong above. its 10 to 2.5 microseconds.

      M 1 Reply Last reply
      0
      • G gengel

        My math was wrong above. its 10 to 2.5 microseconds.

        M Offline
        M Offline
        Michael Bisbjerg
        wrote on last edited by
        #3

        Microseconds... Damn.. Uhm 10^-6.. 0.001 ms... Afaik, VB only works in ms. And then only down to somewhere near 50 or so as an interval for the timer class. So, if you're gonna do that, with microseconds, you'll need another language.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups