I have connected my pic18f4455 to sensors by external A/D called MCP3001 (10-bit resolution) .This A/D always sends 5v to the pic18 even there is no data coming from the sensors. Also this A/D needs a clock from Pic18 to work. For that reason, I selected the idle mode instead of sleeping mode. To save power, I have tried to make my pic18 works in idle mode when the coming data from sensors less than 250, and it works greater than 250.
I can't make the interrupt because the A/D sends 5v to the pic18 all the time.In addition, I don't think watchdog will help me with the condition (less the 250).
could you help me to write the right code for my project. I wrote a code to explain my case, but it needs a modification to work
- Code: Select all
while(1) //This is the primary control loop
{
SLEEP();
get_sensor_data(); //This function gets a sample from your A/D
if(sensor_data >= 250) //This checks the value of the sensor data
{
Do_Other_Tasks(); //If greater or equal to 250, it will run your other tasks
}
} //Returns to the start of the While() loop which puts the MCU to SLEEP.