Looks like you have it coded incorrectly. Try this instead ( Adapted from Demo) This should set B.1 on for 10 ms then off for 10ms giving a frequency of ~50Hz (Untested)
Don't buy a new usb scope. Get a second hand hardware scope with real knobs.
Modern ones are all software dso though. I wouldn't buy an old scope, too much component wear.
Scopes are very useful. I use a hantek 2022 with official and open source software, only 16M samples/S and not suitable for all ucontroller testing. Better than nothing I guess.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If anybody wants a USB 'scope, I could let one go for a £10 (which I will make a donation to The British Hedgehog Preservation Society) and the cost of postage. I think it cost me something like £50? It's not great, but does work. 2 Channels, good for about 10MHz. Model number is Cleqee OSC482.
I've replaced that with a Fnirsi 1014D. Claimed to be good for 100MHz but realistically 25-30MHz. It is however a fabulous little 'scope. Much better than the one I bought at work (OWON) that cost well over twice the price. Cost just under £150 from AliExpress.
I would really like an ana-digi type "real" 'scope with a CRT but a used Hameg will often fetch significantly more than the amount I paid for a newer and much lighter LCD one.
Oh dear. I'll stick with mine until I can get a real scope, not with a crt and the faults but a lcd.... lots o money for a new one from flea bay though.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I purchased a new Siglent 1202X-E about 6 months ago to replace my old TEK with a dim screen. So far I am very pleased. I use this scope almost daily with no problems. More than good enough for microcontroller stuff.
Last edit: William Roth 2022-01-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Any problems with it ? There's a similar hantek screen,same price. Get what you pay for I suppose. Using a pc and a usb box is poor. £150 seems ok for a scope.
Last edit: stan cartwright 2022-01-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Hantek is more expensive, and Amazon UK have the Yeapook in stock for next day delivery.
I prefer the layout of the FNIRSI/Yeapook screen. With the measurements shown on the right hand side, there is more vertical space for the traces. They can run from a USB power bank making it (semi) portable too.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am getting a bit lost here Stan.
Are you saying that the code works and the USB Scope was giving incorrect results?
Or have we gone off on a tangent discussing Scopes and lost the focus?
If Millis() is not working in the new compilers I need to fix it so please advise.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Stan's original code worked ok for 65 seconds, then start toggling as fast as the loop would allow. Seems that after 65 seconds the "if" condition is always true causing an a very fast toggle.
Nothing wrong with the scope.
Last edit: William Roth 2022-01-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The point was strange results on scope but scope gets the 1KHz probe trimmer signal correct.
I dug out some 50Hz timer 1 & 0 interrupts that worked once but gave strange results.
I tried using millis() instead. I think millis() is a long and I'm using word vars.
If I change elapsed to a long it seems to work when if millis()-elapsed>=10.
Probably scope triggers on rising edge which is every other 10ms so gives 50Hz.
The point was strange results on scope but scope gets the 1KHz probe trimmer signal correct.
I dug out some 50Hz timer 1 & 0 interrupts that worked once but gave strange results.
I tried using millis() instead. I think millis() is a long and I'm using word vars.
If I change elapsed to a long it seems to work when if millis()-elapsed>=10.
Probably scope triggers on rising edge which is every other 10ms so gives 50Hz.
I guess if millis()-elapsed>=10 will only work as both long vars or if millis() >65535 then it won't using a word var for elapsed. Testing a new gcb release.
This is Bill's method. Note the assignment of the CurrentMs variable. Why is this important? This 'If CurrentMs - PreviousMs >= 20 then' will work as expected and the variable states will be caches when the millis interrupt fires.
This may not work as expected ' if millis()-elapsed>=20 then' Why? The interrupt can fire durin g calc of millis and elapsed.... yes. Millis is four bytes and those four bytes can change messing up any calculation. This is NOT an implementation issue of millis() this is a usage issue. The way to stop this... use Bills method.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It has CurrentMs = Millis() in the loop, CurrentMs will overflow after time.
Your point about a millis event happening during the main program is true.
Use int off, do a comparison to millis(), then int on?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried this code and it should run at around 50Hz but usb scope says 60 odd kHz.
If I scope the 1 KHz calibrate probe pin it says 1 KHz.
Last edit: stan cartwright 2022-01-24
Looks like you have it coded incorrectly. Try this instead ( Adapted from Demo) This should set B.1 on for 10 ms then off for 10ms giving a frequency of ~50Hz (Untested)
Last edit: William Roth 2022-01-25
Thanks. I saw Chris Ropers demo
I don't see my code gave so high a frequency. and why
Didn't work. I shouldgiver 25Hz.
NO - That should give 50Hz
20mS = 20E-3 = 0.020
1/0.02 = 50
if you want 25Hz then:
1/25 = 0.04 = 40E-3 or 40mS
so
if millis()-elapsed>=40 then ' will generate a 25Hz signal
Last edit: Chris Roper 2022-01-25
CurrentMs - PreviousMs >= 20 gives 25Hz
CurrentMs - PreviousMs >= 10 gives 50Hz
Sure. The pin is on for 10 ms then off for 10ms giving a period of 20ms. 1000ms / 20 ms = 50Hz
Don't buy a new usb scope. Get a second hand hardware scope with real knobs.
Modern ones are all software dso though. I wouldn't buy an old scope, too much component wear.
Scopes are very useful. I use a hantek 2022 with official and open source software, only 16M samples/S and not suitable for all ucontroller testing. Better than nothing I guess.
If anybody wants a USB 'scope, I could let one go for a £10 (which I will make a donation to The British Hedgehog Preservation Society) and the cost of postage. I think it cost me something like £50? It's not great, but does work. 2 Channels, good for about 10MHz. Model number is Cleqee OSC482.
I've replaced that with a Fnirsi 1014D. Claimed to be good for 100MHz but realistically 25-30MHz. It is however a fabulous little 'scope. Much better than the one I bought at work (OWON) that cost well over twice the price. Cost just under £150 from AliExpress.
I would really like an ana-digi type "real" 'scope with a CRT but a used Hameg will often fetch significantly more than the amount I paid for a newer and much lighter LCD one.
Mkstevo Right on and all. looks tidy. How much? Postage 4u a few quid ukmail to wales,cardiff.
Typical dso in a box , nice.
Just to be clear, the picture above is NOT the one I'm selling, it is my new one.
This is the one I'm selling.
Last edit: mkstevo 2022-01-26
Oh dear. I'll stick with mine until I can get a real scope, not with a crt and the faults but a lcd.... lots o money for a new one from flea bay though.
I purchased a new Siglent 1202X-E about 6 months ago to replace my old TEK with a dim screen. So far I am very pleased. I use this scope almost daily with no problems. More than good enough for microcontroller stuff.
Last edit: William Roth 2022-01-28
Rigol 1202X-E looks good. 200MHz. £360 is a bit over budget for a hobby.... I don't fix stuff anymore. Think this any good? https://www.banggood.com/Hantek-DSO2C10-Digital-Oscilloscope-2CH-Digital-Storage-1GS-or-s-Sampling-Rate-100MHz-Bandwidth-Dual-Channel-Economical-Oscilloscope-p-1765866.html?utm_source=googleshopping&utm_medium=cpc_organic&gmcCountry=GB&utm_content=minha&utm_campaign=minha-gb-en-pc¤cy=GBP&cur_warehouse=CN&createTmp=1&utm_source=googleshopping&utm_medium=cpc_bgs&utm_content=tanya&utm_campaign=tanya-ssc-gb-euw-all-0113&ad_id=491180619117&gclid=Cj0KCQiAosmPBhCPARIsAHOen-PzQiVJEoWhXtpqc0_Dmv-9gHuwCwkbAuSV7RpZXp-w-woDTVAhBcwaArEKEALw_wcB
The FNIRSI I bought can be bought as a "Yeapook" on Amazon for £149.99.
https://smile.amazon.co.uk/YEAPOOK-ADS1014D-Oscilloscope-Generator-Bandwidth/dp/B099S4QP3T
Any problems with it ? There's a similar hantek screen,same price. Get what you pay for I suppose. Using a pc and a usb box is poor. £150 seems ok for a scope.
Last edit: stan cartwright 2022-01-27
The Hantek is more expensive, and Amazon UK have the Yeapook in stock for next day delivery.
I prefer the layout of the FNIRSI/Yeapook screen. With the measurements shown on the right hand side, there is more vertical space for the traces. They can run from a USB power bank making it (semi) portable too.
I had an old tektronix that reached the green grasslands of Manitou and I replaced it with this one.
It has good quality and it's honest.
https://www.amazon.it/DSO4102S-Oscilloscopio-Digital-Generator-AC100-240V/dp/B07K32RTL4
Thanks all. I'll see what's reviewed for £150 scopes. I never got x,y mode to work with my hantek usb.
I am getting a bit lost here Stan.
Are you saying that the code works and the USB Scope was giving incorrect results?
Or have we gone off on a tangent discussing Scopes and lost the focus?
If Millis() is not working in the new compilers I need to fix it so please advise.
Stan's original code worked ok for 65 seconds, then start toggling as fast as the loop would allow. Seems that after 65 seconds the "if" condition is always true causing an a very fast toggle.
Nothing wrong with the scope.
Last edit: William Roth 2022-01-28
So, no issue with millis() ? Stan's code just is not right.
The point was strange results on scope but scope gets the 1KHz probe trimmer signal correct.
I dug out some 50Hz timer 1 & 0 interrupts that worked once but gave strange results.
I tried using millis() instead. I think millis() is a long and I'm using word vars.
If I change elapsed to a long it seems to work when if millis()-elapsed>=10.
Probably scope triggers on rising edge which is every other 10ms so gives 50Hz.
The point was strange results on scope but scope gets the 1KHz probe trimmer signal correct.
I dug out some 50Hz timer 1 & 0 interrupts that worked once but gave strange results.
I tried using millis() instead. I think millis() is a long and I'm using word vars.
If I change elapsed to a long it seems to work when if millis()-elapsed>=10.
Probably scope triggers on rising edge which is every other 10ms so gives 50Hz.
I guess if millis()-elapsed>=10 will only work as both long vars or if millis() >65535 then it won't using a word var for elapsed. Testing a new gcb release.
Last edit: stan cartwright 2022-01-28
This is Bill's method. Note the assignment of the CurrentMs variable. Why is this important? This 'If CurrentMs - PreviousMs >= 20 then' will work as expected and the variable states will be caches when the millis interrupt fires.
This may not work as expected ' if millis()-elapsed>=20 then' Why? The interrupt can fire durin g calc of millis and elapsed.... yes. Millis is four bytes and those four bytes can change messing up any calculation. This is NOT an implementation issue of millis() this is a usage issue. The way to stop this... use Bills method.
It has CurrentMs = Millis() in the loop, CurrentMs will overflow after time.
Your point about a millis event happening during the main program is true.
Use int off, do a comparison to millis(), then int on?