コード例 #1
0
 def setUp(self):
     SimTestCase.setUp(self)
     # create analog pin as injector and connect to ADC2
     self.a2pin = pysimulavr.Pin(1.5)  # set to 1.5V level
     self.__net1 = pysimulavr.Net()
     self.__net1.Add(self.a2pin)
     self.__net1.Add(self.dev.GetPin("B4"))  # connect to ADC2
     # create analog pin as injector and connect to ADC3
     self.a3pin = pysimulavr.Pin(1.0)  # set to 1V level
     self.__net2 = pysimulavr.Net()
     self.__net2.Add(self.a3pin)
     self.__net2.Add(self.dev.GetPin("B3"))  # connect to ADC3
コード例 #2
0
 def test_00(self):
     """check adc conversion on free running mode with interrupt"""
     self.assertDevice()
     self.assertStartTime()
     # create analog pin as injector and connect to ADC0
     apin = pysimulavr.Pin(1.0)  # set to 1V level
     net1 = pysimulavr.Net()
     net1.Add(apin)
     net1.Add(self.dev.GetPin(
         self.adc0_pin[self.processorName]))  # connect to ADC0
     # create analog pin as injector and connect to AREF
     rpin = pysimulavr.Pin(2.5)  # set to 2.5V level
     net2 = pysimulavr.Net()
     net2.Add(rpin)
     net2.Add(self.dev.GetPin(
         self.aref_pin[self.processorName]))  # connect to AREF
     # skip initialisation
     self.assertInitDone()
     # check, that we are not in idle loop ...
     self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0,
                      "not in idle loop")
     # run
     self.sim.doRun(self.sim.getCurrentTime() + (16 * self.ADC_CLOCK))
     # check, that we are now in idle loop ...
     self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1,
                      "in idle loop")
     # check adc_value and isr_count to be (0x5555, 0)
     v = self.sim.getWordByName(self.dev, "adc_value")
     c = self.sim.getByteByName(self.dev, "isr_count")
     self.assertEqual(v, 0x5555, "expected adc value is 0x0, got 0x%x" % v)
     self.assertEqual(c, 0, "expected isr_count is 0, got %d" % c)
     # change input value for next conversion
     apin.SetAnalogValue(1.35)
     # run
     self.sim.doRun(self.sim.getCurrentTime() + (14 * self.ADC_CLOCK))
     # check adc_value and isr_count
     self.assertComplete(1.0, 2.5, 1)
     # change input value for next conversion
     apin.SetAnalogValue(0.7)
     # run
     self.sim.doRun(self.sim.getCurrentTime() + (14 * self.ADC_CLOCK))
     # check adc_value and isr_count
     self.assertComplete(1.35, 2.5, 2)
     # run
     self.sim.doRun(self.sim.getCurrentTime() + (14 * self.ADC_CLOCK))
     # check adc_value and isr_count
     self.assertComplete(0.7, 2.5, 3)
コード例 #3
0
ファイル: adc_diff.py プロジェクト: SKZ81/simulavr-Traumflug
 def test_00(self):
   """check adc conversion, differential channel"""
   self.assertDevice()
   self.assertStartTime()
   # create analog pin as injector and connect to ADC1
   a1pin = pysimulavr.Pin(1.0) # set to 1V level
   net1 = pysimulavr.Net()
   net1.Add(a1pin)
   net1.Add(self.dev.GetPin(self.adc1_pin[self.processorName])) # connect to ADC1
   # create analog pin as injector and connect to ADC2
   a2pin = pysimulavr.Pin(1.32) # set to 1.32V level
   net2 = pysimulavr.Net()
   net2.Add(a2pin)
   net2.Add(self.dev.GetPin(self.adc2_pin[self.processorName])) # connect to ADC2
   # create analog pin as injector and connect to ADC3
   a3pin = pysimulavr.Pin(0.4) # set to 0.4V level
   net3 = pysimulavr.Net()
   net3.Add(a3pin)
   net3.Add(self.dev.GetPin(self.adc3_pin[self.processorName])) # connect to ADC3
   # skip initialisation
   self.assertInitDone()
   # check, that we are not in idle loop ...
   self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop")
   # run
   self.sim.doRun(self.sim.getCurrentTime() + (15 * self.ADC_CLOCK))
   # check, that we are now in idle loop ...
   self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop")
   c = self.sim.getByteByName(self.dev, "complete")
   self.assertEqual(c, 0, "conversion is not completed")
   # run, first conversion, channel A2 / A1
   self.sim.doRun(self.sim.getCurrentTime() + (12 * self.ADC_CLOCK))
   # get ADC value
   self.assertComplete(1.32, 1.0, 2.56)
   # start next conversion
   self.sim.setByteByName(self.dev, "complete", 2)
   # run, further conversion, channel A3 / A1
   self.sim.doRun(self.sim.getCurrentTime() + (15 * self.ADC_CLOCK))
   # get ADC value
   self.assertComplete(0.4, 1.0, 2.56)
