Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3843

Interfacing (DSI, CSI, I2C, etc.) • Zero W using SPI has PWM glitch

$
0
0
Hello,
I have been using this code on a Pi 3B+ without any issues, but then had a mishap and let the smoke out of it. So I used a spare Zero W board (brand new) instead. However, when I run the code the outputs out of pin 12 and 13 at pulse at around 0.2Hz, without even setting the PWM frequency at all and even if I try to change it has no effect. I have split the code and run the SPI code on its own and then run the PWM code on its own and they work fine. I used Thonny to step into the code and the pulses start when the GPIO.setup(xxxx) configurations are made. Funny thing is, is that it does not happen all the time. I thought I had it solved when I turned off 1 wire, which fixed it for a little bit but when I cycled the power it came back again.
Does anyone have an suggestions to what is causing this or any tests that I could do to locate the issue?

Code:

import digitalioimport adafruit_max31865import timeimport RPi.GPIO as GPIOimport busioimport board#pin DEFINESPWMPORT0 = 12PWMPORT1 = 13GPIO.setmode(GPIO.BCM)#Using broadcom numbersGPIO.setup(PWMPORT0,GPIO.OUT)GPIO.output(PWMPORT0,GPIO.LOW)GPIO.setup(PWMPORT1,GPIO.OUT)GPIO.output(PWMPORT1,GPIO.LOW)pwmPort1 = GPIO.PWM(PWMPORT1, 100)   # Initialize PWM on pwmPin 100Hz frequencypwmPort1.start(0)pwmPort2 = GPIO.PWM(PWMPORT0, 100)   # Initialize PWM on pwmPin 100Hz frequencypwmPort2.start(0)spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) #Configure SPIcsDev1 = digitalio.DigitalInOut(board.D27)  # Chip select of the Mash Tank !!!!Changed to hlt get up and runningcsDev1.direction = digitalio.Direction.OUTPUTdev1RTD_SPI = adafruit_max31865.MAX31865(spi, csDev1)csDev2 = digitalio.DigitalInOut(board.D22)  # Chip select of the HLT !!!!Changed to hlt get up and runningcsDev2.direction = digitalio.Direction.OUTPUTdev2RTD_SPI = adafruit_max31865.MAX31865(spi, csDev2)while (True):csDev1.value = FalsecsDev2.value = Truedev1RTD_SPI = adafruit_max31865.MAX31865(spi, csDev1)dev1Temp = dev1RTD_SPI.temperature #update for interfacetime.sleep(0.5)csDev1.value = TruecsDev2.value = Falsedev2RTD_SPI = adafruit_max31865.MAX31865(spi, csDev2)dev2Temp = dev2RTD_SPI.temperatureprint ("Dev1 Temp =", dev1Temp)print ("Dev2 Temp =", dev2Temp)time.sleep(0.5)print("Enter in PWM Value for both Port 0 and Port 1:")newPIDValue = input()pwmPort1.ChangeDutyCycle(int(newPIDValue))pwmPort2.ChangeDutyCycle(int(newPIDValue))

Statistics: Posted by CWildRun — Sun Mar 31, 2024 12:04 am



Viewing all articles
Browse latest Browse all 3843

Trending Articles