| Posted: 03:43am 26 Aug 2023 |
|
|
|
Thanks for the feedback @chopperp and TassyJim.
I have tried longer gate periods but the result is always an integer value, even printing str$(pin(GPnn),6,4).
I have used PULSIN to measure the period and using that to determined the frequency. It measures period in µs.
Sub Freq TimeEnd=Timer Period%=Pulsin(GP22,0,25000,25000) Period2%=Pulsin(GP22,0,25000,25000) Period3%=Pulsin(GP22,0,25000,25000) Period%=(Period3%+Period%+Period2%)/3 DeltaTime=TimeEnd-TimeStart Freq!=(1000000/Period%)/2 ' Measuring PWM 50% duty cycle so two edges Frequency$=Str$(Freq!,6,2) ' used in the JSON string to talk to the graph TimeStart=Timer End Sub
This subroutine is called by a 1s Tick. Interestingly the DeltaTime is rarely 1000ms, usually under.

Frequency to 2 decimal places. Target frequency for the PWM output I'm measuring is 50.01Hz.
 Using the Pin(GPNN),FIN would just have been far more elegant:) Edited 2023-08-26 13:47 by carlschneider |