コード例 #4
0
 def test_00(self):
   """check state of analog comparator (with interrupt)"""
   self.assertDevice()
   self.assertStartTime()
   # create analog pin as injector and connect to D7
   apin = pysimulavr.Pin(1.0) # below bandgap voltage level
   net = pysimulavr.Net()
   net.Add(apin)
   net.Add(self.dev.GetPin(self.ain1_pin[self.processorName])) # connect to AIN1
   if self.processorName == "at90s8515":
     # create analog pin as injector and connect to AIN0, because at90s8515 has no bandgap source to AIN0
     rpin = pysimulavr.Pin(1.5)
     net2 = pysimulavr.Net()
     net2.Add(rpin)
     net2.Add(self.dev.GetPin("B2")) # connect to AIN0
   # skip initialisation
   self.assertInitDone()
   # check, that we are not in idle loop ...
   self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop")
   # get a output pin
   opin = self.dev.GetPin("B0")
   # check initial isr counter
   self.assertEqual(self.sim.getByteByName(self.dev, "isr_count"), 0, "isr counter is 0")
   # run till in idle loop
   self.sim.doRun(self.sim.getCurrentTime() + self.DELAY)
   # check, that we are now in idle loop ...
   self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop")
   # check isr counter is 0
   self.assertEqual(self.sim.getByteByName(self.dev, "isr_count"), 0, "isr counter is 0")
   # check output state
   self.assertEqual(opin.toChar(), "H", "output value wrong: got=%s, exp=H" % opin.toChar())
   # set voltage on apin to 2.0V
   apin.SetAnalogValue(2.0)
   # run
   self.sim.doRun(self.sim.getCurrentTime() + self.DELAY)
   # check output state
   self.assertEqual(opin.toChar(), "L", "output value wrong: got=%s, exp=L" % opin.toChar())
   # check isr counter
   self.assertEqual(self.sim.getByteByName(self.dev, "isr_count"), 1, "isr counter is 1")
コード例 #5
0
 def test_00(self):
     """check adc conversion"""
     self.assertDevice()
     self.assertStartTime()
     # create analog pin as injector and connect to ADC0 input
     apin = pysimulavr.Pin(1.0)  # set to 1V level
     net1 = pysimulavr.Net()
     net1.Add(apin)
     net1.Add(self.dev.GetPin(
         self.adc0_pin[self.processorName]))  # connect to ADC0
     # create analog pin as injector and connect to AREF
     rpin = pysimulavr.Pin(2.5)  # set to 2.5V level
     net2 = pysimulavr.Net()
     net2.Add(rpin)
     net2.Add(self.dev.GetPin(
         self.aref_pin[self.processorName]))  # connect to AREF
     # skip initialisation
     self.assertInitDone()
     # check, that we are not in idle loop ...
     self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0,
                      "not in idle loop")
     # run
     self.sim.doRun(self.sim.getCurrentTime() + (15 * self.ADC_CLOCK))
     # check, that we are now in idle loop ...
     self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1,
                      "in idle loop")
     c = self.sim.getByteByName(self.dev, "complete")
     self.assertEqual(c, 0, "conversion is not completed")
     # run
     self.sim.doRun(self.sim.getCurrentTime() + (12 * self.ADC_CLOCK))
     # get ADC value
     self.assertComplete(1.0, 2.5)
     # start next conversion
     self.sim.setByteByName(self.dev, "complete", 2)
     apin.SetAnalogValue(1.65)
     # run
     self.sim.doRun(self.sim.getCurrentTime() + (15 * self.ADC_CLOCK))
     # get ADC value
     self.assertComplete(1.65, 2.5)
コード例 #6
0
 def test_00(self):
     """check state of analog comparator"""
     self.assertDevice()
     self.assertStartTime()
     # create analog pin as injector and connect to F1 (AIN1 over ADC1)
     a1pin = pysimulavr.Pin(1.0)
     net1 = pysimulavr.Net()
     net1.Add(a1pin)
     net1.Add(self.dev.GetPin(
         self.adc1_pin[self.processorName]))  # connect to AIN1
     # create analog pin as injector and connect to E2 (AIN0)
     a0pin = pysimulavr.Pin(1.8)
     net0 = pysimulavr.Net()
     net0.Add(a0pin)
     net0.Add(self.dev.GetPin(
         self.ain0_pin[self.processorName]))  # connect to AIN0
     # skip initialisation
     self.assertInitDone()
     # check, that we are not in idle loop ...
     self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0,
                      "not in idle loop")
     # get a output pin
     opin = self.dev.GetPin("B1")
     # run till in idle loop
     self.sim.doRun(self.sim.getCurrentTime() + self.DELAY)
     # check, that we are now in idle loop ...
     self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1,
                      "in idle loop")
     # check output state
     self.assertEqual(opin.toChar(), "H",
                      "output value wrong: got=%s, exp=H" % opin.toChar())
     # set voltage on a0pin == AIN0 to 0.3V
     a0pin.SetAnalogValue(0.3)
     # run
     self.sim.doRun(self.sim.getCurrentTime() + self.DELAY)
     # check output state
     self.assertEqual(opin.toChar(), "L",
                      "output value wrong: got=%s, exp=L" % opin.toChar())
コード例 #7
0
 def test_00(self):
     """check port function (I/O)"""
     self.assertDevice()
     self.assertStartTime()
     # create digital pin as injector
     bpin = pysimulavr.Pin()
     bpin.SetPin("L")  # set to L state
     bnet = pysimulavr.Net()
     bnet.Add(bpin)
     # connect to ports
     ports = self.create_connections(bnet)
     # skip initialisation
     self.assertInitDone()
     # check, that we are not in idle loop ...
     self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0,
                      "not in idle loop")
     # run till in idle loop
     self.sim.doRun(self.sim.getCurrentTime() + self.DELAY)
     # check, that we are now in idle loop ...
     self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1,
                      "in idle loop")
     # and 1 time processed the complete loop
     c = self.sim.getByteByName(self.dev, "loop_count")
     self.assertTrue(c > 0, "loop one time processed")
     # check output state
     for p in ports:
         p.assertState("L")
     # set input pin to H
     bpin.SetPin("H")  # set to H state
     # run
     self.sim.doRun(self.sim.getCurrentTime() + self.DELAY)
     c2 = self.sim.getByteByName(self.dev, "loop_count")
     self.assertTrue(c2 > c, "loop count incremented")
     # check output state
     for p in ports:
         p.assertState("H")