'**************************************************************************** '* My first attempts to writing code for a 16 bit PIC * ' *************************************************************************** ' NOTE: Pickit3 must be used for programming these devices! ' Each interrupt has its own handler, simply write one handler for each interrupting ' device without having to work out which interrupt it is. ' Timers are more logical: you specify the count going upwards that will trigger an _ ' interrupt rather than working out when the counter would underflow. ' '01.08.2016: Test and debug board designed, etched and soldered. ' Programming requires the PiCkit3 programmer. PicKit2 does not work! '02.08.2016: 1M resistor added over X-tal pins '03.08.2016: Finaly got the clock up and running on the X-tal ' Working out the MIDI UART now. ' Midi-in buffering implemented. ' Trying to use the pwm channels... we cannot use the HPWM commands... ' Implementing velocity control with timers ' Repeats working now. ''------------------------------------------------------------------------------------------------------------- ' START: ' Config FWD = FWDTEN_OFF, PLLKEN_ON, WDTPOST_PS512, WDTPRE_PR128, WINDIS_OFF ' Config FOSC = FCKSM_CSECME, IOL1WAY_OFF, OSCIOFNC_ON, POSCMD_NONE ' Config FOSCSEL = FNOSC_FRCPLL, IESO_OFF ' Config FGS = GCP_OFF, GWRP_OFF ' [end from forum] Device = 24EP128MC202 Clear Config FPOR = ALTI2C1_OFF, ALTI2C2_OFF ' unsure about this Config FWDT = WDTPOST_PS256, WINDIS_OFF, PLLKEN_ON, FWDTEN_OFF ' unsure about his ' first try to configure the clock... ' select internal FRC at POR not using PLL: Config FOSCSEL = FNOSC_FRC, IESO_OFF DelayMS 10 ' make sure we assign the correct pins to use for the ICD (Pickit3) Config FICD = ICS_PGD1, JTAGEN_OFF ' this sets the pins used for the programmer ' enable clock switching and configure POSC for XT mode with 10MHz crystal Config FOSC = FCKSM_CSECMD, OSCIOFNC_OFF, POSCMD_XT Main_Setup: ' configure PLL prescaler, PLL postscaler, PLL divisor PLLFBD = 46 CLKDIV.7 = 0 'PLLPOST N2=2 CLKDIV.6 = 0 CLKDIV.0 = 0 'PLLPRE N1=2 CLKDIV.1 = 0 CLKDIV.2 = 0 CLKDIV.3 = 0 CLKDIV.4 = 0 Write_OSCCONH ($3) ' = __builtin_write_OSCCONH(0x03) Write_OSCCONL (OSCCON | %1) ' = __builtin_write_OSCCONL(OSCCON | 0x01) PLL_Setup(48, 2, 2, $0300) ' should set it to 120MHz operation with 10MHz X-tal ' Fosc = 10MHz * 48 / 2 * 2 = 120MHz ' now we get a 10MHz clock signal on pin OSC2, pin10... DelayMS 1000 ' wait for stability ' wait for the clock switch to occur: 'while OSCCON & %0111000000000000 = %0011000000000000 ' mask for COSC bits 14-12 'wend ' wait for pll to lock ' this is done in de PLL_setup macro 'while osccon.5 = 1 'wend Declare Xtal = 120 ' set to Fosc Declare CCP1_Pin PORTB.15 ' pwm1L ' makes no sense as we cannot use HPWM here Declare CCP2_Pin PORTB.14 ' pwm1H Declare CCP3_Pin PORTB.13 ' pwm2L Declare CCP4_Pin PORTB.12 ' pwm2H Declare CCP5_Pin PORTB.11 ' pwm3L 'Declare CCP6_Pin PORTB.10 ' pwm3H 'Declare Hserial_Baud = 31250 ' USART1 baud rate - set to MIDI 'Declare Hrsout1_Pin = PORTB.8 ' RP40 ' Select the pin for TX with USART1 'Declare HRSin1_Pin = PORTB.9 ' RP41 PPS_Output(cOut_Pin_RP40, cOut_Fn_U1TX) ' Map UART1 TX pin to RP40 'RP35 PPS_Input(cIn_Pin_RP41, cIn_Fn_U1RX) ' Map UART1 RX pin to RP41 'RPI34 ' constant declarations and port-assignments: Symbol overrun_error_led PORTB.7 Symbol framing_error_led PORTA.4 Symbol midi_led PORTB.4 Symbol debug_led PORTB.5 ' this is pin 14 Symbol loopcnt PORTB.6 ' this is pin 15 'initialisations for the midi input parser: Symbol Midichannel = 12 ' robot_Channel Symbol NoteOff_Status = 128 + Midichannel ' 2 bytes follow Symbol NoteOn_Status = 144 + Midichannel Symbol Keypres_Status = 160 + Midichannel Symbol Control_Status = 176 + Midichannel Symbol ProgChange_Status = 192 + Midichannel ' 1 byte message Symbol Aftertouch_Status = 208 + Midichannel ' 1 byte follows Symbol Pitchbend_Status = 224 + Midichannel ' lsb msb follow ' port I/O settings: TRISA = %101111 ' set to input TRISB = %1111111100001111 Output overrun_error_led Output framing_error_led Output midi_led Output debug_led Output loopcnt ' init timer1: IFS0bits_T1IF = 0 ' clear Timer1 interrupt flag IPC0bits_T1IP0 = 0 ' set priority IEC0bits_T1IE = 1 ' Enable the Timer1 interrupt TMR1 = 0 ' clear the count PR1 = 65535 ' load Timer1 period T1CON = %1000000000110000 ' pre-scale 256. bit 15 is "start" ' init UART1-receiver: 31250 Baud ' should generate an interrupt for each byte received U1MODE.0 = 0 ' = U1MODEbits.STSEL = 0 ' 1 stop-bit U1MODE.1 = 0 ' U1MODEbits.PDSEL = 0 ' 8 bit no parity U1MODE.2 = 0 U1MODE.5 = 0 ' =U1MODE_bits.ABAUD = 0 ' no autobauding U1MODE.3 = 0 ' = U1MODEbits.BRGH =0 ' 0 = standard speed mode - 16 clocks per bit U1MODE.4 = 0 ' logic high is the idle state for the input serial data (default) U1MODE.7 = 0 ' wakeup disabled U1MODE.8 = 0 U1MODE.9 = 0 U1BRG = 119 ' 239 ' voor 120MHz 119 ' voor 60MHz ((60000000 / Hserial_baud) / 16) - 1 ' BRGVAL U1STA.5 = 0 ' no bit8 U1STA.6 = 0 ' U1STAbits.URXISEL = 0 ' receive interrupt mode selection bits U1STA.7 = 0 ' interrupt flag is set when a byte is received U1STA.10 = 1 ' Transmit enable bit U1MODE.15 = 1 '=U1MODEbits.UARTEN = 1 U1MODE.12 = 0 ' disable IrDA IEC0.11 = 1 ' enable IRQ for receiver IEC4.1 = 1 ' enable IRQ for error trapping on receiver ' --------------------------- ' variable declarations: ' Dim timer_flag As Bit ' Dim cnt As Byte ' variables for midi reception and parsing: Dim inByte As Byte Dim IndexIn As Byte 'System ' Pointer to the next empty location in the buffer Dim IndexOut As Byte 'System ' Pointer to the location of the oldest character in the buffer Dim Ringbuffer[256] As Byte ' Array for holding received characters in the uart Dim Bytein As Byte 'System ' midi byte read from buffer Dim StBit As Bytein.7 ' highest bit of ByteIn ' midi variables Dim statusbyte As Byte 'System Dim noteUit As Byte 'System ' note off + release value Dim release As Byte 'System Dim noteAan As Byte 'System ' note on + release value Dim velo As Byte 'System Dim notePres As Byte 'System ' note pressure + pressure value Dim pres As Byte 'System Dim Ctrl As Byte 'System ' continuous controller + value Dim value As Byte 'System Dim prog As Byte 'System ' program change + program-byte Dim aft As Byte 'System ' channel aftertouch Dim pblsb As Byte 'System ' pitch bend lsb Dim pbmsb As Byte 'System ' pitch bend msb ' variables for the timing system: Dim time As Dword ' 10 us resolution Dim maxtim As time.31 ' overflow bit, will cause timer reset after 6 hours Dim t As Word ' loopcounter 750kHz Dim tl As t.Byte0 Dim th As t.Byte1 Dim i As Byte Dim idx As Byte Dim Nxt As Dword Dim TimVals[8] As Dword Dim tg As Bit Dim resort_flag As Bit Dim Dur[128] As Word Dim Dur5[128] As Word Dim notes As Word Dim VelFlags As Word Dim velo0 As Byte Dim velo1 As Byte Dim velo2 As Byte Dim velo3 As Byte Dim pres0 As Byte Dim pres1 As Byte Dim pres2 As Byte Dim pres3 As Byte Clear Ringbuffer Clear IndexIn ' Clear the buffer internal pointer Clear IndexOut ' Clear the buffer external pointer Clear time Clear t GoSub Dur_Lookup Set TimVals GoTo MAIN ' jump over irq's Isr- T1Interrupt ' timer1 interrupt IFS0bits_T1IF = 0 ' Reset the Timer1 interrupt flag Toggle debug_led EndIsr- ' exit the interrupt Isr- U1RXInterrupt ' UART receive IRQ - midi receiver 'IEC0bits_U1RXIE = 0 ' that's the irq enable flag! 'IFS0bits_U1RXIE Clear IFS0.11 ' reset UART1 receive irq flag Inc IndexIn ' Move up the buffer index (0-255) Ringbuffer[IndexIn] = U1RXREG 'Toggle midi_led 'debug EndIsr- Isr- U1ErrInterrupt ' this irq is generated on UART1 receive errors ' this interrupt is enabled by setting IEC4.1 ' error handling: Clear IFS4.1 ' clear interrupt flag If U1STA.2 = 1 Then Set framing_error_led EndIf If U1STA.1 = 1 Then ' = overrun error Set overrun_error_led ' not happening Clear U1STA.1 EndIf EndIsr- Isr- U1TXInterrupt ' UART send IRQ IEC0bits_U1TXIE = 0 ' reset UART1 transmit IRQ flag EndIsr- ' attempt to use a procedure... ' Proc GetMidi (byval IndexIn as byte, Byref IndexOut as word, Byref RingBuffer as word) , byte ' ' read procedure for incoming buffered midi bytes ' ' is Indexout and IndexIn global? ' If IndexIn <> Ptr8(IndexOut) then ' inc Ptr16(IndexOut) ' Result = Ptr8(Ringbuffer +IndexOut) ' else ' Result = 255 ' no new byte came in ' endif ' endproc GetMidi: If IndexIn <> IndexOut Then Inc IndexOut Bytein = Ringbuffer[IndexOut] Else Set Bytein EndIf Return MAIN: While Inc t ' word-var If tl.7 <> tg Then ' at 750kHz loopspeed tg.4 gives a time resolution of ca. 10 us ?? tg = tl.7 ' tl is low byte of t 'toggle loopcnt ' geeft pulsetijden van 1.3us Inc time ' with 1.3us pulses, this will overflow after 5583 seconds = 1.5 hours EndIf 'Bytein = GetMidi (IndexIn,IndexOut,Ringbuffer) ' Read data from the serial buffer GoSub GetMidi ' Start the midi parser. Midi_Parse: If Bytein > Pitchbend_Status Then ' here higher statusses are not implemented. If Bytein > 253 Then '254 = midiclock, 255= reset 'midiclock can interrupt all other msg's... '255 had to be intercepted since thats what we 'get when no new byte flows in. Else Clear statusbyte 'reset the status byte EndIf GoTo Midi_Parse_done 'throw away... EndIf If StBit =1 Then 'should be faster than If Bytein > 127 Then 'status byte received, bit 7 is set Clear statusbyte 'if on another channel, the statusbyte needs a reset Select Bytein 'eqv to Select case ByteIn Case NoteOff_Status statusbyte = Bytein Set noteUit 'reset value. Cannot be 0 !!! Set release '0 is a valid midi note! Case NoteOn_Status statusbyte = Bytein Set noteAan '= 255 Set velo '= 255 Case Keypres_Status statusbyte = Bytein notePres = 255 pres = 255 Case Control_Status ' controllers and switches statusbyte = Bytein Set Ctrl Set value Case ProgChange_Status ' could be used for different lookup tables statusbyte = Bytein prog = 255 Case Aftertouch_Status ' not used on this board statusbyte = Bytein Set aft Case Pitchbend_Status ' used for saw bending positioning statusbyte = Bytein pblsb = 255 pbmsb = 255 EndSelect Else 'midi byte is 7 bits Select statusbyte Case 0 'not a message for this channel GoTo Midi_Parse_done 'Check_Timers 'disregard Case NoteOff_Status If noteUit = 255 Then noteUit = Bytein Else release = Bytein 'message complete, so we can do the action... Select noteUit Case 120 ' HPWM 1, 0, 2000 Low PORTB.15 Clear VelFlags.0 Clear notes.0 Set TimVals[0] Set resort_flag Case 121 ' HPWM 2, 0, 2000 Low PORTB.14 Clear VelFlags.1 Clear notes.1 Set TimVals[1] Set resort_flag Case 122 ' HPWM 3, 0, 2000 Low PORTB.13 Clear VelFlags.2 Clear notes.2 Set TimVals[2] Set resort_flag Case 123 ' HPWM 4, 0, 2000 Low PORTB.12 Clear VelFlags.3 Clear notes.3 Set TimVals[3] Set resort_flag Case 124 ' hpwm 5, 0, 2000 Low PORTB.11 Case 125 ' hpwm 6, 0, 2000 Low PORTB.10 EndSelect Set noteUit 'reset EndIf Case NoteOn_Status If noteAan = 255 Then noteAan = Bytein Else velo = Bytein If velo = 0 Then ' note off via velo=0 Select noteAan Case 120 ' HPWM 1, 0, 2000 Low PORTB.15 Clear VelFlags.0 Clear notes.0 Set TimVals[0] Set resort_flag Case 121 ' HPWM 2, 0, 2000 Low PORTB.14 Clear VelFlags.1 Clear notes.1 Set TimVals[1] Set resort_flag Case 122 ' HPWM 3, 0, 2000 Low PORTB.13 Clear VelFlags.2 Clear notes.2 Set TimVals[2] Set resort_flag Case 123 ' HPWM 4, 0, 2000 Low PORTB.12 Clear VelFlags.3 Clear notes.3 Set TimVals[3] Set resort_flag Case 124 ' HPWM 5, 0, 2000 Low PORTB.11 Case 125 ' HPWM 6, 0, 2000 Low PORTB.10 EndSelect Else Select noteAan Case 120 ' HPWM 1, velo + velo, 5000 velo0 = velo High PORTB.15 If velo < 127 Then Set notes.0 Set VelFlags.0 TimVals[0] = time + Dur[velo0] Set resort_flag Else Clear notes.0 Clear VelFlags.0 EndIf Case 121 ' HPWM 2, velo + velo, 5000 High PORTB.14 velo1 = velo If velo < 127 Then Set notes.1 Set VelFlags.1 TimVals[1] = time + Dur[velo1] '10 Set resort_flag Else Clear notes.1 Clear VelFlags.1 EndIf Case 122 ' HPWM 3, velo + velo, 10000 High PORTB.13 velo2 = velo If velo < 127 Then Set notes.2 Set VelFlags.2 TimVals[2] = time + Dur[velo2] '10 Set resort_flag Else Clear notes.2 Clear VelFlags.2 EndIf Case 123 ' HPWM 4, velo + velo, 10000 High PORTB.12 velo3 = velo If velo < 127 Then Set notes.3 Set VelFlags.3 TimVals[3] = time + Dur[velo3] Set resort_flag Else Clear notes.3 Clear VelFlags.3 EndIf Case 124 ' HPWM 5, velo + velo, 15000 High PORTB.11 Case 125 ' HPWM 6, velo + velo, 15000 High PORTB.10 EndSelect Set noteAan '= 255 EndIf EndIf Case Keypres_Status If notePres = 255 Then notePres = Bytein Else pres = Bytein GoSub KeyPres EndIf Case Control_Status 'this is where the action takes place for controllers If Ctrl = 255 Then Ctrl = Bytein Else value = Bytein GoSub Controller EndIf Case ProgChange_Status ' not used for Flex If prog = 255 Then 'single byte message prog = Bytein GoSub ProgChange EndIf Case Aftertouch_Status ' not used for flex If aft = 255 Then aft = Bytein GoSub Aftertouch EndIf Case Pitchbend_Status ' used for position control in flex If pblsb = 255 Then pblsb = Bytein Else pbmsb = Bytein GoSub Pitchbend EndIf EndSelect EndIf Midi_Parse_done: If resort_flag= 1 Then GoSub SortTimers EndIf Check_Timers: If idx < 4 Then ' we moeten alleen checken wanneer er een timer loopt If time >= Nxt Then ' nagaan of de eerstvolgende timer afgelopen is... ' in dit geval is de eerste timer afgelopen en moeten we de juiste aktie ondernemen: Set Nxt.31 ' timer reset, is immers afgelopen ' aan de hand van idx weten we welke timer dit is Select idx Case 0 Toggle LATB.15 TimVals[0] = time + Dur[velo0] Case 1 Toggle LATB.14 TimVals[1] = time + Dur[velo1] Case 2 Toggle LATB.13 TimVals[2] = time + Dur[velo2] Case 3 Toggle LATB.12 TimVals[3] = time + Dur[velo3] 'Case Else ' ' in dit geval is idx geset ' GoTo jumpout EndSelect GoSub SortTimers ' find a new nxt and idx EndIf ' beveiliging tegen overflow crashes... If maxtim = 1 Then Clear time Clear notes Set TimVals EndIf Else ' idx > 2, no timers running, so to avoid overflows, we can reset the loop timer If maxtim = 1 Then Clear time ' 16.06.2015 EndIf 'Toggle loopcnt ' for loopspeed measurement: 1.3us now 'Inc cnt 'HRSOut cnt ' lijkt te werken, maar we moeten de baudrate checken... Wend SortTimers: 'look up the next smallest timer value in the Timvals array ' zoek de de volgende kleinste timer waarde: Set idx ' makes it 255 Set Nxt.31 ' nxt is set on entry. - for speed, we just set the highest bit For i = 0 To 7 If TimVals[i] < Nxt Then Nxt = TimVals[i] ' 8 dword comparisons idx = i EndIf Next i Clear resort_flag Return ' ************************************************************************************** ' procedures for midi receiver: KeyPres: ' used for bow pressure pwm and motor speed modulation Select notePres ' CASE epos, estretch, eBend ' change to Pipos for the other board ' ' used to modulate motor speed ' IF mot_enable = 0 THEN ' the motor must be running of course ' SollSpeed = pres ' regardless direction of rotation ' IF SollSpeed <> MotSpeed THEN ' Period = Freqs[MotSpeed] ' TimVals[2] = time + Dur5[RampSpeed] ' SET resort_flag ' we do need to resort here ' EndIf ' EndIf ' CASE Beat_Motor_e ' ' on the condition that the note is on! ' IF notes.3 = 1 THEN ' HPWM 1, pres, fPwm ' EndIf ' CASE Beat_Motor_e2 ' IF notes.4 =1 THEN ' HPWM 2, pres, fPwm ' EndIf ' CASE Beater_e1 ' ' should program the repetition rate - notes.0 flag ' pres0 = pres ' CASE Beater_e2 ' pres1 = pres ' ' should program the repetition rate - notes.1 flag EndSelect Set notePres '= 255 Return ProgChange: ' not implemented here. Set prog '= 255 'this is not realy required Return Pitchbend: Set pblsb Set pbmsb Return Aftertouch: 'this is the channel aftertouch, affecting any playing note 'not implemented here. Set aft ' reset Return Controller: Select Ctrl Case 30 ' can be used for global repeat frequency pres0 = value ' repeat rates pres1 = value Case 66 'on/off for the robot If value = 0 Then 'CLEAR PowerOn 'CC66.0 =0 GoSub PowerDown Else 'SET PowerOn 'CC66.0 =1 EndIf Case 123 ' all notes off - no controller resets Clear notes Clear VelFlags Set resort_flag Set TimVals ' stop timers EndSelect Set Ctrl 'mandatory reset Return PowerDown: Clear VelFlags 'stop all running timers Clear notes Set resort_flag Clear velo0 Clear velo1 Clear pres0 Clear pres1 Set TimVals Return 'How often will the LED flash? ' The clock is 80Megs (I know it's 79.23 but 80 is easier to work with) ' The prescale (bits 4,5 in T1CON) is set at 256 (both bits set). And the timer is fed from the system clock/2 ' So 40,000,000/256 is 156,250 per second (into the timer) ' And the timer is dividing this by 65535 (max value) giving 2.38 per second ' So the LED will be toggled 2.4 times a second, which means it will be on for about half a second and off for the same. ' I think that this is the slowest you can get a single 16 bit timer to run with an 80meg clock. ' The datasheet shows that you can link two timers to form a 32 bit unit. ' Don't forget that these babies do one instruction every two clocks, that's 40 million instructions a second. Dur_Lookup: 'lookup for experiment. 1 dur unit is now 2.3us Set Dur[0] Dur[1]= 23674 ' freq= 2.11202162710146 ' 56ms - 17.8 Hz Dur[2]= 22917 ' freq= 2.18178644674259 Dur[3]= 22548 ' freq= 2.21749157353202 Dur[4]= 22185 ' freq= 2.25377507324769 Dur[5]= 21827 ' freq= 2.29074082558299 Dur[6]= 21475 ' freq= 2.32828870779977 Dur[7]= 21129 ' freq= 2.36641582658905 Dur[8]= 20789 ' freq= 2.40511809129828 Dur[9]= 20454 ' freq= 2.44450963136795 Dur[10]= 20124 ' freq= 2.48459550785132 Dur[11]= 19800 ' freq= 2.52525252525252 Dur[12]= 19481 ' freq= 2.56660335711719 Dur[13]= 19167 ' freq= 2.60865028434288 Dur[14]= 18858 ' freq= 2.65139463357726 Dur[15]= 18554 ' freq= 2.69483669289641 Dur[16]= 18255 ' freq= 2.73897562311695 Dur[17]= 17961 ' freq= 2.7838093647347 Dur[18]= 17672 ' freq= 2.82933454051607 Dur[19]= 17387 ' freq= 2.87571173865532 Dur[20]= 17107 ' freq= 2.92278014847723 Dur[21]= 16831 ' freq= 2.97070881112233 Dur[22]= 16560 ' freq= 3.01932367149758 Dur[23]= 16293 ' freq= 3.06880255324372 Dur[24]= 16030 ' freq= 3.11915159076731 Dur[25]= 15772 ' freq= 3.17017499365965 Dur[26]= 15518 ' freq= 3.22206469905916 Dur[27]= 15268 ' freq= 3.27482315954938 Dur[28]= 15022 ' freq= 3.32845160431367 Dur[29]= 14780 ' freq= 3.382949932341 Dur[30]= 14542 ' freq= 3.43831660019254 Dur[31]= 14307 ' freq= 3.4947927587894 Dur[32]= 14077 ' freq= 3.55189315905378 Dur[33]= 13850 ' freq= 3.6101083032491 Dur[34]= 13627 ' freq= 3.66918617450649 Dur[35]= 13407 ' freq= 3.72939509211606 Dur[36]= 13191 ' freq= 3.79046319460238 Dur[37]= 12978 ' freq= 3.85267375558638 Dur[38]= 12769 ' freq= 3.91573341686898 Dur[39]= 12564 ' freq= 3.97962432346386 Dur[40]= 12361 ' freq= 4.04498017959712 Dur[41]= 12162 ' freq= 4.1111659266568 Dur[42]= 11966 ' freq= 4.17850576633796 Dur[43]= 11773 ' freq= 4.24700586086809 Dur[44]= 11583 ' freq= 4.31667098333765 Dur[45]= 11397 ' freq= 4.38711941739054 Dur[46]= 11213 ' freq= 4.45910996165165 Dur[47]= 11032 ' freq= 4.53226976069616 Dur[48]= 10855 ' freq= 4.60617227084293 Dur[49]= 10680 ' freq= 4.6816479400749 Dur[50]= 10508 ' freq= 4.75827940616673 Dur[51]= 10338 ' freq= 4.83652544012381 Dur[52]= 10172 ' freq= 4.91545418796697 Dur[53]= 10008 ' freq= 4.99600319744204 Dur[54]= 9846 ' freq= 5.07820434694292 Dur[55]= 9688 ' freq= 5.16102394715111 Dur[56]= 9532 ' freq= 5.24548887956357 Dur[57]= 9378 ' freq= 5.33162721262529 Dur[58]= 9227 ' freq= 5.4188793757451 Dur[59]= 9078 ' freq= 5.50782110597048 Dur[60]= 8932 ' freq= 5.59785042543663 Dur[61]= 8788 ' freq= 5.68957669549385 Dur[62]= 8646 ' freq= 5.78302105019662 Dur[63]= 8507 ' freq= 5.87751263665217 Dur[64]= 8370 ' geeft nu 20ms pulsen freq= 25Hz 03.08.2016 '5.973715651135 Dur[65]= 8235 ' freq= 6.07164541590771 Dur[66]= 8102 ' freq= 6.17131572451246 Dur[67]= 7972 ' freq= 6.27195183140993 Dur[68]= 7843 ' freq= 6.37511156445238 Dur[69]= 7717 ' freq= 6.47920176234288 Dur[70]= 7593 ' freq= 6.58501251152377 Dur[71]= 7470 ' freq= 6.69344042838019 Dur[72]= 7350 ' freq= 6.80272108843537 Dur[73]= 7231 ' freq= 6.91467293597013 Dur[74]= 7115 ' freq= 7.02740688685875 Dur[75]= 7000 ' freq= 7.14285714285714 Dur[76]= 6888 ' freq= 7.25900116144018 Dur[77]= 6777 ' freq= 7.37789582411096 Dur[78]= 6667 ' freq= 7.49962501874906 Dur[79]= 6560 ' freq= 7.62195121951219 Dur[80]= 6454 ' freq= 7.74713356058258 Dur[81]= 6350 ' freq= 7.8740157480315 Dur[82]= 6248 ' freq= 8.00256081946223 Dur[83]= 6147 ' freq= 8.13404912965674 Dur[84]= 6048 ' freq= 8.26719576719577 Dur[85]= 5951 ' freq= 8.40194925222652 Dur[86]= 5855 ' freq= 8.5397096498719 Dur[87]= 5760 ' freq= 8.68055555555555 Dur[88]= 5668 ' freq= 8.82145377558222 Dur[89]= 5576 ' freq= 8.96700143472023 Dur[90]= 5486 ' freq= 9.11410864017499 Dur[91]= 5398 ' freq= 9.26268988514264 Dur[92]= 5311 ' freq= 9.41442289587648 Dur[93]= 5225 ' freq= 9.56937799043062 Dur[94]= 5141 ' freq= 9.72573429293912 Dur[95]= 5058 ' freq= 9.88533017002768 Dur[96]= 4977 ' freq= 10.0462125778581 Dur[97]= 4897 ' freq= 10.2103328568511 Dur[98]= 4818 ' freq= 10.3777501037775 Dur[99]= 4740 ' freq= 10.548523206751 Dur[100]= 4664 ' freq= 10.7204116638079 Dur[101]= 4589 ' freq= 10.8956199607758 Dur[102]= 4515 ' freq= 11.0741971207087 Dur[103]= 4442 ' freq= 11.2561909049977 Dur[104]= 4370 ' freq= 11.441647597254 Dur[105]= 4300 ' freq= 11.6279069767442 Dur[106]= 4231 ' freq= 11.8175372252422 Dur[107]= 4162 ' freq= 12.013455069678 Dur[108]= 4095 ' freq= 12.2100122100122 Dur[109]= 4029 ' freq= 12.4100273020601 Dur[110]= 3964 ' freq= 12.6135216952573 Dur[111]= 3901 ' freq= 12.8172263522174 Dur[112]= 3838 ' freq= 13.0276185513288 Dur[113]= 3776 ' freq= 13.2415254237288 Dur[114]= 3715 ' freq= 13.4589502018842 Dur[115]= 3655 ' freq= 13.6798905608755 Dur[116]= 3596 ' freq= 13.9043381535039 Dur[117]= 3538 ' freq= 14.1322781232335 Dur[118]= 3481 ' freq= 14.3636885952312 Dur[119]= 3425 ' freq= 14.5985401459854 Dur[120]= 3370 ' freq= 14.8367952522255 Dur[121]= 3316 ' freq= 15.0784077201448 Dur[122]= 3262 ' freq= 15.3280196198651 Dur[123]= 3210 ' freq= 15.5763239875389 Dur[124]= 3158 ' freq= 15.8328055731476 Dur[125]= 3107 ' freq= 16.0926939169617 Dur[126]= 3057 ' freq= 16.3559044815178 Dur[127]= 3008 ' 6.9ms nu = 144Hz 'here used for ramping speed [21.06.2016] Set Dur5[0] ' not used Dur5[1]= 41667 ' freq= .999992000063999 Dur5[2]= 39494 ' freq= 1.0550125757499 Dur5[3]= 38450 ' freq= 1.08365843086259 Dur5[4]= 37434 ' freq= 1.11307011451265 Dur5[5]= 36445 ' freq= 1.14327525495038 Dur5[6]= 35482 ' freq= 1.17430434210774 Dur5[7]= 34544 ' freq= 1.20619113787247 Dur5[8]= 33631 ' freq= 1.23893629885126 Dur5[9]= 32743 ' freq= 1.27253662360403 Dur5[10]= 31877 ' freq= 1.30710752789367 Dur5[11]= 31035 ' freq= 1.34257021642232 Dur5[12]= 30215 ' freq= 1.37900601246621 Dur5[13]= 29416 ' freq= 1.41646269603844 Dur5[14]= 28639 ' freq= 1.45489251254117 Dur5[15]= 27882 ' freq= 1.49439303732396 Dur5[16]= 27146 ' freq= 1.53490999287802 Dur5[17]= 26428 ' freq= 1.57661066545583 Dur5[18]= 25730 ' freq= 1.61938074880166 Dur5[19]= 25050 ' freq= 1.66333998669328 Dur5[20]= 24388 ' freq= 1.70849051446066 Dur5[21]= 23743 ' freq= 1.75490319953951 Dur5[22]= 23116 ' freq= 1.8025033166061 Dur5[23]= 22505 ' freq= 1.85144042064726 Dur5[24]= 21910 ' freq= 1.90171915411532 Dur5[25]= 21331 ' freq= 1.95333864641445 Dur5[26]= 20768 ' freq= 2.006291730868 Dur5[27]= 20219 ' freq= 2.06076792455941 Dur5[28]= 19685 ' freq= 2.11667090000847 Dur5[29]= 19164 ' freq= 2.17421554303207 Dur5[30]= 18658 ' freq= 2.23317969057062 Dur5[31]= 18165 ' freq= 2.29378842095605 Dur5[32]= 17685 ' freq= 2.35604561304307 Dur5[33]= 17218 ' freq= 2.41994811631239 Dur5[34]= 16763 ' freq= 2.48563304102289 Dur5[35]= 16320 ' freq= 2.5531045751634 Dur5[36]= 15888 ' freq= 2.62252433702585 Dur5[37]= 15469 ' freq= 2.69355916133342 Dur5[38]= 15060 ' freq= 2.76671093404161 Dur5[39]= 14662 ' freq= 2.84181330423316 Dur5[40]= 14274 ' freq= 2.91906029610948 Dur5[41]= 13897 ' freq= 2.99824902257082 Dur5[42]= 13530 ' freq= 3.07957625030796 Dur5[43]= 13172 ' freq= 3.16327563518575 Dur5[44]= 12824 ' freq= 3.24911624038262 Dur5[45]= 12485 ' freq= 3.33733813910025 Dur5[46]= 12155 ' freq= 3.42794460441519 Dur5[47]= 11834 ' freq= 3.52092839840009 Dur5[48]= 11522 ' freq= 3.61627032343922 Dur5[49]= 11217 ' freq= 3.71459986330272 Dur5[50]= 10921 ' freq= 3.81527943106553 Dur5[51]= 10632 ' freq= 3.91898670679709 Dur5[52]= 10351 ' freq= 4.02537597011561 Dur5[53]= 10078 ' freq= 4.13441820467024 Dur5[54]= 9811 ' freq= 4.24693371385859 Dur5[55]= 9552 ' freq= 4.36208821887214 Dur5[56]= 9300 ' freq= 4.48028673835125 Dur5[57]= 9054 ' freq= 4.60201752448273 Dur5[58]= 8815 ' freq= 4.72679145396105 Dur5[59]= 8582 ' freq= 4.85512312592247 Dur5[60]= 8355 ' freq= 4.9870337123479 Dur5[61]= 8134 ' freq= 5.12253094008688 Dur5[62]= 7919 ' freq= 5.26160710527423 Dur5[63]= 7710 ' freq= 5.40423692174665 Dur5[64]= 7506 ' freq= 5.5511146638245 Dur5[65]= 7308 ' freq= 5.70151432220398 Dur5[66]= 7115 ' freq= 5.85617240571562 Dur5[67]= 6927 ' freq= 6.01510995621 Dur5[68]= 6744 ' freq= 6.1783313562673 Dur5[69]= 6565 ' freq= 6.34678852500635 Dur5[70]= 6392 ' freq= 6.51856487275761 Dur5[71]= 6223 ' freq= 6.69559162247576 Dur5[72]= 6059 ' freq= 6.87682235792485 Dur5[73]= 5898 ' freq= 7.06454165253758 Dur5[74]= 5743 ' freq= 7.25520924023449 Dur5[75]= 5591 ' freq= 7.45245334764204 Dur5[76]= 5443 ' freq= 7.65509216730969 Dur5[77]= 5299 ' freq= 7.86311882745172 Dur5[78]= 5159 ' freq= 8.07650061381405 Dur5[79]= 5023 ' freq= 8.29517552591413 Dur5[80]= 4890 ' freq= 8.52079072937969 Dur5[81]= 4761 ' freq= 8.75166281593503 Dur5[82]= 4635 ' freq= 8.98957209636821 Dur5[83]= 4513 ' freq= 9.23258734027624 Dur5[84]= 4393 ' freq= 9.48478640261021 Dur5[85]= 4277 ' freq= 9.74203101862676 Dur5[86]= 4164 ' freq= 10.0064040986231 Dur5[87]= 4054 ' freq= 10.277914816642 Dur5[88]= 3947 ' freq= 10.5565408326999 Dur5[89]= 3843 ' freq= 10.842223956978 Dur5[90]= 3741 ' freq= 11.1378419317473 Dur5[91]= 3642 ' freq= 11.4406004027091 Dur5[92]= 3546 ' freq= 11.7503290092122 Dur5[93]= 3452 ' freq= 12.0702974121282 Dur5[94]= 3361 ' freq= 12.3971040364971 Dur5[95]= 3272 ' freq= 12.7343113284434 Dur5[96]= 3186 ' freq= 13.0780498012136 Dur5[97]= 3102 ' freq= 13.4321942832581 Dur5[98]= 3020 ' freq= 13.7969094922737 Dur5[99]= 2940 ' freq= 14.172335600907 Dur5[100]= 2862 ' freq= 14.5585837409737 Dur5[101]= 2787 ' freq= 14.9503647889008 Dur5[102]= 2713 ' freq= 15.3581521071385 Dur5[103]= 2641 ' freq= 15.7768522024486 Dur5[104]= 2571 ' freq= 16.2064047711656 Dur5[105]= 2504 ' freq= 16.640042598509 Dur5[106]= 2437 ' freq= 17.0975242784845 Dur5[107]= 2373 ' freq= 17.5586458772299 Dur5[108]= 2310 ' freq= 18.037518037518 Dur5[109]= 2249 ' freq= 18.5267526307989 Dur5[110]= 2190 ' freq= 19.0258751902588 Dur5[111]= 2132 ' freq= 19.5434646654159 Dur5[112]= 2076 ' freq= 20.0706486833654 Dur5[113]= 2021 ' freq= 20.616856341745 Dur5[114]= 1967 ' freq= 21.182850364345 Dur5[115]= 1915 ' freq= 21.7580504786771 Dur5[116]= 1865 ' freq= 22.3413762287757 Dur5[117]= 1815 ' freq= 22.9568411386593 Dur5[118]= 1767 ' freq= 23.5804565176382 Dur5[119]= 1721 ' freq= 24.2107301956227 Dur5[120]= 1675 ' freq= 24.8756218905473 Dur5[121]= 1631 ' freq= 25.5466993664418 Dur5[122]= 1588 ' freq= 26.2384550797649 Dur5[123]= 1546 ' freq= 26.9512721000431 Dur5[124]= 1505 ' freq= 27.6854928017719 Dur5[125]= 1465 ' freq= 28.4414106939704 Dur5[126]= 1427 ' freq= 29.1987853305302 Dur5[127]= 1389 ' freq= 29.9976001919846 For i = 0 To 127 Dur5[i] = Dur5[i] >> 3 'so range becomes 8Hz to 240Hz Next i Return